Search tutorials
Ok I'll try to make this as simple as possible;
Open up Flash and open up a new file (It should work on any version of flash really, although I only tested MX & MX 2004)
Create a new layer and call it Controls. Now, create a dynamic text box. If you know how to make dynamic text boxes skip this part
----------------------------------------------------------------------
How to make Dynamic Text Boxes:
Create a standard text box (Control & T). Now, select the Box which says Static Text, and scroll down to Dynamic Text. Done; wasn't that easy?
----------------------------------------------------------------------
Now, give it the variable name of health.
On the first frame of Controls put this script in:
health = 100;
This tells the dynamic text box called health to have a value of 100. If in your game you want 35 health, change it to health = 35;
Now, create a new layer called Character. This will be the man youre controlling.
Draw a small dot, or whatever you want to move about. Select it, Convert to Symbol (F8) and call it Character.
Also give it an instance name of character (don't change this one yet)
Next step is to make a new layer called Enemy. Draw the "Bad Guy" or whatever you want your character to run into. Convert him into a symbol and give him an instance name of Red. (Red because in the .zip file I called it red)
Next step,
On the Controls layer create a new frame and give it the frame label Gameover. Then, give it some frame script saying: Stop();
Now for some script, give this code to the character:
onClipEvent (enterFrame) {
if (this.hitTest(_root.Red)) {
_root.health -= 1;
if (_root.health == 0) {
_root.gotoAndStop("Gameover");
}
}
}
What does this mean in English? It means:
When the movie clip called Character Comes into contact with another Movie Clip called Red it will look for a dynamic text box called health and take away 1 from it. If the dynamic text box called health = 100 it will goto and stop on the frame called "Gameover"
But, the character can't move; what use is that?
Give this script to the character:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x = _x-10;
}
if (Key.isDown(Key.UP)) {
_y = _y-10;
}
if (Key.isDown(Key.RIGHT)) {
_x = _x+10;
}
if (Key.isDown(Key.DOWN)) {
_y = _y+10;
}
}
So now it looks like:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x = _x-10;
}
if (Key.isDown(Key.UP)) {
_y = _y-10;
}
if (Key.isDown(Key.RIGHT)) {
_x = _x+10;
}
if (Key.isDown(Key.DOWN)) {
_y = _y+10;
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.Red)) {
_root.health -= 1;
if (_root.health == 0) {
_root.gotoAndStop("Gameover");
}
}
}
And there you go, Health system done. If you want to make it more complex you can start by fixing a glitch Ive found. If you made it so the enemy did 3 damage the health doesnt go onto zero, it goes onto 1, then -2. The script only goes to Gameover if it equals 0. To fix this, you need to add something which makes the script say if health = 0 or under.
| » Level Basic |
|
Added: 2004-12-27 Rating: 3 Votes: 10 |
| » Author |
| Likes Flash when it works- Hates it when it doesn't |
| » Download |
| Download the files used in this tutorial. |
| Download (11 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!