luky
11-07-2007, 03:17 AM
Hi. i'm new at flash, and need some help making a platformer game where you can doublejump. i want it to be set up where you have to tap the up arrow twice to doublejump, but right now if the key is pressed for more than a split second, you jump twice as high. i thought the "jumpkey" boolean would prevent the guy from jumping if the key is down, but in reality it doesn't. the source code for the main character is below; could somebody tell me what's wrong? (note: ignore all the 'attack' stuff)
onClipEvent (load) {
jumping = true;
jumpkey = false;
xaccel = 4;
xspeed = 0;
friction = .7;
yspeed = 0;
jumpcount = 0;
gravity = .9;
}
onClipEvent (enterFrame) {
if (_root.ground.hitTest(this._x, this._y+1, true)) {
yspeed = 0;
jumping = false;
jumpcount = 2;
this._y = 590; }
if (attack==false) {
if (jumpkey==false) {
if ((Key.isDown(Key.UP)) && (jumpcount > 0)) {
jumpkey = true;
yspeed -= 15;
jumping = true;
jumpcount -= 1; }
}
if (jumping==false) {
if (Key.isDown(Key.LEFT)) {
xspeed -= xaccel; }
if (Key.isDown(Key.RIGHT)) {
xspeed += xaccel; }
else {
gotoAndStop("stand"); }
}
if (!Key.isDown ()) {
attackkey = false;
jumpkey = false;
gotoAndStop("stand"); }
}
if ((Key.isDown(Key.SPACE)) && (attackkey=false)) {
attack = true;
attackkey = true; }
if (jumping==false) {
xspeed *= friction; }
if (xspeed<1 and xspeed>-1) {
xspeed = 0; }
else {
attack = false; }
_x += xspeed;
_y += yspeed;
yspeed += gravity;
}
onClipEvent (load) {
jumping = true;
jumpkey = false;
xaccel = 4;
xspeed = 0;
friction = .7;
yspeed = 0;
jumpcount = 0;
gravity = .9;
}
onClipEvent (enterFrame) {
if (_root.ground.hitTest(this._x, this._y+1, true)) {
yspeed = 0;
jumping = false;
jumpcount = 2;
this._y = 590; }
if (attack==false) {
if (jumpkey==false) {
if ((Key.isDown(Key.UP)) && (jumpcount > 0)) {
jumpkey = true;
yspeed -= 15;
jumping = true;
jumpcount -= 1; }
}
if (jumping==false) {
if (Key.isDown(Key.LEFT)) {
xspeed -= xaccel; }
if (Key.isDown(Key.RIGHT)) {
xspeed += xaccel; }
else {
gotoAndStop("stand"); }
}
if (!Key.isDown ()) {
attackkey = false;
jumpkey = false;
gotoAndStop("stand"); }
}
if ((Key.isDown(Key.SPACE)) && (attackkey=false)) {
attack = true;
attackkey = true; }
if (jumping==false) {
xspeed *= friction; }
if (xspeed<1 and xspeed>-1) {
xspeed = 0; }
else {
attack = false; }
_x += xspeed;
_y += yspeed;
yspeed += gravity;
}