[SOLVED] Variable Mario Type Jump


(Tomas Barrio) #1

Hi I am new to Flashpunk I know how to code in C#, but flash is something similar yet different to me, I want to simulate a mario jump, in which by pressing up it will jump a bit and by keeping it pressed it will jump much more, I am using MattTuttle example:

I just need to be pointed in the right direction for this, not sure what to use D:


Mario Style Jumping
(Bora Kasap) #2

use 2 different gravity variable for decreasing Y speed while jumping, if key down use 1st gravity variable, else use 2nd gravity variable. So 2nd gravity variable is the world’s global gravity variable…

1st variable should be less than 2nd variable.


(Zachary Lewis) #3

I’ve always used this little trick to get short hops feeling good: Begin jumping when the user presses the button, and just stop them when they release the button.

Peep these codes with your eyes. It belongs in your game World.

override public function update():void
{
  if (!isJumping && Input.pressed(Key.SPACE))
  {
    // If the player wasn't jumping and SPACE has been pressed, start jumping.
    // Jump by setting the player's y-velocity to a determined jump speed.
    player.vy = -JUMP_SPEED;

    // isJumping will need to be reset once the player has landed from his jump.
    isJumping = true;
  }
  else if(isJumping && Input.released(Key.SPACE))
  {
    // If the player has already jumped and SPACE has been released, stop
    // jumping. To make the jump feel right, set the velocity to a small
    // negative value if he isn't currently moving faster than the value.
    if (player.vy < HOP_SPEED)
    {
      player.vy = HOP_SPEED;
    }
  }
}

2D Top Down Zelda-like Jump Physics question (SOLVED)
Jumping progressively on a platformer[SOLVED]
(der_r) #4

I just implemented that in my own platformer. I used tweens to accomplish this. Here’s my implementation:

(For some reason the code is all wrangled up. I hope it’s still readable.)

// In Player class:

private var isJumping:Boolean = false;

private var jumpAlarm:Alarm = null;

[...]

// in update()

if (Input.pressed("jump"))
 {

	jump();

}
 else if (Input.released("jump"))
 {

	stopJump();

}

[...]

if (isJumping)
 {
	velY = -GC.PlayerJumpStrength;
}

[...]

if (!onGround)
 {
	velY += Physics.gravity;

	velY = FP.clamp(velY, -16, 16);
}


// jump()

public function jump():void
{
	// If pressed "jump" and down and standing on a platform, fall through.
	if (onPlatform && Input.check("down"))
 { 
		onGround = false;

		pPlatform.removeEntity(this);

		onPlatform = false;
		pPlatform = null;

		moveBy(0, 2, "solid", true);
	} else if (onGround)
 {
		onGround = false;
		isJumping = true;
		jumpAlarm = FP.alarm(GC.PlayerJumpDuration, stopJump);

	
		if (onPlatform)
	{
			pPlatform.removeEntity(this);

			onPlatform = false;
			pPlatform = null;

		}
	}
}


// stopJump()

public function stopJump():void

{
	if (jumpAlarm)
 {
		jumpAlarm.cancel();
		jumpAlarm = null;
	}

	isJumping = false;
}

(Tomas Barrio) #5

Sorry for the late reply, AlobarNon the problem I see with you is that altering the gravity just seems wrong, hmm but I tried it and works, yet I am not sure how to code it. zachlewis yeah that’s more like it same with der_r hmm gotta read the code, it does look easier than using the engine I got, I really need to learn how to use states to save my self all this problems… and understand the code at full, I haven’t had time to implement it but that’s more like what I was loooking, thanks al for the elp, If I find any new problem to fix I’m gonna post it !!!

EDIT: after testing it I was able to solve it using zachlewis idea, instead of using velocity I decidd to use acceleration which works smoother ( atleast in my opinion : D!)