stop();
xSpeed = 0;
maxSpeed = 20;
maxSpeed2 = -20;
slowSpeed = 1;
var grav:Number = 0;
var gravity:Number = 10;
var maxJump:Number = -9;
var toughingGround:Boolean = false;
Son.onEnterFrame = function() {
this._x += xSpeed;
//gravity
Son._y += grav;
grav += gravity;
while (ground.hitTest(Son._x, Son._y, true)) {
}
if (ground.hitTest(Son._x, Son._y+5, true)) {
toughingGround = true;
jumping = false;
} else {
toughingGround = false;
}
if (Key.isDown(Key.SPACE) && toughingGround) {
jumping = true;
grav-maxJump;
} else if (Key.isDown(Key.RIGHT)) {
this._xscale = 100;
if (xSpeed>10) {
this.gotoAndStop("SonRun");
} else {
this.gotoAndStop("SonWalk");
}
if (xSpeed<maxSpeed) {
xSpeed += 1;
}
} else if (Key.isDown(Key.LEFT)) {
this._xscale = -100;
if (xSpeed<-10) {
this.gotoAndStop("SonRun");
} else {
this.gotoAndStop("SonWalk");
}
if (xSpeed>maxSpeed2) {
xSpeed -= 1;
}
} else if (xSpeed>0) {
this.gotoAndStop("SonBreak");
xSpeed -= slowSpeed;
} else if (xSpeed<0) {
this.gotoAndStop("SonBreak");
xSpeed += slowSpeed;
}
};