Page 1 of 1

making a platform game with destructible terrain?

Posted: Sun Oct 15, 2017 9:25 am
by 5kcool
how would i go about making a platformer with destructible terrain in love2d?

example: http://jastanton.com/experiments/Destructible-Terrain/

best regards Felix

Re: making a platform game with destructible terrain?

Posted: Sun Oct 15, 2017 3:30 pm
by hamberge
Well...

I think you should start with the easiest thing and build out the system from there. Maybe start with a player represented by a table with an x and y position. Every frame update the position based on input. Then add gravity and floor collision detection. Then add a data representation to represent your level. Then add the ability to modify the data representation based on mouse position when you click.

Re: making a platform game with destructible terrain?

Posted: Mon Oct 16, 2017 7:09 am
by 5kcool
Thanks! I will try to do it.

Re: making a platform game with destructible terrain?

Posted: Sat Oct 28, 2017 4:31 pm
by Ostego160
If you haven't found a solution already, I actually use destructible terrain in my current project (albeit more tile destruction, not worms style). I did it by having my tile loader spawn objects with a health attribute and during a bullet collision event, the health of the object is subtracted by the damage of the bullet. Here is a sample of my collision event using HC where my bullets and static objects are stored in tables:

Code: Select all

function checkCollision()
   for i=1,#bullets do
      for k=1,#statics do
         if statics[k].mask then
            local collides, dx, dy = bullets[i].mask:collidesWith(statics[k].mask)
            if collides then
               statics[k].health = statics[k].health - bullets[i].damage
               bullets[i].remove = true
            end
         end
      end
   end
end
Then in the static object I have the following check function:

Code: Select all

if self.health <= 0 then self.remove = true end
And my garbage collector removes it. In addition, if you want levels of destruction, you can have the aforementioned function check for levels of health and change the sprite accordingly. I don't know if its the best way but it worked well for me. I hope this helps in some way.

Re: making a platform game with destructible terrain?

Posted: Wed Nov 01, 2017 4:15 pm
by 5kcool
Thanks very much! That sounds very interesting. I will try to implement it into a future game.