PDA

View Full Version : game double-jump


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;
}

ginowhitaker
11-07-2007, 01:16 PM
You want the double jump to be only active if you are in jump mode...and only on the ascent and not the descent, correct?

luky
11-07-2007, 11:38 PM
You want the double jump to be only active if you are in jump mode...and only on the ascent and not the descent, correct?

actually, i'd like to have it available on both the ascent and descent. what i'm trying to get rid of is the double jump activating if you hold down the button for longer than a split-second. it needs to be a completely different keypress altogether. i probably should just set up the doublejump as a completely different function from jumping, right?

ginowhitaker
11-08-2007, 02:34 AM
Let me look into it. I believe I've got a script for that...I just have to find it.

Draxus
11-08-2007, 03:46 AM
You could do something like:


var jumps:Number = 0

if (Key.isDown(87))
{
if (jumps == 0)
{
player.ySpeed = -20;
jumps++;
}
if (doubleJump == true)
{
player.ySpeed = -20;
jumps++;
doubleJump = false;
}
}
else
{
if (jumps == 1)
{
doubleJump = true;
}
}

Then set jumps to 0 when you hit the ground.

I wrote it up real quick and can give you the FLA if you're still confused.