tisdag 27 maj 2008

Basic game tutorial

This is my first tutorial, so bear with me.

In this tutorial you're going to learn how to make a basic flash game, with score and stuff..
This tutorial is made in adobe flash CS3 Pro, but I'm pretty sure that any version with AS 2.0 will work just as fine.
Let's get to it!

First, create a new flash file (AS 2.0), then set up the background color to your liking.
Dimensions can be anything, I'll be using 550*400px.
I will use a framerate of 30fps, it's nice and smooth.

Now, draw a circle, and convert it to a movieClip (mark it, press F8).
Name it "ball", and instance it the same.
Select the movieclip, and press F9, then paste the following code into the actions panel.

onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= 8;
} else if (Key.isDown(Key.DOWN)) {
this._y += 8;
}
if (Key.isDown(Key.LEFT)) {
this._x -= 8;
} else if (Key.isDown(Key.RIGHT)) {
this._x += 8;
}
}

So what does this code do? Well, it checks if one of the arrow keys is down, and if it is, it changes the balls x or y position..






Let's make this a maze game then.. create some kind of maze, make it a movieclip, and instance it as "maze".
Now replace the code on the ball movieclip, with:

onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= 8;
} else if (Key.isDown(Key.DOWN)) {
this._y += 8;
}
if (Key.isDown(Key.LEFT)) {
this._x -= 8;
} else if (Key.isDown(Key.RIGHT)) {
this._x += 8;
}
if (_root.maze.hitTest(this._x,this._y,true)) {
_root.ball._x = 75;
_root.ball._y = 35;
}

}

This is how my version looks;





In the next tut, we will look at gravity and rotation.
See ya <3


0 kommentarer:

Skicka en kommentar

Prenumerera på Kommentarer till inlägget [Atom]

<< Startsida