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 2

Here we go with the second part of the step by step Space Checkers tutorial. In the previous step I showed you how to initialize the game and move the monsters, now it’s time to develop game logic checking if the player picked a monster which can be moved and eventually showing where the monster can be placed.

In the original game when the player picks a monster, a red marker is placed over its tile.

If the monster can be moved, a cyan marker is placed over its tile, and one or more yellow markers are placed on the tiles the monster can be placed on.

This is what we are going to create:

Pick a monster, and see the tiles highlight according to the rules mentioned above.

Three new symbols have been created, called StartMove, PossibleMove and WrongMove, representing respectively the highlights for the starting tile, the possible move tiles and the highlight for a wrong move.

Here’s how I changed the script:

Let me explain the most interesting parts:

Line 7: a new sprite called moveContainer is created. It will contain all highlights

Line 19: moveContainer is added between squareContainer and monsterContainer. This is important as it affects the hierarchy of Display Objects. Highlights will stay in front of the tiles, and monsters will stay in front of highlights.

Lines 35-36: adding two custom properties to monster, called theRow and theCol, storing monster’s row and column.

Line 55: the core of this script: once a monster is picked, checkMonster functions will handle highlights.

checkMonster function (lines 74-117)needs to be optimized, but it just checks for possible moves at the top, left, bottom and right of the picked monster, placing the right highlights according to monster capabilities.

The really interesting function is checkField (lines 118-125) which receives as arguments the picked monster, the row offset to watch (+1 = down, -1 = up) and the column offset to watch (+1 = right, -1 = left).

Line 119: to check if it’s a valid move, we can look two tiles further. The first tile must be a monster, and the second tile must be an empty tile. But first, we need to check if tiles exist. This statement checks if tiles exist

Line 120: Now it’s time to see if the first tile is a monster and the second tile is an empty tile.

Line 121: returns true: it’s a valid move

Line 124: returns false: it’s an illegal move

Next time, killing monster and completing the level.

Download the source code.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4.80 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 2 comments

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

    on June 25, 2012 at 8:21 am

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

  2. veeramani

    on June 26, 2012 at 10:29 am

    thanks again…….