Flash Actionscript 2.0 – Making a Turn Based Battle System

This tutorial is pretty much a continuation to the tutorial, “Making a 1on1 Battle System,” which you can find a link to in the resources section on this page. In the previous tutorial, you were shown how to make a battle system involving two characters, the hero and the enemy. The only real draw back was that it wasn’t turn based and they attacked at the same time. This tutorial will show you how to convert that system to turn based.

Step 1 – Enemy Attack Variable

On your main frame or setup frame (a blank frame you just use to house all your variables), press f9 and type in:

EnemyAttack = false;

This variable will keep your enemy from attacking and it will wait till your hero attacks before it attacks. When you have your hero attack, set up some frames to be shown like a movie clip of your hero’s attack. Set your attack button to jump to the first frame of the movie and on your last frame have it jump back to your main frame where your hero and enemy are staring each other down.

Step 2 – Coding the Attacks

On each attack frame type in:

stop();

function moveon(){
gotoAndStop(2);
}

setTimeout(moveon, 50);

The stop function keeps it from cycling through every frame in a split second while the function moveon tells it where to go next. The last part tells it to wait a little bit before going to the next frame because if it doesn’t, it’ll basically be the same as having no stop function at all. Where it says gotoAndStop(); replace the number with whatever number the next frame is after the one your currently typing in. Just a reminder, on the last frame have it go back to the frame where they’re staring each other down but also type in:

_root.EnemyAttack = true;

You’re setting your enemy attack variable to true and telling the enemy it’s their turn to attack.

Step 3 – Making the Enemy Attack

On your main frame where they are staring each other down, press f9 and type in:

if (EnemyAttack == true){

gotoAndStop();

}

Make another series of frames but this time showing the enemy attacking and where it says gotoAndStop(); add the number to the frame that starts the enemy attack. In each frame again type in the codes to make it stop for a bit then go on to the next frame as a movie clip would and on the last frame have it go back to the main frame and also add:

_root.EnemyAttack = false;

That’s telling the enemy that their attack is over and they have to wait for the hero to attack again before they can make another move. And that’s it for a basic turn based battle system. There are ways to have your enemy attack without waiting using a timer system and make an enemy use different attacks using a roulette type system but I’ll be explaining those in future tutorials. If you’d like to know how to do those sooner or if you have questions about this tutorial you can email me at [email protected]


People also view

Leave a Reply

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