Saturday, December 10, 2016

Just discovered JBox2D

I think I'm pretty late to the 2D physics library game; I've just discovered Jbox2D and I can't believe what I've been missing.  Apart from anything, it handles all the collision detection for you, which saves tons of coding straight away.  But not only that, it also handles them in realistic ways.  As a game developer, you just create all the physics objects and then let the physics engine do everything else.  All you need to do is draw the graphics and handle user input.  It's so good, I'm surprised at the lack of example code on the internet.

Here's a small vid one of my first experiments - water and getting something to float in it.



It's pretty simple, but what's even simpler is the code required to do this.  I've just created the particles and the rectangle, and then the rest is automatic.  The main bit of code I had to write was drawing it all.

I've been messing about with it for a few weeks now, and my first "big" project with ti is going to be a remake the classic Escape from Krakatoa using JBox2d.  It's a game that lends itself to a physics enghine; the player flies a helicopter, must avoid rocks being thrown from a volcano and rescue people from the island.  I'm going to check I can recreate each aspect using the physics engine, and then put it all together.  Next up is flying a helicopter.

No comments: