Build 10 games and learn game development along the way in this fast paced game development course

Get the source code of 12 commercial games, loaded 50+ million times, and learn the secrets of game design

Learn how to make a successful Flash game from a real world example. Fully commented source code

Create realistic Flash physics games from scratch with advanced features, from Angry Birds to Crush the Castle

PhysInjector game prototype in only 100 lines of code

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?

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (11 votes, average: 4.64 out of 5)
Loading ... Loading ...
Learn how to make a successful commercial Flash game from a real world example: get the fully commented source code of Globez, a Flash game played millions of times which generated a four figure income. Limited copies available.

Get it now
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 6 comments

  1. Luna

    on April 8, 2013 at 4:29 pm

    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. benben

    on April 10, 2013 at 10:25 am

    Does the PhysInjector can use the b2_kinematicBody?

  3. reyco1

    on April 11, 2013 at 12:50 pm

    @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

  4. benben

    on April 15, 2013 at 11:36 am

    @reyco1
    Thank you !
    672194647@qq.com This is my Mail.
    I want to get the stable pre-release version of PhysInjector.

  5. Every

    on April 17, 2013 at 3:50 pm

    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

  6. anGTabAtABaKo!

    on April 22, 2013 at 8:04 am

    Wow! I scored 271! :D

Thank you for the download!!

I hope you will find it useful and make something interesting out of it

To keep up to date with the blog, why don't you like my Facebook page and follow me on Twitter?

Want to learn more? Don't miss this:

Learn how to make a successful commercial Flash game from a real world example: get the fully commented source code of Globez, a Flash game played millions of times which generated a four figure income. Limited copies available.

Get it now

×