Notes: I will refer to a moveclip as a MC
What will you learn?
From this tutorial you will learn how to create a basic birds eye view game which you will be able to adapt to your own style.
Lets get started
Ok, what you need to do is decide on how your character is going to look. For example, my character is a human. With this in mind you need to create your character from a birds eye view.
From here you need to select your whole character and convert it into a moveclip, with a registration point of centre. After this, give that symbol and instance name of "hero" without the quotes.
draw character> convert to a moveclip> centre registration point> give instance name of hero
Character continues
With your hero MC on the stage, double click it. This brings you to edit mode. From here you need to insert another 3 frames. In total you should have 4 frames. Your first frame should contain your hero facing upwards, the next frame should contain a MC with your character facing upwards walking.( not going into depth about walking cycles from above). Your third frame should contain an MC of your character facing to the right, and the last should contain an MC of your character walking right.
Note: your walking MC's do not have to move visually as the code will do this.
Moving your character
The following code shouldn't take too much knowledge of AS to understand. I will briefly go over the coding. Place the following code onto your hero MC:
onClipEvent (load) {
speed = 5;
}
onClipEvent (enterFrame) {
if(this._y>300) {
this._y=300;
}
if(this._y<0) {
this._y=0;
}
if(this._x>400) {
this._x=400;
}
if(this._x<0) {
this._x=0;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
_yscale = +100;
this.gotoAndStop(2);
_y -= speed;
}else if (Key.isDown(Key.DOWN)) {
_yscale = -100;
this.gotoAndStop(2);
_y += speed;
}else if (Key.isDown(Key.LEFT)) {
_xscale = -100;
this.gotoAndStop(3);
_x -= speed;
}else if (Key.isDown(Key.RIGHT)) {
_xscale = +100;
this.gotoAndStop(3);
_x += speed;
} else {
this.gotoAndPlay(1);
}
}
onClipEvent (load) {
speed = 5;
}
This section tells the game to load a variable of speed.
onClipEvent (enterFrame) {
if(this._y>300) {
this._y=300;
}
if(this._y<0) {
this._y=0;
}
if(this._x>400) {
this._x=400;
}
if(this._x<0) {
this._x=0;
}
}
Change the numbers in here depending on what size your canvas is.
This section tells the character that it cannot move out of the boundaries which have been set.
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
_yscale = +100;
this.gotoAndStop(2);
_y -= speed;
}else if (Key.isDown(Key.DOWN)) {
_yscale = -100;
this.gotoAndStop(2);
_y += speed;
}else if (Key.isDown(Key.LEFT)) {
_xscale = -100;
this.gotoAndStop(3);
_x -= speed;
}else if (Key.isDown(Key.RIGHT)) {
_xscale = +100;
this.gotoAndStop(3);
_x += speed;
} else {
this.gotoAndPlay(1);
}
}
The last part of the code tells the game that, if a certain key is down, do something. In our case it plays out moving animations. Else, it plays another frame.
_xscale = +100; This is the scaling on the _x axis
_x += speed; this tells it to move along the _x axis using the variable "speed"
The Room
To make a realistic environment, you need to have objects which the character cannot walk through.
A code is used to test weather something is touching something else. If so, do something. Here's the code:
onClipEvent (enterFrame) {
if (hitTest(_root.hero)) {
if (_root.hero._x<=_x-(_root.hero._width/2)+_
root.hero.speed) {
_root.hero._x = _x-_root.hero._width/2-_root.hero.speed
} else if (_root.hero._x>=_x+_width-_root.hero.speed
) {
_root.hero._x = _x+_width+(_root.hero._width/2)
} else if (_root.hero._y<=_y-(_root.hero._height/2)+
_root.hero.speed) {
_root.hero._y = _y-_root.hero._height/2-_root.hero.speed
} else if (_root.hero._y>=_y+_height-_root.hero.spee
d) {
_root.hero._y = _y+_height+(_root.hero._height/2)
}
}
}
Place this code on any MC object you do not want the character to walk through.
Room information
Maybe you want the game to be more interactive. A fun and easy way to do this is to show whitty comments about objects around the room. To do this you need to make the comments.
Write anything on the stage, e.g "this is a rug". Select the text box and convert it to an MC (f8). You may want to give it an instance name of what the comment is. ( "ruginfo")
You now need to decide what is to be clicked in order for the information to be displayed. Make sure the object is an MC and place this code on it.
onClipEvent(load){
_root.ruginfo._visible=false;
}
on(press){
_root.ruginfo._visible=true;
}
on(release){
_root.ruginfo._visible=false;
}
Using visibility is a common way of displaying objects if you dont want them to always appear.
onClipEvent(load){
_root.ruginfo._visible=false;
}
This tells the movie/game to load the ruginfo to be invisible.
on(press){
_root.ruginfo._visible=true;
}
Once the object is pressed , the ruginfo becomes visible
on(release){
_root.ruginfo._visible=false;
}
Once the mouse click is released the ruginfo returns to invisible.
thats all folks!
Using what i have told you, you should be able to throw together some nice games. Hopefully people will find this usefull,
If you would like to comment on my tutorial feel free.
_danny_