Untitled
By: a guest | Sep 2nd, 2010 | Syntax:
ActionScript | Size: 1.14 KB | Hits: 19 | Expires: Never
onClipEvent (load) {
speed = 8;
gravity = 0;
r = _height/1.2;
jumping = false;
var scale:Number = _xscale;
jumpheight = 15;
running = false;
var touchingGround = false;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_xscale = +scale;
if(touchingGround == true) {
this.character.gotoAndStop(2);
}
_x += speed;
} else if (Key.isDown(Key.LEFT)) {
_xscale = -scale;
if(touchingGround == true) {
this.character.gotoAndStop(2);
}
_x -= speed;
} else {
if (touchingGround == true) {
this.character.gotoAndStop(1);
}
}
if (Key.isDown(Key.UP) && !jumping) {
gravity = -jumpheight;
jumping = true;
this.character.gotoAndStop(3);
}
if (!_root.ground.hitTest(_x, _y, true)) {
gravity++;
_y += gravity;
touchingGround = false;
} else {
jumping = false;
touchingGround = true;
gravity = 0;
}
while (_root.ground.hitTest(_x, _y-1+r, true)) {
gravity = 0;
jumping = false;
_y--;
touchingGround = true;
}
if(touchingGround == false){
this.character.gotoAndStop(3);
}
if(gravity > 1 || gravity < 0){
this.character.gotoAndStop(3);
}
}