Adobe Flash
Platform Games
What I learned
Some of the Basics
Some of the basics of making a platform game are making a character, the ground, the restart box, an enemy, and a goal. Also a great, but not necessary, skill is knowing how to code the actions for the symbols, which I have obtained knowledge of as well.
A character is one of the simplest things in the game, but has the most complicated coding. In the game I made, my character is just a blue ball, but has the most intricate coding. The code I used for my character looks like this:
onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var speed:Number = 7;
var maxJump:Number = -12;
var touchingGround:Boolean = false;
}
onClipEvent (enterFrame) {
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y, true)) {
_y -= gravity;
grav = 0;
}
if (ground.hitTest(_x, _y+5, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.UP) && touchingGround) {
grav = maxJump;
}
if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
_x -= speed;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
_x += speed;
}
if (ground.hitTest(_x, _y-(height), true)) {
grav = 3;
}
}
The restart box fairly simple, but with my experience is hard to perfect. The restart box is a rectangle that runs below the stage and makes the level restart when you fall off the stage. To make the restart box you must simply make an invisible rectangle and put a simple code into it. The code looks like this:
onClipEvent (enterFrame) {
if (_root.char.hitTest(this)) {
_root.char._x = charX = 123.00
_root.char._y = chary = 119.00
}
}
A goal, or as I called a portal in my game, is a place that you want to character to reach. Making the goal is pretty easy as well, and the coding is very similar to the enemy and restart box since its just the same thing but instead of restarting the same level it just goes to the next one. The coding looks like this:
onClipEvent (enterFrame) {
if (this.hitTest(_root.char))
{
_root.gotoAndStop();
}
}
Inside those two parentheses by the "gotoAndStop" all you have to put in is the frame number and it will work perfectly.
Coding
My Game
To find my game, go to the S-Share and go to:
S:\Projects\West Media\Flash Lessons\Game\Champagne\2nd\GAME(EXTENDED)By Brett H..swf