From 8f5566a1f07e763ee1f9a2d1a30299c25a1f23d7 Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Sun, 23 May 2004 00:11:58 +0000 Subject: [PATCH] Made butt-jump to behave according to what Marek asked. You can tune a definition... Now, we just need a butt-jump image. SVN-Revision: 1300 --- src/player.cpp | 39 +++++++++++++++++++++++++++++---------- src/player.h | 1 + 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/player.cpp b/src/player.cpp index 5cebfba26..829016488 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -29,9 +29,12 @@ #include "sprite.h" #include "screen.h" -#define AUTOSCROLL_DEAD_INTERVAL 300 +// behavior definitions: +#define TILES_FOR_BUTTJUMP 3 // animation times (in ms): #define SHOOTING_TIME 320 +// others stuff: +#define AUTOSCROLL_DEAD_INTERVAL 300 Surface* tux_life; @@ -310,6 +313,19 @@ Player::under_solid() issolid(base.x + base.width - 1, base.y) ); } +bool +Player::tiles_on_air(int tiles) +{ + for(int t = 0; t != tiles; t++) + { + if(issolid(base.x + base.width / 2, base.y + base.height + (tiles*32)) || + issolid(base.x + 1, base.y + base.height + (tiles*32)) || + issolid(base.x + base.width - 1, base.y + base.height + (tiles*32))) + return false; + } + return true; +} + void Player::handle_horizontal_input() { @@ -415,7 +431,6 @@ Player::handle_vertical_input() --base.y; jumping = true; can_jump = false; - butt_jump = true; // player started jumping, enable butt jump if (size == SMALL) play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER); else @@ -426,15 +441,19 @@ Player::handle_vertical_input() { jumping = false; physic.set_velocity_y(0); - butt_jump = false; // jump was not full, disable butt jump } - /* Do butt jump, in case the player has done the combination - (full jump and hold DOWN) */ - if (input.down == UP && physic.get_velocity_y() == World::current()->get_level()->gravity && butt_jump) - butt_jump = false; // in case DOWN is not hold after the full jump, disable it - - if (input.down == DOWN && butt_jump && on_ground() && size == BIG) + /* In case the player has pressed Down while in a certain range of air, + enable butt jump action */ + if (input.down == DOWN && !butt_jump) + if(tiles_on_air(TILES_FOR_BUTTJUMP)) + butt_jump = true; + + /* When Down is not held anymore, disable butt jump */ + if(butt_jump && input.down == UP) + butt_jump = false; + + if (butt_jump && on_ground() && size == BIG) { if(World::current()->trybreakbrick(base.x, base.y + base.height, false) || World::current()->trybreakbrick( @@ -442,7 +461,7 @@ Player::handle_vertical_input() // make tux jumping a little bit again after breaking the bricks physic.set_velocity_y(2); } -// butt_jump = false; +// butt_jump = false; // comment this, in case you won't to disable the continued use of buttjump } if ( (issolid(base.x + base.width / 2, base.y + base.height + 64) || diff --git a/src/player.h b/src/player.h index 7e39b4a6a..95b1a56b8 100644 --- a/src/player.h +++ b/src/player.h @@ -162,6 +162,7 @@ public: void check_bounds(ViewPort& viewport, bool back_scrolling, bool hor_autoscroll); bool on_ground(); bool under_solid(); + bool tiles_on_air(int tiles); void grow(); private: -- 2.11.0