Physics like the game "bacon - the game"

Hello everyone, I’m new to defold and want to create simple 2D games. I’m not a programmer either and hope to be able to learn coding games. I would like to use physics similar to the game “Bacon - the game”. Has anyone ever looked at this game and has an example code on how to program the bacon? Thank you in advance for that. and - I come from Germany.

1 Like

I’m not familiar with the game. Can you please share a link or video or describe the game?

If this is the Game (video link) you are talking about, then yes Defold would capable of this. You can see the Physics Manual here. Unfortunately at this time Defold does not have physics joints support in the editor. Defold uses it’s version of Box2d and you can get an idea of how to do this by researching more on Box2d. Once you understand how to create this in Box2d you should be able to easily move that over into Defold.

Thank you very much for your reply :slight_smile:

Yes, exactly. That’s the game. I have no idea how to get the “bacon” done. Are there many small elements next to each other? How do I get an object as “flexible” and natural behavior as in the game?

I look at the physics manual :slight_smile:

It probably works with the joints. Thanks for the link to the manual. I will try to understand how that works. Thank you very much and Merry Christmas to all of you here. :slight_smile:

1 Like

Hope you have a wonderful time during your celebrations! I recommend watching some videos on Box2d. There are plenty out there. The Bacon looks to be a matrix of spring joints connected together. As with most things in game programming, there are multiple paths you could take to recreate this. Box2d has an editor you could probably setup and work out easier than in Defold.

Thank you very much for the tip! Is box2d completely integrated into defold or just parts of it?

I would reference the Defold Manual vs Box2d. Defold has it’s own flavor of Box2d. It is built into the engine. But for what you are wanting to do it is possible with the Defold physics.

It looks like joints are the solution here - you need to create a chain that will simulate your physics and also make visuals accordingly.

  1. Make a chain using fixed joints connections:

2a. Either add small “slices of bacon” to each collision object in your chain (each collision object should be then inside a separate game object):

bacon
(of course sprites must overlap each other and you must somehow limit rotation of each one)

2b. If you are brave enough - make one sprite for your bacon, but use it as a texture to a quad with many polygons and then modify its vertices in a vertex shader according to a list of position of the center points of each segment (each segments connected to each other via above fixed joints) - if this sounds like black magic to you - you need to step into shaders. The below one is my explanation, pretty good for a start, but does not touch vertex programs sadly:

If you will get to understand it, there is a forum post, where Sergey helped me “wave” the grass by modifying vertices of a quad (same solution that you need for your bacon). It took me a while to get it:

bacon

2 Likes

Second using the shader. Yeah it’s a bit more code and learning but will pay off in visuals and performance

1 Like

Or you could first just go with simple sprites added to each “point” - collision objects that you will be joining, just to get the physics right, so you can see anything. Then it’s highly advisable to do the shader - approach for the same look as in Bacon game :wink:

Instead of the bacon - you can also have something more suiting the first solution, e.g. some kind of chain with balls :smiley: