Creation of Flash game Space Checkers – Step 3

Continuing with the creation of Space Checkers game, we are going to let monsters be eaten and removed from the board after a successful move. It’s a very important step because removing monsters from the board allows players to solve levels and progress through the game.

Starting with some theory, once the player picks a monster, the game highlights the possible moves, if any, as seen in step 2. We also need to store such possible moves somewhere, so I created a vector of points to store possible moves.

Once the player picks a monster, the vector is populated with possible moves, and once the monster is released somewhere in the board, I just need to check for the tile the monster landed on to be one in the vector of possible moves.

Then, since at each successful move a monster is eaten and must be removed from the board, we need to know which monster has to be removed. This is not a big problem, since we know the player just performed a successful move, we just need to know the direction the player moved the monster, and remove the monster which lies in the adjacent tile in the opposite side of the direction the player just moved.

A real world example: if the player moved the monster to the right, the monster to remove is the monster to the left of the tile where the moved monster landed.

Here is the source code:

Line 14: possibleLandings is the vector of points used to store possible landing tiles

Lines 104-130: I modified a bit checkMonster function to make it shorter. It works the same way, just look how I push possible moves into possibleLandings vector at line 115.

Lines 72-77: Checking if the current landing tile is inside possibleLandings vector. Look at line 73: unfortunately I could not use indexOf method as it does not work with variable passed by reference.

Lines 79-81: This is the old code to place the monster in its starting position if the move is not allowed.

Lines 82-98: code to execute if the move is allowed: monster position and properties are updated, as well as fieldArray values, then I determine the direction the monster moved, and remove the killed monster (lines 88-93).

And this is the result:

Now you can remove monsters by jumping over them. Next time we’ll see how to progress through levels.

Download the source code.

  • Tompa

    Very nice!
    Found one “bug” tho, if you hold one of the monsters and then rightclick,
    your monster will be placed where you pointer is when you leftclick your mouse again.

  • Pingback: Creation of Flash game Space Checkers – Step 3 – Emanuele Feronato « eaflash()

  • veeramani

    Nice!!!

    Thanks for helping me….

    tons of thanks

  • Rennan

    Hi, Emanuele!

    First of all, thank you for sharing with us your knowledge. I can´t wait to see the next step of Space Checkers Tutorial.

  • Athithan

    Hi Please give the idea about this peg game in plus combinations, see below.

    * * *
    * * *
    * * * * * * *
    * * * * * * *
    * * * * * * *
    * * *
    * * *

    Best regards
    Athi

  • Athithan

    – * * *
    – * * *
    * * * * * * *
    * * * * * * *
    * * * * * * *
    – * * *
    – * * *

  • TOMER

    Hi emanuele,
    how are you? you an amazing website i can sleep in it and it also helped me a lot.
    At the end of Space checkers part 3 you wrote that soon you will post how to continue and create more levels, when do ou think you can upload this tutorial?

    Thank you very much and again AMAZING BLOG!