membuat game platform flash
lihat tutorial videonya di
https://www.youtube.com/watch?v=HfwNPcgPwVM
dan ini adalah actionscript 02 nya
onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var maxspeed:Number = 10;
var xspeed:Number = 0;
var acceleration:Number = 2;
var maxJump:Number = -15;
var friction:Number = 0.9;
var touchingGround:Boolean = false;
}
onClipEvent (enterFrame) {
xspeed *= friction;
if (Math.abs(speed) < 0.3) {
xspeed = 0;
}
_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)) {
if(touchingGround)
this.gotoAndStop(3);
}
else if(Key.isDown(Key.LEFT)) {
if(touchingGround)
this.gotoAndStop(4);
}
else if(Key.isDown(Key.DOWN)) {
if(touchingGround) {
if(this._currentframe == 1 || this._currentframe == 3) {
this.gotoAndStop(7);
}
if(this._currentframe == 2 || this._currentframe == 4) {
this.gotoAndStop(8);
}
}
}
if(Key.isDown(Key.UP)) {
if(!touchingGround) {
if(this._currentframe == 1 || this._currentframe == 3) {
this.gotoAndStop(5);
}
if(this._currentframe == 2 || this._currentframe == 4) {
this.gotoAndStop(6);
}
}
}
if (touchingGround) {
if(this._currentframe == 5)
this.gotoAndStop(1);
if(this._currentframe == 6)
this.gotoAndStop(2);
}
if (Key.isDown(Key.RIGHT)) {
if ( xspeed < maxspeed ) {
xspeed += acceleration;
}
}
if (Key.isDown(Key.LEFT)) {
if ( Math.abs(xspeed) < maxspeed ) {
xspeed -= acceleration;
}
}
if (Key.isDown(Key.UP) && touchingGround) {
grav = maxJump;
}
if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
acceleration = -2;
xspeed = 0;
xspeed += acceleration;
_x += xspeed ;
}else{
acceleration = 2;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
acceleration = -2;
xspeed = 0;
xspeed -= acceleration;
_x += xspeed ;
}else{
acceleration = 2;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true))
{
_x += xspeed;
}
if (ground.hitTest(_x, _y-(height), true))
{
grav = 3;
}
_x += xspeed;
}
https://www.youtube.com/watch?v=HfwNPcgPwVM
dan ini adalah actionscript 02 nya
onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var maxspeed:Number = 10;
var xspeed:Number = 0;
var acceleration:Number = 2;
var maxJump:Number = -15;
var friction:Number = 0.9;
var touchingGround:Boolean = false;
}
onClipEvent (enterFrame) {
xspeed *= friction;
if (Math.abs(speed) < 0.3) {
xspeed = 0;
}
_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)) {
if(touchingGround)
this.gotoAndStop(3);
}
else if(Key.isDown(Key.LEFT)) {
if(touchingGround)
this.gotoAndStop(4);
}
else if(Key.isDown(Key.DOWN)) {
if(touchingGround) {
if(this._currentframe == 1 || this._currentframe == 3) {
this.gotoAndStop(7);
}
if(this._currentframe == 2 || this._currentframe == 4) {
this.gotoAndStop(8);
}
}
}
if(Key.isDown(Key.UP)) {
if(!touchingGround) {
if(this._currentframe == 1 || this._currentframe == 3) {
this.gotoAndStop(5);
}
if(this._currentframe == 2 || this._currentframe == 4) {
this.gotoAndStop(6);
}
}
}
if (touchingGround) {
if(this._currentframe == 5)
this.gotoAndStop(1);
if(this._currentframe == 6)
this.gotoAndStop(2);
}
if (Key.isDown(Key.RIGHT)) {
if ( xspeed < maxspeed ) {
xspeed += acceleration;
}
}
if (Key.isDown(Key.LEFT)) {
if ( Math.abs(xspeed) < maxspeed ) {
xspeed -= acceleration;
}
}
if (Key.isDown(Key.UP) && touchingGround) {
grav = maxJump;
}
if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
acceleration = -2;
xspeed = 0;
xspeed += acceleration;
_x += xspeed ;
}else{
acceleration = 2;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
acceleration = -2;
xspeed = 0;
xspeed -= acceleration;
_x += xspeed ;
}else{
acceleration = 2;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true))
{
_x += xspeed;
}
if (ground.hitTest(_x, _y-(height), true))
{
grav = 3;
}
_x += xspeed;
}
Comments
Post a Comment