Box2D breakout prototype

Porting Breakout/Arkanoid with Box2D seems to be an interesting challenge for developers.

Some days ago I showed you Phyballs, now it’s time for Andre Vidal to show his work.

Andre runs his own blog I suggest you to visit because you will find some interesting source code.

This is Andre’s breakout

(arrow keys = left and right paddle )
( everything is draggable with the mouse )

He used all the basic techiniques you ought to learn before adventuring into professional use of Box2d.

The bricks are hanging by distance joints attached to the body Ground, the paddle is fixed on the x axis by a prismatic joint attached also to the Ground.

The code looks for only 2 collisions, on ball against the paddle an Impulse is applied to the ball and on ball against a brick the brick distant joint is broken and the gravity acts on the brick (which makes it fall down).

Download the source code

  • Great one! Got the 1st comment space, wow!
    Hey emanuele, did u recieve my new game on ur mail?

  • Peter

    OH My Freggin’ GOD, do you guys imagine how cool this would be as a full game? Do you guys imagine how cool platform, shooting, adventure (etc) games you can make with this? I cant see Box2D in games. I mean, almost no one is using it, Why?

    Greetings from indignant Peter (sweden).

  • um, it’s really easy, because you can just drag the ball and knock the bricks of of thier joints.
    you don’t even have to use the paddle…

  • The paddle does not work like in Breakout ;-) Check out b2ContactListener :-)

  • I’ve seen Box2D in tons of games … I think. Or they were using their own physics engine.

  • Nathan

    This is very off-topic, but Emanuele, we need you to make some mods in the forums! They have been invaded by spam!

    Apparently many people have tried to contact you via email and PMs but you haven’t answered.

    See the topic in forum entitled “SPAM OUT OF CONTROL” for more info.

  • Quite, sorry for the O/T-ness but we can’t really cope with the spam… every visit I’m deleting posts from -every- forum, and it’s getting rather… risqué to say the least.

    Some for of bot control would be welcomed! Or the ability to delete ALL posts from a user when banning them.

  • Hei Emanuele, i have one problem with Box2D, i need change the gravity for time, but just using the function setGravity in my b2World, not working, i have to do something to change this value?

    And good work with box2D, i use APE until i read your blog! Now i try to forgeth the APE!

    look at this simple thing i do with APE:

    http://www.brunomikoski.com/2008/08/08/source-acquaplay-jogo-desenvolvido-em-ape-actionscript-3/