/* This code is Copyright (C) 2007 Alex Smith
* Removing this notice will result in your immediate
* death. */
onClipEvent (load) {
speed = 0;
maxmove = 15;
jumping = true;
jump = 0;
/* Function to test if we have hit any of the ground
* objects. When you add some ground, add it in here */
var doGroundHitTest = function() {
if (_root.ground.hitTest(this._x, (this._y + this._height + 2), true)) {
return true;
} else {
return false;
}
}
/* Function to test if we died */
var doDeathTest = function() {
if (this._y > 1200) {
_root._x = 0
_root.gotoAndPlay("fall");
}
}
/* Function to test if we hit a wall */
var doWallHitTest = function(dir) {
if (dir == "left") {
if(_root.left_wall.hitTest(this._x - 10, this._y, true)) {
return true;
} else {
return false;
}
} else if (dir == "right") {
if (_root.wall2.hitTest(this._x + 30, this._y, true)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
/* Function to test if we are on a spring */
var doSpringTest = function() {
if (_root.spring1.hitTest(this._x, (this._y + this._height + 2), true)) {
jumping = true;
jump = 20;
}
}
}
onClipEvent (enterFrame) {
if (!doGroundHitTest() && !jumping) {
this._y += 6;
jumping = true;
jump = 0;
falling = true;
}
if (_root.dead) {
this.gotoAndStop("dead");
} else {
speed *= .85;
if (speed > 0) {
dir = "right";
} else if (speed < 0) {
dir = "left";
}
// if (dir == "right" && !_root.right_wall.hitTest(this._x + 20, this._y, true)) {
if (dir == "right" && !doWallHitTest("right")) {
this._x += speed;
_root._x -= speed;
}
if (dir == "left" && !doWallHitTest("left")) {
this._x += speed;
_root._x -= speed;
}
if (Key.isDown(Key.LEFT)) {
if (speed > -maxmove) {
speed--;
}
this.gotoAndStop("run");
} else if (Key.isDown(Key.RIGHT)) {
if (speed < maxmove) {
speed++;
}
this.gotoAndStop("run");
}
if (speed<1 && speed>-1 && !attacking) {
speed = 0;
this.gotoAndStop("idle");
}
if (Key.isDown(Key.UP) && !jumping && doGroundHitTest()) {
jumping = true;
}
if (jumping) {
this.gotoAndStop("jump");
this._y -= jump;
jump -= .5;
if (jump<0) {
falling = true;
}
if (jump<-15) {
jump = -15;
}
}
if (doGroundHitTest() && falling) {
jump = 12;
jumping = false;
falling = false;
}
}
/* Death test and obsticle tests */
doDeathTest();
doSpringTest();
}