Skip to content

Devlog 4

Antonio Caggiano edited this page Jan 28, 2021 · 5 revisions

Back with a new devlog. This time I am going to talk about dynamic entities, and how everything is now destructible!

While a static entity is not affected by physical forces thus does not move, a dynamic entity is affected by forces, so it can fall and can be pushed and pulled around. Thanks again to Box2D, implementing this was just a matter of setting the type of physics bodies to either b2_dynamicBody or b2_staticBody.

[Video dynamic/static bodies]

Another easy but important thing to add was a proper background in order to give to the player's eyes something more interesting to see than a boring solid color. For the moment, I just added a static sprite, but I guess it would be nice to implement a fancy parallax scrolling effect in the future.

[Screenshot with a good enough background]

Then I realized that something was missing. Tiles and entities could be added and positioned freely in the scene and, as all normal people that like symmetry, I also wanted to destroy them, not by interacting through the editor, but as Mario does by punching (or hitting with his head?)!

Appetite for Destruction

Not every tile should be destructible, but some of them certainly could and would be a good idea to giving this ability to the player. I started by introducing a flag to determine whether a tile is destructible or not. Then I implemented a destruction listener, which is a Box2D contact listener, responsible of checking impulses generated from collisions between entities. Then this impulse is big enough, both entities destructible flags are checked and added to a list accordingly. This list is processed later on to actually destroy the entities, something that should not be done in the previous step in order to avoid errors while Box2D is processing.

The result is really cool because not only do entities get destroyed after a collision with the main character, but they also get destroyed when colliding heavily between each other.

Last thing to do was to tweak the threshold for the impulse triggering destructions, and increase manually impulses when the collisions was from a character punching. In technical words, one of the entities is a character and the normal of the collision is close to (0, -1).

[Video of tiles getting destroyed]

Clone this wiki locally