by Fuzzy » Thu Jul 23, 2009 5:31 am
There is a more realistic way. You need an array as big as the max x of the screen. use things like sin and cos to generate some values, storing them in the array, after multiplying them by the max height you want. If you use random you will have to smooth the array values.
Step through the array, drawing lines to a canvas from the number in the array down to the bottom.
Thats your height field.
Next, whenever the tank gets hit, check to see if he is higher than the pixels at his x value. if so, make him fall.
When firing, trace the shot, figure out where it will be next draw. if that is a value that is greater than the value stored at that point of the array, then you have struck the ground.
To draw a pit, go back several pixels from the collision point and take some points out of that array box. then do the same, closer to the collision point. and so on, for a few pixels past the collision. next, redraw the ground using the array, and decide of any tanks are in the air.
Mortal Enemy of IF....THEN(and Inspector Gadget)
Still ThreeFingerPete to tekdino