Here is a lot of code that we learned from the wiki that makes our character move and jump.
stop();
boss.onRelease=function() {
gotoAndPlay("question1");
}
stop();
//horizonal walking speed related variables
//This is your starting walking speed
_global.landspeed = 0;
//This is your speed limit
_global.landspeedmax = 30;
//This is used to slowly accelerate your hero up to the speed limit
_global.acceleration = .95;
//jump related variables
//Variables to know whether our hero is Jumping or Falling
_global.isJumping = false;
_global.isFalling = true;
//Velocity as mentioned in the Jump Cycle diagram
_global.velocity = 0;
//Tweak this value along with gravity for interesting results
_global.velocitymax = 25;
//Gravity (acceleration) as mentioned in the Jump Cycle diagram
//more gravity (5.0)
//less gravity (.01)
_global.gravity = 1.5;
girl.onEnterFrame = function(){
if(_root.deadzone.hitTest(this)){
//If the hero hits this movieclip called deadzone, which is below the stage's boundary
//go to frame 2, the "You're Dead" frame
_root.gotoAndStop("dead 2");
_root._x = 0;
} else {
//"I'm not dead yet!"
if (!_root.ground.hitTest(this._x, this._y, true) && !_global.isJumping) {
//hero isn't on the ground and isn't jumping - hero fell off a platform or is in freefall
//changing the number below can make hero fall faster or slower based on conditions above
this._y += 10;
}
if (_root.ground.hitTest(this._x, this._y, true) && _global.isFalling) {
//hero is in the falling section of a jump and finally lands back on terra firma
//reset jump counter back to default
_global.velocity = _global.velocitymax;
_global.isJumping = false;
_global.isFalling = false;
}
if(_global.isJumping == true){
//If hero is jumping, move hero's y coordinate
this._y -= _global.velocity;
_global.velocity -= _global.gravity;
if (_global.velocity < 0) {
//hero is starting the descent down
_global.isFalling = true;
}
if (_global.velocity < -_global.velocitymax) {
//this caps (or sets) the hero's terminal velocity
_global.velocity = -_global.velocitymax;
}
} else {
if(Key.isDown(87)){
girl (0, "jump");
//Hero is jumping, velocity is turned on
_global.isJumping = true;
_global.velocity = _global.velocitymax;
}
}
_global.landspeed *= _global.acceleration;
if(Key.isDown(68)) {
girl (0,"right");
if (_global.landspeed < _global.landspeedmax) {
_global.landspeed++;
}
this._x += _global.landspeed;
deadzone._x += _global.landspeed;
_root._x -= _global.landspeed;
this._xscale = 100;
}
if(Key.isDown(65)) {
girl (0,"left");
if (_global.landspeed > -_global.landspeedmax) {
_global.landspeed--;
}
this._x += _global.landspeed;
deadzone._x += _global.landspeed;
_root._x -= _global.landspeed;
this._xscale = -100;
}
if (Math.abs(_global.landspeed) < 1 ) {
//if my hero's speed has slowed down between
//a range of -1 to 1, make the speed stop
//Math.abs (absolute value) statement above would be the same
//as stating if(_global.landspeed > -1 && _global.landspeed < 1)
_global.landspeed = 0;
}
}
}
No comments:
Post a Comment