Build 10 classic Flash games and learn game development along the way with this ultra-fast paced game development course.

If you love this blog, this is the book for you.

Buy the book

Get the source code of 12 commercial Flash games, which have been loaded more than 50 million times!

Learn from real world successful examples.

Get it now

Box2D for Flash Games teaches you how to make Flash physics games from scratch with the most advanced features.

Create the new Flash game smashing hit.

Buy the book

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.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 5.00 out of 5)
Loading ... Loading ...
Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 4 comments

  1. Tompa

    on July 3, 2012 at 2:00 am

    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.

  2. Creation of Flash game Space Checkers – Step 3 – Emanuele Feronato « eaflash

    on July 3, 2012 at 9:48 am

    [...] on http://www.emanueleferonato.com Share this:TwitterFacebookLike this:LikeBe the first to like [...]

  3. veeramani

    on July 10, 2012 at 7:11 am

    Nice!!!

    Thanks for helping me….

    tons of thanks

  4. Rennan

    on September 16, 2012 at 10:26 pm

    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.