[cs3] Creating a basic Flash platform game, part 1
Creating a basic Flash platform game, part 1
In this tutorial you will be making:
-A main character
-Terrain
TERRAIN
1. Draw your terrain. For this you should probably use a straight, horizontal line.
2. Convert your line into a movie clip.
3. Name it “terrain” (no quotes).
MAIN CHARACTER/AVATAR
1. Draw the body of your character (no legs or arms yet, and no head if you want it animated).
2. Convert it to a movie clip.
3. Name it “man” (no quotes).
4. Double click on the character to edit.
5. Insert the action stop(); on the first frame.
6. Use the next few frames to animate your character walking.
7. Double click on the background to deselect the character.
8. Add these codes to the character.
onClipEvent (load) {
gravity = 0.2; yspeed = 0; xspeed = 1; jumping = 0;
}
onClipEvent (enterFrame) {
if (_root.go) {
if (Key.isDown(Key.LEFT)) {
if (!_root.terrain.hitTest(_x-_width/2, _y+_height/4, true)) {
_x -= xspeed;
}
} if (Key.isDown(Key.RIGHT)) {
if (!_root.terrain.hitTest(_x+_width/2, _y+_height/4, true)) {
_x += xspeed;
}
}if((Key.isDown(Key.UP))(!jumping)){
yspeed = -5; jumping = 1;
} yspeed += gravity; while (_root.terrain.hitTest(_x, _y+_height/2, true)) {
_y--; yspeed = 0; jumping = 0;
} if ((!_root.terrain.hitTest(_x, _y+_height/2+1, true)) or (yspeed<0)) {
_y += yspeed;
} else {
yspeed = 0; jumping = 0;
}
}
} onClipEvent (load) {
scale = _xscale;
} onClipEvent (enterFrame) {
if (key.isdown(key.right)) {
this._x += 10; _xscale = scale; play();
} if (key.isdown(key.left)) {
this._x -= 10; _xscale = -scale; play();
}
}