From: Matthias Braun Date: Fri, 6 May 2005 22:14:15 +0000 (+0000) Subject: fixed a bug in my last effects removal, improved the algo to determine if a badguy... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=eb87b07de097463cf91cf76be9bbc6b9fc0cad98;p=supertux.git fixed a bug in my last effects removal, improved the algo to determine if a badguy was squished, added safe_timer for the yeti SVN-Revision: 2423 --- diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 844fbfb38..dd8544ea4 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -17,7 +17,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. - #include #include "badguy.h" @@ -30,9 +29,6 @@ static const float Y_OFFSCREEN_DISTANCE = 1200; BadGuy::BadGuy() : sprite(0), dir(LEFT), state(STATE_INIT) { - //Set hitpoints and bullet hitpoints - hitpoints = 1; - bullet_hitpoints = 1; } BadGuy::~BadGuy() @@ -49,7 +45,7 @@ BadGuy::draw(DrawingContext& context) return; if(state == STATE_FALLING) { uint32_t old_effect = context.get_drawing_effect(); - context.set_drawing_effect(old_effect & VERTICAL_FLIP); + context.set_drawing_effect(old_effect | VERTICAL_FLIP); sprite->draw(context, get_pos(), LAYER_OBJECTS); context.set_drawing_effect(old_effect); } else { @@ -150,24 +146,20 @@ BadGuy::collision_solid(GameObject& , const CollisionHit& ) } HitResponse -BadGuy::collision_player(Player& player, const CollisionHit& hit) +BadGuy::collision_player(Player& player, const CollisionHit& ) { if(player.is_invincible()) { kill_fall(); return ABORT_MOVE; } - if(hit.normal.y > .9) { - //TODO: fix inaccuracy (tux sometimes dies even if badguy was hit) - // give badguys some invincible time (prevent them from being hit multiple times) - hitpoints--; - bullet_hitpoints--; - if(collision_squished(player)) - return ABORT_MOVE; - else if (hitpoints <= 0) { - bullet_hitpoints = 0; + // hit from above? + if(player.get_movement().y > 0 && player.get_bbox().p2.y < + (get_bbox().p1.y + get_bbox().p2.y) / 2) { + // if it's not is it possible to squish us, then this will hurt + if(!collision_squished(player)) player.kill(Player::SHRINK); - return FORCE_MOVE; - } + + return FORCE_MOVE; } player.kill(Player::SHRINK); return FORCE_MOVE; @@ -199,15 +191,11 @@ BadGuy::kill_squished(Player& player) void BadGuy::kill_fall() { - bullet_hitpoints--; - if (bullet_hitpoints <= 0) { - hitpoints = 0; - sound_manager->play_sound("fall", this, - Sector::current()->player->get_pos()); - physic.set_velocity_y(0); - physic.enable_gravity(true); - set_state(STATE_FALLING); - } + sound_manager->play_sound("fall", this, + Sector::current()->player->get_pos()); + physic.set_velocity_y(0); + physic.enable_gravity(true); + set_state(STATE_FALLING); } void diff --git a/src/badguy/badguy.h b/src/badguy/badguy.h index ef17b751c..621466eda 100644 --- a/src/badguy/badguy.h +++ b/src/badguy/badguy.h @@ -137,9 +137,6 @@ protected: Vector start_position; Direction dir; - - int hitpoints; - int bullet_hitpoints; private: void try_activate(); diff --git a/src/badguy/nolok_01.cpp b/src/badguy/nolok_01.cpp index 61c8b12d7..045a507e0 100644 --- a/src/badguy/nolok_01.cpp +++ b/src/badguy/nolok_01.cpp @@ -63,8 +63,8 @@ Nolok_01::write(lisp::Writer& writer) void Nolok_01::activate() { - hitpoints = INITIAL_HITPOINTS; - bullet_hitpoints = INITIAL_BULLET_HP; + //hitpoints = INITIAL_HITPOINTS; + //bullet_hitpoints = INITIAL_BULLET_HP; physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); action = WALKING; @@ -111,6 +111,7 @@ Nolok_01::collision_squished(Player& player) { bool result = false; player.bounce(*this); +#if 0 if (hitpoints <= 0) { bullet_hitpoints = 0; sprite->set_action("dead"); @@ -118,6 +119,7 @@ Nolok_01::collision_squished(Player& player) Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2")); result = true; } +#endif return result; } @@ -139,6 +141,7 @@ Nolok_01::collision_solid(GameObject& , const CollisionHit& hit) void Nolok_01::kill_fall() { +#if 0 bullet_hitpoints--; if (bullet_hitpoints <= 0) { hitpoints = 0; @@ -149,6 +152,7 @@ Nolok_01::kill_fall() set_state(STATE_FALLING); Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2")); } +#endif } IMPLEMENT_FACTORY(Nolok_01, "nolok_01") diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index c1da901e2..2bbf5d71b 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -31,8 +31,9 @@ static const float JUMP_VEL2 = 700; static const float RUN_SPEED = 350; static const float JUMP_TIME = 1.6; static const float ANGRY_JUMP_WAIT = .5; +/// the time we are safe when tux just hit us +static const float SAFE_TIME = .5; static const int INITIAL_HITPOINTS = 3; -static const int INITIAL_BULLET_HP = 10; Yeti::Yeti(const lisp::Lisp& reader) { @@ -42,15 +43,23 @@ Yeti::Yeti(const lisp::Lisp& reader) sprite = sprite_manager->create("yeti"); state = INIT; side = LEFT; - hitpoints = INITIAL_HITPOINTS; - bullet_hitpoints = INITIAL_BULLET_HP; sound_manager->preload_sound("yeti_gna"); - sound_manager->preload_sound("yeti_roar"); + sound_manager->preload_sound("yeti_roar"); + hit_points = INITIAL_HITPOINTS; } Yeti::~Yeti() { - Mix_FreeChunk(sound_gna); +} + +void +Yeti::draw(DrawingContext& context) +{ + // we blink when we are safe + if(safe_timer.started() && size_t(global_time*40)%2) + return; + + BadGuy::draw(context); } void @@ -117,41 +126,29 @@ Yeti::summon_snowball() Sector::current()->add_object(new BouncingSnowball(get_pos().x+(side == LEFT ? 64 : -64), get_pos().y, (side == LEFT ? RIGHT : LEFT))); } -HitResponse -Yeti::collision_player(Player& player, const CollisionHit& hit) -{ - if(player.is_invincible()) { - kill_fall(); - return ABORT_MOVE; - } - if(hit.normal.y > .9) { - hitpoints--; - bullet_hitpoints--; - sound_manager->play_sound("yeti_roar"); - if(collision_squished(player)) - return ABORT_MOVE; - else if (hitpoints <= 0) { - bullet_hitpoints = 0; - player.kill(Player::SHRINK); - return FORCE_MOVE; - } - } - player.kill(Player::SHRINK); - return FORCE_MOVE; -} - bool Yeti::collision_squished(Player& player) { - bool result = false; + if(safe_timer.started()) + return true; + player.bounce(*this); - if (hitpoints <= 0) { - bullet_hitpoints = 0; - //sprite->set_action("dead"); + sound_manager->play_sound("yeti_roar"); + hit_points--; + if(hit_points <= 0) { + sprite->set_action("dead"); kill_squished(player); - result = true; + } else { + safe_timer.start(SAFE_TIME); } - return result; + + return true; +} + +void +Yeti::kill_fall() +{ + // shooting bullets or being invincible won't work :) } void @@ -223,18 +220,4 @@ Yeti::collision_solid(GameObject& , const CollisionHit& hit) return CONTINUE; } -void -Yeti::kill_fall() -{ - sound_manager->play_sound("yeti_roar"); - bullet_hitpoints--; - if (bullet_hitpoints <= 0) { - sound_manager->play_sound("fall", this, - Sector::current()->player->get_pos()); - physic.set_velocity_y(0); - physic.enable_gravity(true); - set_state(STATE_FALLING); - } -} - IMPLEMENT_FACTORY(Yeti, "yeti") diff --git a/src/badguy/yeti.h b/src/badguy/yeti.h index edad74789..4716ddcab 100644 --- a/src/badguy/yeti.h +++ b/src/badguy/yeti.h @@ -17,7 +17,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. - #ifndef __YETI_H__ #define __YETI_H__ @@ -29,10 +28,10 @@ public: Yeti(const lisp::Lisp& lisp); ~Yeti(); + void draw(DrawingContext& context); void write(lisp::Writer& writer); void active_action(float elapsed_time); - HitResponse collision_solid(GameObject& other, const CollisionHit& hit); - HitResponse collision_player(Player& player, const CollisionHit& hit); + HitResponse collision_solid(GameObject& object, const CollisionHit& hit); bool collision_squished(Player& player); void kill_fall(); @@ -53,9 +52,9 @@ private: Direction side; YetiState state; Timer timer; + Timer safe_timer; int jumpcount; - Mix_Chunk* sound_gna; - Mix_Chunk* sound_roar; + int hit_points; }; #endif diff --git a/src/object/player.cpp b/src/object/player.cpp index 71a6241f5..f2bc78a7e 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -896,6 +896,6 @@ Player::bounce(BadGuy& ) if(controller->hold(Controller::JUMP)) physic.set_velocity_y(520); else - physic.set_velocity_y(200); + physic.set_velocity_y(300); }