Real world catapult prototype using Box2D – Cleaner code

We got it.

After the first catapult prototype and the “slippery wheels” sequel, this is a version with realistic movement and a lot cleaner code.

To add realistic movement I defined friction and restitution, making useless the CreateFixture2 function and widely using the more appropriate CreateFixture one.

This way I have full control on fixtures, while in the old way I could only define their masses.

This is the result:

Left and right to move, spacebar to fire

And this is the code:

No need to download, just cut and paste on the first catapult prototype.

Next time, full comments and some other interesting features…

  • muito legal…
    já tomo esse site como base..
    pelo seu otimo trabalho…

  • Zero Xue

    Thanks a lot,this is really helpful!

  • SOO much better! Thanks for making this update Emanuele!

  • Nice and clean. Really helped me :)

    Now, you should add/edit:
    Smaller size of catapult.
    Boxes in what will hit catapult
    Ball should go more away and lower from ground.

    (sry for bad English)

  • Woot for clean code, I’ll never be able to adjust to underscores in function names though, especially with the lower casing of the second word in a function. Good stuff though, very organized.

  • diego

    Perfect! that’s an Excellent example!!
    i try do a slingshot…
    can you help me? how can i do it this?