028 : No double jumps

You:

Yay! We can jump.

You:

well... sort of...

You:

If I hold the jump button down, I can fly off the top of the screen.

Balthazar:

Yes, apparently you can jump while you're in mid-air, which is not quite what we want. How do you think we should fix that?

You:

You should only be allowed to jump if you're standing on a platform.

Balthazar:

So we should add a variable to the player that keeps track of whether-or-not the player is currently on a platform.

script.js: Add a platform variable to the player.
function init_player() { ... _player.origin_x = _player.width / 2; _player.origin_y = _player.height; _player.platform = false; _player.velocity_x = 0; _player.velocity_x_delta = 0.8; ... }
Balthazar:

And we need to check this variable whenever the player tries to jump.

script.js: Only allow jumps if the player is on a platform.
function check_input() { ... // Up arrow, 'w' and spacebar to jump. if (_game.keymap[38] || _game.keymap[87] || _game.keymap[32]) { // Only allow jumps if the player is on a platform. if (_player.platform) { _player.platform = false; _player.velocity_y = _player.velocity_y_jump; } } ... }
You:

It doesn't seem to work yet.

Balthazar:

That's because we're not quite done. We now need to set the platform variable when the player is on a platform.

GOTO 033 if you already have the Collision I - Basic badge.

GOTO 032