HTML5 “Back to Square One” prototype made with Phaser – Adding enemies

If you enjoyed last week’s post HTML5 player movement like in popular iOS game “Back to Square One” made with Phaser, today there’s more for you as I am updating the prototype adding enemies.

Enemies are moved with a tween with yoyo effect to make them patrol up and down, and we use ARCADE physics to check for collisions.

The result works fine:

Click or touch the canvas to make the square roll. If you touch an enemy, the game will restart.

I did not optimize some parts of the previous code, and even worse I do not have a pool to handle enemies, I am just creating and destroying them on the fly, but at least the code is well commented and I also highlighted the newly added lines:

Next time, some optimization and some new tile types. Meanwhile, download the complete source code.

  • Robert

    Hey Emanuele,

    I couldn’t find any direct contact to you on your site, so I’ll just write it here.

    I’m looking for a person who could port a few actionscript games to javascript , so they could work in the most popular browsers (safari, firefox, IE, chrome). They’re not super complex (angry bird like game, endless runner, one incorporates a bit of video material though). A total of six games.

    Would you be interested?

  • Carlo

    Hi Emanuelle,
    Can you please explain me or create an example on how do mass/density work in Phaser with box2d?.
    Let’s say we have two cars and a bee on the road. If a car1 crashes the other car2, it will apply a force the car2 and it car2 will apply a force on car1. If car1 hits a bee the amount of force applied from the bee to the car1 will be near zero, but the force applied from the car to the bee will be huge.
    Is there a way to do this using box2d?

    Thank you

    • Emanuele Feronato

      Ok, I will create it next week