PhysInjector game prototype in only 100 lines of code

Emanuele Feronato Actionscript 3, Box2D, Flash, Game design

Some days ago I showed you a new Box2D library called PhysInjector, now it’s time to let you see how can you make a fully working physics game prototype in only 100 lines of code, braces and classes included.

It’s (not that) vaguely based on my BarBalance game, an old game which I sold to FOG.

In this prototype, which would need to be a bit optimized but I wanted to keep it with only 100 lines of code, you have to create boxes by clicking with mouse button above the black line. Boxes will fall on the balance at the bottom of the screen, which color represents the next box you are about to create.

When two boxes of the same color collide, they become a bit transparent, and when a box turns completely transparent, it disappears. If a box falls down the balance, you lose a life. Lose al lives and it’s game over.

Give it a go:

Although the game is made by only 100 lines, it features:

* Static bodies
* Dynamic bodies
* Sensors
* Revolute joints
* Motors
* Collision detection
* Score
* Lives
* 8 different box colors
* Increasing difficulty

All these features in just a few lines are possible thanks to PhysInjector which allowed me to add Box2D physics in a snap.

This is the source code.

During next days, I will show you how to create the same thing using the standard Box2D library, and we’ll then count the lines.

Download the source code of the entire project. What’s your best score?

Want to learn more? Learn by example!

Get the full commented source code of an actual commercial cross platform HTML5 game!!

Comments 6

  1. Luna

    Hi Emanuele! Thanks for your contributions. I’m making my first game and it is almost entirely on knowledge that I learned from you!

    I have an unrelated question – How do you code the Rate this post stars in flash cs6? I want to add something similar to my site.

    I’m a BIG fan
    Luna

  2. reyco1

    @benben
    it doesn’t at the moment, but that is very simple to add to the PhysicsObject class. It’s in the next release. If you really need it now, hit me up and I will send you a stable pre-release

  3. Every

    Hi Emanuele!
    Today,I liked it when I see the library!I’m learning it by your demo.It’s very good.But I’m failed when I want to replace the box by my Sprite.Could you teach my how can I do?Thanks.
    I’m your new fan.
    Every

Leave a Reply

Your email address will not be published. Required fields are marked *