Made this over the course of about 10 hours. Pretty playable so far but the way Im doin the terrain is really bringin the system down. I doubt (given proper controls) itd be playable on mobile at all.
So Im lookin for some ideas on how to better do destructible terrain. Right now its generating a sprite object at each 8x8 location for the peak of the terrain. Then goin back thru and filling the locations below the peak with semi random terrain. I couldnt think of a better way to do it with c2 =/
Arrow keys: adjust angle/power
Space Bar: Shoot
Dont pay any attention to the numbers in the boxes on the first screen its there for debug stuff I just forgot to remove it in the uploaded version. Its local mp only 2 to 6 players. Should be pretty much fully playable. Last one left alive is the winner!
Develop games in your browser. Powerful, performant & highly capable.
I answered on your other post, but figured I should copy it here since I came up with a possible answer while typing it.
I'm curious about a faster way to do terrain too, I was planning on trying a catapult game eventually.
One thing about your current method, it would be easy to turn on gravity for each of the dirt sprites, allowing you to drop enemies for damage.
Maybe slightly faster but not as interesting would be to use tall vertical sprites like columns of dirt, when they got hit, they could slide down so far. (or reduce in height) It would cut the number of sprites from around 2000 to 80.
if you did it that way you couldnt put holes inside it only reduce the overall height
Might be complicated but, when the cannonball hits the sprite you reduce it's height to the position of the cannonball, (all dirt above the hit vanishes) minus a few extra pixels. Then you spawn a stretched sprite above it from the original height down to a few pixels above the cannonball hit. (draw in the overhang) or if the calculated bottom position is above where the surface was, then skip it as that means the crater is on the surface.
It would still look like your original animation, except the rocks couldn't be mixed in, as they would appear to shift down.
(hmm, maybe reverse it, the sky is the sprite columns, moving down hiding the destroyed dirt, rocks wouldn't shift that way.)
I didn't say it was a complete idea, I was trying to spark ideas to reduce the sprites. You would still have to figure how to handle the overhang sprites when they get hit.
Search for "worms" there is an example that uses the canvas plugin to do destructible terrain.
Another idea would be to set the bottom layer as transparent "use webgl" off, and "clear background" as no. That way anything that is drawn stays there until it's overdrawn. Then you could draw the terrain, and only redraw the parts where stuff is moving/changing. You can store the entire terrain in an array and juggle a small amount of blocks to do the drawing. So at any given time you'd have only say 100 objects being drawn per frame but you would see 1000s on screen.
Here is a capx of the second idea: