Create HTML5 Vertical Endless Runner cross platform games

Using Phaser framework and other FREE software
Endless runner games are gaining more and more popularity and they are really easy to code.
I will take you by hand through the creation of a complete HTML5 vertical endless runner cross platform game with a lot of features and room for customization.
100 pages + 31 source code examples with a free update to come in a few days.

Create a game like Perfectionism with Flash – Step 6

Emanuele Feronato Flash, Game design

This is the last step.

And the end of this one, we’ll have our complete Perfectionism game

The score

You get one point every time you move a square into a ring, and you lose one point every time you move a square out of a ring

To show the score, I just created a new movieclip with a dynamic text area into it just like in the picture

Perfectionism

As you can see, the movieclip is called and linked as score while the text area is instanced as scoretxt

Now, the actionscript:

Line 4: Attaching the score movieclip into the movie

Line 28: Declaring a new variable called points that will contain the score

Line 96: When the square stopped moving, I check if before moving the square was inside a ring. It’s easy: I just have to check if the level array element at pos attribute (that has not been updated yet) was 3

Line 97: In this case, subtract 1 to points variable

Line 102: Now I check if the square moved into a ring. Now that I have the pos value updated at line 100, I have to check if the level array element at pos attribute (that now is updated) is 3

Line 103: In this case, add 1 to points variable

Line 105: Updating the text in the scoretext text area into the score movieclip.

And now the game has score too!

Now, we must allow the player to make only 100 moves (swapping rows/columns and changing level count as a move) and fix a little bug that allows the player to go to previous level even if there isn’t any previous level (when he’s playing level 1) and go to next level even if there isn’s any next level (when he’s playing level 21)

Only 100 moves

After creating the moves movieclip, in the same way as for the score, just calling and linking the movieclip as moves and instancing the text area as movestxt, this is the actionscript:

Line 5: Attaching the moves movieclip

Line 30: Declaring a variable called turns, that will store the number of moves left, and setting it to 100

Line 33: If we are playing level 1…

Line 34: … then don’t show the previous level button

Line 37: If not, then show the previous level button

Lines 39-44: Same thing as lines 33-38, just for the next level button when we are playing on level 21

Please notice that this method will only make the buttons invisible, but they will remain clickable.

Line 195: All the code that previously was executed when the player clicked on two buttons, now it will be executed only if turns is greater than zero (the player did not spend all moves)

Line 196: If the player switched rows/columns, then drecrease turns variable

Line 197: Update the number of moves left shown onscreen

Lines 232-234: If turns is zero, then call the function reset_swap… nothing happens and the player is not longer able to swap rows/columns

Line 248: Now the condition to advance level is: nextlevel is true (as before) and the current level is not the last one (21st) and turns is greater than zero (the player has moves left)

Line 249: if the player changes the level, then decrease turns variable

Line 250: Update the number of moves left shown onscreen

Lines 255-257: Same concept as lines 248-250, just for the previous level

And finally the game is complete

Now you can optimize the code, make your custom levels, add an intro, a game over screen, a highscore tables, and whatever you want, but we made the complete game in just 300 lines of code.

Download the source code and tell me if you made some interesting game out of it.

Stay up to date
Follow me on the social networks and never miss a post.

Official Emanuele Feronato Facebook page

Official Emanuele Feronato Twitter account

From null to full HTML5 cross platform game

I will take you by hand from the bare bones of JavaScript programming through the creation of a full cross platform HTML5 game, with detailed explainations and source code.

If you don't know where to start, then From null to full HTML5 cross platform game is the book for you.

Comments 7

  1. Eblup

    Hey, i am having trouble with your platform physics. the guys corners have glitches so i would love for you to help. in return i will help you with a virtual camera for flash games. put in this code.this makes evreything move and youre guy stays in the same plase so now please help fix the glitches and my help with isometric games.

    //camera code
    _x -= _root.guy.speed;
    _y -= _root.guy.gravity;

  2. Ashker

    Cool, good job :P.
    I may make my own version of the game, and when/if i do i will post to see what you guys think.

    Keep up the good work Emanuele

  3. Viktor H

    Hi Emanuele! Love your stuff.

    Anyway, the RSS feed haven’t updated for me! It still says Blog in peace is the latest blog-post.
    What’s up with that?

Leave a Reply

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