Tilebased games in Flash 5 - Part 7
And now... maze-enemies. We´re gonna go with the absolute simplest kind of enemies. Their behavior will be something like this:
1. Dropped onto the map. 2. Pick a random direction(Up, Down, Left, Right) out of possible directions. 3. Check to see if I´m about to collide. If true, go to nr 2. 4. Check to see if I CAN get a NEW direction. If true, go to nr 2. 5. Move. 6. Go to nr 3.So we start as usual, drawing a map and adding a character, basicly where we were after tutorial nr 2. Could look something like this:
And here´s the fla for that one.
Now, make a copy of the charcater-movieclip and make it into an enemy-movieclip. Make the mapDrawing-function attach the enemys...
[insert explanation of the enemy-code, not finished.]And here´s an example of how it could turn out:
And here´s the fla for that.
This is of course a very basic type of enemy, not very smart. But in many cases it can be irritating enough. It would be pretty to easy expand it so that it could prioratize certain directions if it´s within a certain range of the character. If the character is only 2 tiles away to the left, it could prioratize moving left if possible.
From here to making more advanced enemies, I would suggest to have look at two algorithms, A*(a star) and Robust Tracing. They are both pathfinding algorithms which can be pretty useful in some cases.
But the approach when making enemies is always dependent on what type of game your making. It can be a good idea to find a similar game and look at the enemies there and see how they behave. And start working towards that behavior.
(C) OutsideOfSociety 2002.