I'm working on a Scorched Earth clone using xLIBC. Screenies so far (the square pixels are 'tanks'):
Note that this code is mostly untouched from the state it was in last night at 11:00 pm (I've been getting tired as early as 9 lately for some reason, so that was about the point where I started losing the ability to form coherent sentences), and as such it's preeeetty badly written. I'm working on optimizing it, but until that's done I've commented it so you guys can read it and hopefully (please?) help me out. Tank generation is the main thing that needs fixing; while I'm mostly happy with the results it produces, it takes 5-10 seconds on my CSE (depending on terrain) to generate positions, which is way too long for my liking-- I thought about calculating all values before the program starts, but that wouldn't work very well considering that terrain values (and thus, indirectly, tank positions) depend on user input at the beginning. So really, my only option here is to find a way to optimize it.
Anyway, enough rambling Here's the code, fully commented:
Code:
edits: clarified code some more | added screenies |
Note that this code is mostly untouched from the state it was in last night at 11:00 pm (I've been getting tired as early as 9 lately for some reason, so that was about the point where I started losing the ability to form coherent sentences), and as such it's preeeetty badly written. I'm working on optimizing it, but until that's done I've commented it so you guys can read it and hopefully (please?) help me out. Tank generation is the main thing that needs fixing; while I'm mostly happy with the results it produces, it takes 5-10 seconds on my CSE (depending on terrain) to generate positions, which is way too long for my liking-- I thought about calculating all values before the program starts, but that wouldn't work very well considering that terrain values (and thus, indirectly, tank positions) depend on user input at the beginning. So really, my only option here is to find a way to optimize it.
Anyway, enough rambling Here's the code, fully commented:
Code:
DelVar SMenu("TERRAIN","rand",2,"Input ",3,"Slope",1,"Horizontal ish",4
Lbl 4:2->theta:Goto theta
Lbl 1
1->S //slope
randInt(7,35->theta //doesn't really matter what's stored to theta here
Goto theta
Lbl 2 //random terrain
randInt(30,100,80->L1 //80 because that's half the screen size (160)
Goto A
Lbl 3 //steepness of hills depends on user input or (theta)
Input theta
Lbl theta
abs(int(120/theta)-cumSum(randInt(~theta,theta,80->L1 // gives a list of values that are separated by anything from ~theta to theta, which can be used to create smooth hills.
//I forgot why int(120/theta) works, but it does (although if you enter a lower number like 5 it'll be a bit too high up on the screen, and if you enter 1 there won't really be any terrain)
Lbl A
If S //S flags whether or not terrain is a slope
SortD(L1 //this sorts the values from highest to lowest, which translates onscreen into a left-to-right upwards slope, like this: /
If S and randInt(0,1
SortA(L1 //ensures that it's not always upwards. Sometimes it'll be a l-r downwards slope, like this: \
real(0,1,1 //initiate drawing mode
real(8,3,200->A //color for terrain
real(7,9,0,0,160,120,255 //background, may change it to random color (or even an image?) at some point
real(8,2,0 //sets no offset, as I'm not planning to use screen-switching for the time being
randIntNoRep(0,79->L3 //has no use here but if I do it later, the delay is annoyingly noticeable. When done here it just seems like part of the map generation delay. It'll be used for tank placement a few lines down
For(B,0,79
L1(B+1
real(7,9,2B,Ans,2,Ans+(120-Ans),A //draws 2px wide rects
End
//start tank placement
L1-2->L1 //so that the tanks are a little bit above the terrain
Ans->L2
SortD(L2 //this gives the lowest-down values first, so valleys will be the first places to get tanks
1->N:{0
For(T,1,dim(L2
If dim(Ans)=sum(not(cumSum(5>abs(Ans-L2(T
//1+sum(not(cumSum(LIST=VAL gives the list index of a value of the list. For instance 1+sum(not(cumSum(7={3,1,7 returns 3. I've omitted the '1+' here to save space.
//I didn't actually explain why it's used here-- before this loop, L2 contains lots of repeated values. This loop removes all the repeats.
augment(Ans,{L2(T
End
cumSum(DeltaList(Ans->L2 //removes the first element (the 0)
dim(Ans)-5->Y //Ensures that there won't ever be more than 5 (6?) tanks
For(B,1,80 //tank drawing loop
If max(L2=L1(1+L3(B:Then //This is where L3 is used. If I just iterated through everything normally (1-80) then the tanks would be concentrated on the left side of the screen; this adds some randomness to it.
real(7,3,2L3(B),L1(1+L3(B)),A+25,3,0 //just a pixel for now, nothing fancy
sum(not(cumSum(L2=L1(1+L3(B //putting this on its own line saves five bytes (again, finding list index)
seq(L2(X+(X>Ans)),X,1,dim(L2)-1->L2 //removes the value at Ans
dim(Ans //again, on its own line to save space
If Ans<Y or Ans=1:81->B //ends the For loop if there can't be any more tanks
End
End
Pause
edits: clarified code some more | added screenies |