tutorial game flash

game flash gimana cara buatnya?
nih disini ada tutorial membuat flash platform game character follower


In this tutorial you will learn how to create a platform game with a jumping an walking system, and the ability to make npc like objects follow you through the game, using the efficiency of external actionScript (2.0) files by using classes.

Step 1:

Create a folder in which you want to save your files. Next, in Flash, create 1 flash file (AS 2.0), and 4 actionScript files.

Save the flash file as "game".

Save the actionScript files as the following:

"character" (in this file we will write the code needed to control the character)

"follower" (in this file we will write the code needed to control the follower)

"follower_0" (in this file we will set variables for follower number one)

"follower_1" (in this file we will set variables for follower number two)

Step 2:

In the "character" file, write or paste this code:

class character extends MovieClip {
private var velocity_y:Object;
private var walkSpeed:Object;
private var gravity:Object;
private var damping:Object;
private var jumpCounter:Object;
function character() {
this.velocity_y = 0;
this.walkSpeed = 5;
this.gravity = 2.5;
this.damping = 0.92;
this.jumpCounter = 0;
this.onEnterFrame = character_onEnterFrame;
function character_onEnterFrame():Void {
this._y += this.velocity_y;
this.velocity_y *= this.damping;
//horizontal movement
if (!_root.rightBound.hitTest(_x, _y, true)) {
if (Key.isDown(68)) {
this._x += this.walkSpeed;
}
} else {
this._x += 0;
}
if (!_root.leftBound.hitTest(_x, _y, true)) {
if (Key.isDown(65)) {
this._x -= this.walkSpeed;
}
} else {
this._x -= 0;
}
//gravity movement
if (!_root.ground.hitTest(_x, _y, true)) {
this.velocity_y += this.gravity;
} else {
if (_root.ground.hitTest(_x, _y, true) && this.velocity_y > -15 ) {
this.velocity_y = 0;
}
if (_root.ground.hitTest(_x, _y-3, true) && this.velocity_y > -15 ) {
this.velocity_y -= 0.5;
}
}
//vertical movement
if (this.velocity_y < 50 && _root.ground.hitTest(_x, _y, true) && Key.isDown(87)) {
this.velocity_y = -25;
this.jumpCounter = 15;
}
}
}
}

I don't feel like actually explaining this code, because it kind of speaks for itself, and if you know actionScript a little, this shouldn't be a problem at all...

Next, save the file.

Step 3:

In the "follower" file, write or paste this code:

class follower extends MovieClip {
private var _xPoint:Object;
private var _yPoint:Object;
private var velocity_y:Object;
private var walkSpeed:Object;
private var gravity:Object;
private var damping:Object;
private var followerNum:Object;
function follower() {
this._xPoint = _root.char._x;
this._yPoint = _root.char._y;
this.velocity_y = 0;
this.walkSpeed = 5;
this.gravity = 2.5;
this.damping = 0.92;
this.onEnterFrame = follower_onEnterFrame;
function follower_onEnterFrame():Void {
//set general variables
this._y += this.velocity_y;
this.velocity_y *= this.damping;
//set _xPoint & _yPoint
if (this.followerNum == 0){
this._xPoint = _root.char._x;
this._yPoint = _root.char._y;
}
if (this.followerNum == 1){
this._xPoint = _root.follower0._x;
this._yPoint = _root.follower0._y;
}
if (this.followerNum == 2){
this._xPoint = _root.follower1._x;
this._yPoint = _root.follower1._y;
}
if (this.followerNum == 3){
this._xPoint = _root.follower2._x;
this._yPoint = _root.follower2._y;
}
if (this.followerNum == 4){
this._xPoint = _root.follower3._x;
this._yPoint = _root.follower3._y;
}
//horizontal movement
if (this._x < this._xPoint-30) {
this._x += this.walkSpeed;
}
if (this._x > this._xPoint+30) {
this._x -= this.walkSpeed;
}
//gravity movement
if (!_root.ground.hitTest(_x, _y, true)) {
this.velocity_y += this.gravity;
} else {
if (_root.ground.hitTest(_x, _y, true)) {
this.velocity_y = 0;
}
if (_root.ground.hitTest(_x, _y-3, true)) {
this.velocity_y -= 0.5;
}
}
//jumping movement
if (_root.ground.hitTest(_x, _y, true) && this._y > this._yPoint+50) {
this.velocity_y = -30;
}
}
}
}

As will become usual; save the file.

Step 4:

In the "follower_0" file, put the following code:

class follower_0 extends follower {
function follower_0(){
this.followerNum = 0;
}
}

Save the file.

In the "follower_1" file, put the following code:

class follower_1 extends follower {
function follower_1(){
this.followerNum = 1;
}
}

And again, save the file.

Step 5:

Ok, was all of the codes, so now open your "game" file. Create 2 layers, and name them "character" and "bounds".

Inside the 1st frame of your "character" layer, draw 3 objects that you wish to have as a character, and as followers. A square would do fine.

Convert one square to a movie clip (hotKey is F8), and make sure you set the align to bottom. Next, tick the box of 'export for actionScript' and make sure the identifier and class names are both set to "character". Set the character's instance name to "char".

Convert the next square to a movie clip, tick the box to 'export for actionScript' and set the identifier and class names are both set to "follower_0". Set the follower's instance name to "follower0".

Convert the next square to a movie clip, tick the box to 'export for actionScript' and set the identifier and class names are both set to "follower_1". Set the follower's instance name to "follower1".

In your "bounds" layer, simply create a horizontally stretched rectangle, convert it to a movie clip, and set it's instance name to "ground".

Make sure your "ground" bound is below your character and followers, because otherwise they would keep falling on and on...

If you test your movie now, it should work.

Posting Komentar

Untuk posting kode, bisa di parse dulu gan, pake tool parse yang udah disediakan di website ini https://www.rahmancyber.net/p/parse-code.html

agar kodenya tidak hilang... ^_^

Lebih baru Lebih lama

نموذج الاتصال