First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing! | Flash Jobs
Search tutorials
Author: kyle | Website: http://www.grindergames.com/
Are you ready for some advanced scripting!

Well if you aren't then you need to get better with scripting.


Below is the game we are making...





Now we will get started!

create a movieclip called 'mountain' and place it in the background. Make some nice mountains to go with it.

create another movieclip called 'bg_nature' place the right infront of the mountains.

create another movieclip called 'ground' and place this infront of both.

create another movieclip called 'water' and place this in front of all three.

call the first frame 'game1'.

Write the following script in the frame this game will be in.

var move_speed = 20;
var rotation_speed = 20;
var mountain_offset = 0;
var nature_offset = 0;
function suit_frame(variable, center) {
if (center == "x") {
return (variable*-1)+225;
} else if (center == "y") {
return (variable*-1)+200;
} else if (center == "yyou") {
return (variable*-1)+300;
} else {
return variable*-1;
}
}
onEnterFrame = function() {
if (coin._x > you._x) {
arrow_r._visible = true;
arrow_l._visible = false;
} else {
arrow_r._visible = false;
arrow_l._visible = true;
}
arrow_r._x = suit_frame(_x)+530;
arrow_l._x = suit_frame(_x)+20;
menu._x = suit_frame(_x)+(menu._width/2)+20;
_y = suit_frame(you._y, "yyou");
_x = suit_frame(you._x, "x");
mountain._x = suit_frame(_x, "x")-Math.round(mountain_offset);
bg_nature._x = suit_frame(_x, "x")-Math.round(nature_offset);
if (Key.isDown(Key.RIGHT)) {
you._x += move_speed;
you._rotation += 20;
mountain_offset += 5.5;
nature_offset += 8.5;
}
if (Key.isDown(Key.LEFT)) {
you._x -= move_speed;
you._rotation -= 20;
mountain_offset -= 5.5;
nature_offset -= 8.5;
}
if (you.hitTest(tree1.hitarea)) {
you._x += move_speed;
you._rotation += 20;
mountain_offset += 8.5;
nature_offset += 8.5;
}
if (you.hitTest(tree2.hitarea)) {
you._x -= move_speed;
you._rotation -= 20;
mountain_offset -= 5.5;
nature_offset -= 8.5;
}
}


I know what you are thinking... What does that all mean?

When I write '_x' in the script that if the x and y coordinates of the frame. Otherwise known as our camera. When you give the frame x and y coordinates you need to multiply them by -1 to make them the opposite value. This is how the frame reads x and y coordinates.

The function suite_frame(); makes the scale of an object reversed. The second variable in the function will make the x and y scale at a sertain point on the screen...

'x' this will center the camera in the middle of the screen on the x axis.
'y' this will center the camera in the middle of the screen on the y axis.
'yyou' this will center the camera twards the bottom of the screen.

The mountains and background nature move slower than the foreground so the have an offset of the actual value. When moving you to the right I need to increase the offset to make it move slower than the actuall screen.

All objects that stay still on the screen must be given an x and y coordinate value depending on the x and y coordinates of the camera. This is because all of the objects on the screen will move off the screen because of the position if the camera.

The hitTest states that you cannot go beyond the trees on the left and right sides. Inside the tree symbol is a blank movieclip that goes over the trunk this is actually what you are hit testing.

The arrows are the movie clips that specify where the coin is in relation to you. The menu is what specifies your overall score.

If this is too confusing you can always e-mail me at... kjb999@mail.com

Now create a movieclip called 'you'.

Place the folowing script inside it...



onClipEvent (load) {
_root.points = 0;
_root.coin_c = 2;
_root.faller_c = 2;
_root.high_score = SharedObject.getLocal("mr_Shrimp","/");
if (_root.high_score.data.score == undefined) {
_root.high_score.data.score = 0;
}
}
onClipEvent (enterFrame) {
_root.high_score.data.bloodx = this._x;
if (_root.points > _root.high_score.data.score) {
_root.high_score.data.score = _root.points;
_root.high_score.data.new_high = new Array(1, _root.high_score.data.score, true);
}
_root.high_score2 = _root.high_score.data.score;
_root.when = random(15);
if (_root.when == 5) {
_root.faller1.duplicateMovieClip("faller"+_root.faller_c, _root.faller_c);
if (_root.points >= 8000) {
_root["faller"+_root.faller_c].gotoAndStop(random(3)+1);
} else if (_root.points >= 1000) {
_root["faller"+_root.faller_c].gotoAndStop(random(2)+1);
}
_root.faller_c++;
}
}


In this script it duplicates the movieClip that makes things fall from the sky. It also keeps track of your high score.

make a new symbol called 'faller1' and make 3 frames. In each frame make a different item that falls down. And add stop(); to all the frames.

Add the folowing script to 'faller1'...

onClipEvent (load) {
this._y = 0;
this._x = random(1810)-810;
}
onClipEvent (enterFrame) {
this._y += 20;
if (this._y>=400) {
this.removeMovieClip();
}
if (this._currentframe == 2) {
this._y += 10;
}
if (this.hitTest(_root.you)) {
if (_root.high_score.data.new_high[2] == true) {
_parent.gotoAndStop("scores");
_parent._y = 0;
_parent._x = 0;
} else {
_parent.gotoAndStop("intro");
_parent._y = 0;
_parent._x = 0;
}
}
}

Now we need to create some symbols...
1. 'tree1' tree on the left of the screen. Inside that symbol create another symbol called 'hitarea' that covers up the trunk. Make this invisible with script.
2. 'tree2' tree on the right of the screen. Inside that symbol create another symbol called 'hitarea' that covers up the trunk. Make this invisible with script.
3. 'arrow_r' arrow pointing to the right. Symbolizes where the coin is in relation to you.
4. 'arrow_l' arrow pointing to the right. Symbolizes where the coin is in relation to you.
5. 'coin' this is that rotating coin that you collect.

write the following script inside the movie clip - 'coin'.

onClipEvent (load) {
this._y = 0;
this._x = random(1700)-700;
}
onClipEvent (enterFrame) {
this._y += 30;
if (this._y>=330) {
this._y -= 30;
}
if (this.hitTest(_root.you)) {
_root.points += 100;
this._y = 0;
this._x = random(1700)-700;
}
}

This script determines where the coin is and when you collect it.

Now create another movieClip called 'menu'. This should look like a red outline for the scores. Inside this movie clip create a text feild that shows the variable '_root.points'. Make sure it is dynamic.


Now create another frame called 'intro'. Inside this frame you should have a button that goes to the frame 'game1'.

Now create another frame called 'scores'...

Inside this frame make a movieclip that says submit. The code inside it is the following...

onClipEvent(load) {
_root.high_score = SharedObject.getLocal("mr_Shrimp","/");
}
onClipEvent(enterFrame) {
_root.stage.text = _root.high_score.data.new_high[0];
_root.score.text = _root.high_score.data.new_high[1];
}
on(release) {
_root.high_score.data["name"+_root.high_score.data.new_high[0]] = _root.name.text;
_root.high_score.data.new_high[2] = false;
_parent.gotoAndStop("intro");
}

Now create a text feild. Call it 'stage'. Make it dynamic.

Now create another text field Call it 'score'. Make it dynamic.

Make one more text field called name and make this input.



Congradulations! You have made a simple side scrolling game!

If you have any questions e-mail me at...

kjb999@mail.com
» Level Advanced

Added: 2006-11-07
Rating: 6 Votes: 14
(10 being the highest)
» Author
I script for myself and often use advanced scripting. I am 13 years old.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.