Adobe Flash

Platform Games

What I learned

I learned the basics of Action Script 2.0, as well as the rudimentary knowledge of making a platform game.

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 ground is by far the simplest thing appearance wise and coding wise. The ground can be as complicated looking as you want but all you ultimately have to do is make a few rectangles, and to make it even simpler, the ground has no coding whatsoever.

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
}
}

An enemy is a somewhat intermediate skill to have. The enemy I decided to make in my game is just a red ball that when you touch it makes you restart the level. I like to think of an enemy as a miniature moving restart box since it has the exact same coding as the restart box.

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

Without coding, the game would be nothing, you have to have coding for just about everything. Also another very important thing is the "<instant name>", without this the game wouldn't work either. An instant name is what the symbol represents, so the coding can work. Like the character's instant name for the coding I used would be "char" if you didn't put that in the ball wouldn't move at all, and same for the ground, although the instant name for the ground is simply ground, without it, the ball would just fall through the platforms. The most important code is definitely the simplest, "stop() ;". In the game I made a frame is a level, and if you can remember when we did the butterfly assignment, the end product would go through the frames, and loop and restart, like a gif file. But that is not what you want when you are making a game, you want it to stop on each individual frame so you can play the game instead of it going through all the levels not allowing you to play. That is what the "stop() ;" code does, it makes it stop on each individual frame. As you can see the coding is the most important aspect to creating a game.

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