making a platform game with destructible terrain?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
5kcool
Prole
Posts: 3
Joined: Sat Oct 14, 2017 8:54 am

making a platform game with destructible terrain?

Post 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
hamberge
Prole
Posts: 25
Joined: Wed Aug 16, 2017 2:55 pm

Re: making a platform game with destructible terrain?

Post 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.
5kcool
Prole
Posts: 3
Joined: Sat Oct 14, 2017 8:54 am

Re: making a platform game with destructible terrain?

Post by 5kcool »

Thanks! I will try to do it.
Ostego160
Prole
Posts: 14
Joined: Tue Oct 17, 2017 7:18 pm

Re: making a platform game with destructible terrain?

Post 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.
5kcool
Prole
Posts: 3
Joined: Sat Oct 14, 2017 8:54 am

Re: making a platform game with destructible terrain?

Post by 5kcool »

Thanks very much! That sounds very interesting. I will try to implement it into a future game.
Post Reply

Who is online

Users browsing this forum: No registered users and 56 guests