From 4bbf74b32ab00e94162d90746cdb9ba9fd8a2aaa Mon Sep 17 00:00:00 2001 From: LMH Date: Sat, 14 Jun 2014 12:08:35 -1000 Subject: [PATCH] Powerup: Iceflower improvements Generalized code for changing frozen badguy sprite to iced, and added a default behavior for freezable badguys without iced graphics. Frozen badguys no longer unfreeze on touch. Added ice vulnerability to forest badguys. Note: there are some mild bugs as a result of this change, which should be fixed in subsequent improvements to make Iceflower a more viable powerup. --- data/images/creatures/jumpy/jumpy.sprite | 6 ++-- data/images/creatures/snowjumpy/snowjumpy.sprite | 6 ++-- src/badguy/badguy.cpp | 23 +++++++++++++++- src/badguy/fish.cpp | 1 + src/badguy/goldbomb.cpp | 1 - src/badguy/haywire.cpp | 7 ----- src/badguy/haywire.hpp | 1 - src/badguy/igel.cpp | 11 ++++++-- src/badguy/igel.hpp | 2 ++ src/badguy/jumpy.cpp | 1 - src/badguy/mole.cpp | 15 ++++++++++ src/badguy/mole.hpp | 2 ++ src/badguy/mrbomb.cpp | 7 ----- src/badguy/mrbomb.hpp | 1 - src/badguy/mrtree.cpp | 6 ++++ src/badguy/mrtree.hpp | 2 ++ src/badguy/owl.cpp | 34 +++++++++++++++++++++++ src/badguy/owl.hpp | 4 +++ src/badguy/poisonivy.cpp | 6 ++++ src/badguy/poisonivy.hpp | 2 ++ src/badguy/skullyhop.cpp | 26 ++++++++++++++++++ src/badguy/skullyhop.hpp | 3 ++ src/badguy/snail.cpp | 27 ++++++++++++++++++ src/badguy/snail.hpp | 2 ++ src/badguy/spidermite.cpp | 26 ++++++++++++++++++ src/badguy/spidermite.hpp | 4 +++ src/badguy/spiky.cpp | 7 ----- src/badguy/spiky.hpp | 1 - src/badguy/sspiky.cpp | 1 - src/badguy/stumpy.cpp | 6 ++++ src/badguy/stumpy.hpp | 2 ++ src/badguy/toad.cpp | 33 ++++++++++++++++++---- src/badguy/toad.hpp | 3 ++ src/badguy/walkingleaf.cpp | 5 ++++ src/badguy/walkingleaf.hpp | 2 ++ src/badguy/zeekling.cpp | 35 ++++++++++++++++++++++++ src/badguy/zeekling.hpp | 4 +++ 37 files changed, 284 insertions(+), 41 deletions(-) diff --git a/data/images/creatures/jumpy/jumpy.sprite b/data/images/creatures/jumpy/jumpy.sprite index 0f0bd89c2..85d84603c 100644 --- a/data/images/creatures/jumpy/jumpy.sprite +++ b/data/images/creatures/jumpy/jumpy.sprite @@ -31,13 +31,13 @@ (mirror-action "left-middle")) (action - (name "left-iced") + (name "iced-left") (hitbox 7 8 31.8 31.8) (images "iced-left-up.png")) (action - (name "right-iced") + (name "iced-right") (hitbox 7 8 31.8 31.8) - (mirror-action "left-iced")) + (mirror-action "iced-left")) ) diff --git a/data/images/creatures/snowjumpy/snowjumpy.sprite b/data/images/creatures/snowjumpy/snowjumpy.sprite index 0f0bd89c2..85d84603c 100644 --- a/data/images/creatures/snowjumpy/snowjumpy.sprite +++ b/data/images/creatures/snowjumpy/snowjumpy.sprite @@ -31,13 +31,13 @@ (mirror-action "left-middle")) (action - (name "left-iced") + (name "iced-left") (hitbox 7 8 31.8 31.8) (images "iced-left-up.png")) (action - (name "right-iced") + (name "iced-right") (hitbox 7 8 31.8 31.8) - (mirror-action "left-iced")) + (mirror-action "iced-left")) ) diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 68187b67e..99a5618d1 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -219,6 +219,8 @@ void BadGuy::active_update(float elapsed_time) { movement = physic.get_movement(elapsed_time); + if(frozen) + sprite->stop_animation(); } void @@ -302,8 +304,11 @@ BadGuy::collision_player(Player& player, const CollisionHit& ) return ABORT_MOVE; } + //TODO: unfreeze timer if(frozen) - unfreeze(); + //unfreeze(); + return FORCE_MOVE; + player.kill(false); return FORCE_MOVE; } @@ -548,6 +553,15 @@ BadGuy::freeze() { set_group(COLGROUP_MOVING_STATIC); frozen = true; + + if(sprite->has_action("iced-left")) + sprite->set_action(dir == LEFT ? "iced-left" : "iced-right", 1); + // when no iced action exists, default to shading badguy blue + else + { + sprite->set_color(Color(0.60, 0.72, 0.88f)); + sprite->stop_animation(); + } } void @@ -555,6 +569,13 @@ BadGuy::unfreeze() { set_group(colgroup_active); frozen = false; + + // restore original color if needed + if(!sprite->has_action("iced-left")) + { + sprite->set_color(Color(1.00, 1.00, 1.00f)); + sprite->set_animation_loops(); + } } bool diff --git a/src/badguy/fish.cpp b/src/badguy/fish.cpp index c8bf8093b..f6d3f7c2e 100644 --- a/src/badguy/fish.cpp +++ b/src/badguy/fish.cpp @@ -138,6 +138,7 @@ Fish::freeze() { BadGuy::freeze(); sprite->set_action(physic.get_velocity_y() < 0 ? "iced" : "iced-down"); + sprite->set_color(Color(1.0f, 1.0f, 1.0f)); waiting.stop(); } diff --git a/src/badguy/goldbomb.cpp b/src/badguy/goldbomb.cpp index 59911a7be..60cc90f79 100644 --- a/src/badguy/goldbomb.cpp +++ b/src/badguy/goldbomb.cpp @@ -221,7 +221,6 @@ GoldBomb::freeze() { if(tstate == STATE_NORMAL){ WalkingBadguy::freeze(); - sprite->set_action(dir == LEFT ? "iced-left" : "iced-right"); } } diff --git a/src/badguy/haywire.cpp b/src/badguy/haywire.cpp index 97d1eade5..b968de57d 100644 --- a/src/badguy/haywire.cpp +++ b/src/badguy/haywire.cpp @@ -178,13 +178,6 @@ Haywire::kill_fall() run_dead_script(); } -void -Haywire::freeze() -{ - WalkingBadguy::freeze(); - sprite->set_action(dir == LEFT ? "iced-left" : "iced-right"); -} - bool Haywire::is_freezable() const { diff --git a/src/badguy/haywire.hpp b/src/badguy/haywire.hpp index ae944e89f..83d04012c 100644 --- a/src/badguy/haywire.hpp +++ b/src/badguy/haywire.hpp @@ -33,7 +33,6 @@ public: void active_update(float elapsed_time); - void freeze(); bool is_freezable() const; protected: diff --git a/src/badguy/igel.cpp b/src/badguy/igel.cpp index 857023d83..c1769a40a 100644 --- a/src/badguy/igel.cpp +++ b/src/badguy/igel.cpp @@ -99,8 +99,9 @@ Igel::active_update(float elapsed_time) HitResponse Igel::collision_bullet(Bullet& bullet, const CollisionHit& hit) { - // default reaction if hit on front side - if (((dir == LEFT) && hit.left) || ((dir == RIGHT) && hit.right)) { + // default reaction if hit on front side or for freeze and unfreeze + if (((dir == LEFT) && hit.left) || ((dir == RIGHT) && hit.right) || + (bullet.get_type() == ICE_BONUS) || ((bullet.get_type() == FIRE_BONUS) && (frozen))) { return BadGuy::collision_bullet(bullet, hit); } @@ -110,6 +111,12 @@ Igel::collision_bullet(Bullet& bullet, const CollisionHit& hit) } bool +Igel::is_freezable() const +{ + return true; +} + +bool Igel::collision_squished(GameObject& ) { // this will hurt diff --git a/src/badguy/igel.hpp b/src/badguy/igel.hpp index c63d76675..dbade8a60 100644 --- a/src/badguy/igel.hpp +++ b/src/badguy/igel.hpp @@ -32,6 +32,8 @@ public: void active_update(float elapsed_time); + bool is_freezable() const; + protected: bool collision_squished(GameObject& object); void be_normal(); /**< switch to state STATE_NORMAL */ diff --git a/src/badguy/jumpy.cpp b/src/badguy/jumpy.cpp index 1117d64c8..272e6aea1 100644 --- a/src/badguy/jumpy.cpp +++ b/src/badguy/jumpy.cpp @@ -99,7 +99,6 @@ Jumpy::freeze() { BadGuy::freeze(); physic.set_velocity_y(std::max(0.0f, physic.get_velocity_y())); - sprite->set_action(dir == LEFT ? "left-iced" : "right-iced"); } bool diff --git a/src/badguy/mole.cpp b/src/badguy/mole.cpp index c9a40cd35..46daf14d8 100644 --- a/src/badguy/mole.cpp +++ b/src/badguy/mole.cpp @@ -76,6 +76,9 @@ Mole::collision_badguy(BadGuy& , const CollisionHit& ) bool Mole::collision_squished(GameObject& ) { + if (frozen) + return true; + set_state(DEAD); sound_manager->play("sounds/squish.wav", get_pos()); run_dead_script(); @@ -101,6 +104,9 @@ Mole::active_update(float elapsed_time) { BadGuy::active_update(elapsed_time); + if (frozen) + return; + switch (state) { case PRE_THROWING: if (timer.check()) { @@ -132,9 +138,18 @@ Mole::active_update(float elapsed_time) } +bool +Mole::is_freezable() const +{ + return true; +} + void Mole::set_state(MoleState new_state) { + if (frozen) + return; + switch (new_state) { case PRE_THROWING: sprite->set_action("idle"); diff --git a/src/badguy/mole.hpp b/src/badguy/mole.hpp index a6e62c4e7..cca93cdda 100644 --- a/src/badguy/mole.hpp +++ b/src/badguy/mole.hpp @@ -32,6 +32,8 @@ public: void activate(); void active_update(float); + bool is_freezable() const; + private: enum MoleState { PRE_THROWING, diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 8b411892c..438d328b2 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -131,13 +131,6 @@ MrBomb::ungrab(MovingObject& , Direction dir) grabbed = false; } -void -MrBomb::freeze() -{ - WalkingBadguy::freeze(); - sprite->set_action(dir == LEFT ? "iced-left" : "iced-right"); -} - bool MrBomb::is_freezable() const { diff --git a/src/badguy/mrbomb.hpp b/src/badguy/mrbomb.hpp index 4ad45f337..8c06a36d1 100644 --- a/src/badguy/mrbomb.hpp +++ b/src/badguy/mrbomb.hpp @@ -36,7 +36,6 @@ public: void ungrab(MovingObject& object, Direction dir); bool is_portable() const; - void freeze(); bool is_freezable() const; protected: diff --git a/src/badguy/mrtree.cpp b/src/badguy/mrtree.cpp index a5023acad..cc8feb883 100644 --- a/src/badguy/mrtree.cpp +++ b/src/badguy/mrtree.cpp @@ -42,6 +42,12 @@ MrTree::MrTree(const Reader& reader) } bool +MrTree::is_freezable() const +{ + return true; +} + +bool MrTree::collision_squished(GameObject& object) { // replace with Stumpy diff --git a/src/badguy/mrtree.hpp b/src/badguy/mrtree.hpp index 8b78ab9f2..e57a9315f 100644 --- a/src/badguy/mrtree.hpp +++ b/src/badguy/mrtree.hpp @@ -24,6 +24,8 @@ class MrTree : public WalkingBadguy public: MrTree(const Reader& reader); + bool is_freezable() const; + protected: bool collision_squished(GameObject& object); diff --git a/src/badguy/owl.cpp b/src/badguy/owl.cpp index f379153f9..f31fe9ca7 100644 --- a/src/badguy/owl.cpp +++ b/src/badguy/owl.cpp @@ -99,6 +99,9 @@ Owl::active_update (float elapsed_time) { BadGuy::active_update (elapsed_time); + if(frozen) + return; + if (carried_object != NULL) { if (!is_above_player ()) { Vector obj_pos = get_anchor_pos (bbox, ANCHOR_BOTTOM); @@ -156,8 +159,39 @@ Owl::kill_fall() } void +Owl::freeze() +{ + if (carried_object != NULL) { + carried_object->ungrab (*this, dir); + carried_object = NULL; + } + physic.enable_gravity(true); + BadGuy::freeze(); +} + +void +Owl::unfreeze() +{ + BadGuy::unfreeze(); + physic.set_velocity_x(dir == LEFT ? -FLYING_SPEED : FLYING_SPEED); + physic.enable_gravity(false); + sprite->set_action(dir == LEFT ? "left" : "right"); +} + +bool +Owl::is_freezable() const +{ + return true; +} + +void Owl::collision_solid(const CollisionHit& hit) { + if(frozen) + { + BadGuy::collision_solid(hit); + return; + } if(hit.top || hit.bottom) { physic.set_velocity_y(0); } else if(hit.left || hit.right) { diff --git a/src/badguy/owl.hpp b/src/badguy/owl.hpp index 6614fe119..83b38b97a 100644 --- a/src/badguy/owl.hpp +++ b/src/badguy/owl.hpp @@ -31,6 +31,10 @@ public: void collision_solid(const CollisionHit& hit); void kill_fall(); + void freeze(); + void unfreeze(); + bool is_freezable() const; + protected: bool is_above_player (void); void active_update (float elapsed_time); diff --git a/src/badguy/poisonivy.cpp b/src/badguy/poisonivy.cpp index 334746557..c8973af19 100644 --- a/src/badguy/poisonivy.cpp +++ b/src/badguy/poisonivy.cpp @@ -35,6 +35,12 @@ PoisonIvy::PoisonIvy(const Vector& pos, Direction d) } bool +PoisonIvy::is_freezable() const +{ + return true; +} + +bool PoisonIvy::collision_squished(GameObject& object) { sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); diff --git a/src/badguy/poisonivy.hpp b/src/badguy/poisonivy.hpp index 3e93c4f58..a1bafa39b 100644 --- a/src/badguy/poisonivy.hpp +++ b/src/badguy/poisonivy.hpp @@ -25,6 +25,8 @@ public: PoisonIvy(const Reader& reader); PoisonIvy(const Vector& pos, Direction d); + bool is_freezable() const; + protected: bool collision_squished(GameObject& object); diff --git a/src/badguy/skullyhop.cpp b/src/badguy/skullyhop.cpp index f7a1c6738..2d2fc8943 100644 --- a/src/badguy/skullyhop.cpp +++ b/src/badguy/skullyhop.cpp @@ -80,6 +80,9 @@ const float VERTICAL_SPEED = -450; /**< y-speed when jumping */ bool SkullyHop::collision_squished(GameObject& object) { + if (frozen) + return BadGuy::collision_squished(object); + sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); kill_squished(object); return true; @@ -88,6 +91,12 @@ SkullyHop::collision_squished(GameObject& object) void SkullyHop::collision_solid(const CollisionHit& hit) { + if (frozen) + { + BadGuy::collision_solid(hit); + return; + } + // just default behaviour (i.e. stop at floor/walls) when squished if (BadGuy::get_state() == STATE_SQUISHED) { BadGuy::collision_solid(hit); @@ -128,6 +137,10 @@ SkullyHop::active_update(float elapsed_time) { BadGuy::active_update(elapsed_time); + // no change if frozen + if (frozen) + return; + // charge when fully recovered if ((state == STANDING) && (recover_timer.check())) { set_state(CHARGING); @@ -141,4 +154,17 @@ SkullyHop::active_update(float elapsed_time) } } +void +SkullyHop::unfreeze() +{ + BadGuy::unfreeze(); + initialize(); +} + +bool +SkullyHop::is_freezable() const +{ + return true; +} + /* EOF */ diff --git a/src/badguy/skullyhop.hpp b/src/badguy/skullyhop.hpp index 5698fe625..6b12cb675 100644 --- a/src/badguy/skullyhop.hpp +++ b/src/badguy/skullyhop.hpp @@ -34,6 +34,9 @@ public: bool collision_squished(GameObject& object); void active_update(float elapsed_time); + void unfreeze(); + bool is_freezable() const; + private: enum SkullyHopState { STANDING, diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index faf86602f..c3b3e8c4d 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -102,6 +102,12 @@ Snail::can_break(){ void Snail::active_update(float elapsed_time) { + if(frozen) + { + BadGuy::active_update(elapsed_time); + return; + } + switch (state) { case STATE_NORMAL: @@ -132,9 +138,21 @@ Snail::active_update(float elapsed_time) BadGuy::active_update(elapsed_time); } +bool +Snail::is_freezable() const +{ + return true; +} + void Snail::collision_solid(const CollisionHit& hit) { + if(frozen) + { + WalkingBadguy::collision_solid(hit); + return; + } + switch (state) { case STATE_NORMAL: WalkingBadguy::collision_solid(hit); @@ -166,6 +184,9 @@ Snail::collision_solid(const CollisionHit& hit) HitResponse Snail::collision_badguy(BadGuy& badguy, const CollisionHit& hit) { + if(frozen) + return WalkingBadguy::collision_badguy(badguy, hit); + switch(state) { case STATE_NORMAL: return WalkingBadguy::collision_badguy(badguy, hit); @@ -185,6 +206,9 @@ Snail::collision_badguy(BadGuy& badguy, const CollisionHit& hit) HitResponse Snail::collision_player(Player& player, const CollisionHit& hit) { + if(frozen) + return WalkingBadguy::collision_player(player, hit); + // handle kicks from left or right side if(state == STATE_FLAT && (hit.left || hit.right)) { if(hit.left) { @@ -203,6 +227,9 @@ Snail::collision_player(Player& player, const CollisionHit& hit) bool Snail::collision_squished(GameObject& object) { + if(frozen) + return WalkingBadguy::collision_squished(object); + Player* player = dynamic_cast(&object); if(player && (player->does_buttjump || player->is_invincible())) { kill_fall(); diff --git a/src/badguy/snail.hpp b/src/badguy/snail.hpp index 40181b9d5..cd62a1ec8 100644 --- a/src/badguy/snail.hpp +++ b/src/badguy/snail.hpp @@ -36,6 +36,8 @@ public: void active_update(float elapsed_time); + bool is_freezable() const; + protected: bool collision_squished(GameObject& object); void be_normal(); /**< switch to state STATE_NORMAL */ diff --git a/src/badguy/spidermite.cpp b/src/badguy/spidermite.cpp index 634088a4f..f8b2fc69f 100644 --- a/src/badguy/spidermite.cpp +++ b/src/badguy/spidermite.cpp @@ -67,6 +67,11 @@ SpiderMite::collision_solid(const CollisionHit& hit) void SpiderMite::active_update(float elapsed_time) { + if(frozen) + { + BadGuy::active_update(elapsed_time); + return; + } if(timer.check()) { if(mode == FLY_UP) { mode = FLY_DOWN; @@ -86,4 +91,25 @@ SpiderMite::active_update(float elapsed_time) } } +void +SpiderMite::freeze() +{ + physic.enable_gravity(true); + BadGuy::freeze(); +} + +void +SpiderMite::unfreeze() +{ + BadGuy::unfreeze(); + physic.enable_gravity(false); + initialize(); +} + +bool +SpiderMite::is_freezable() const +{ + return true; +} + /* EOF */ diff --git a/src/badguy/spidermite.hpp b/src/badguy/spidermite.hpp index c2e7675a8..4b90a4613 100644 --- a/src/badguy/spidermite.hpp +++ b/src/badguy/spidermite.hpp @@ -29,6 +29,10 @@ public: void active_update(float elapsed_time); void collision_solid(const CollisionHit& hit); + void freeze(); + void unfreeze(); + bool is_freezable() const; + protected: enum SpiderMiteMode { FLY_UP, diff --git a/src/badguy/spiky.cpp b/src/badguy/spiky.cpp index 3e4297fbf..cc2cd3c23 100644 --- a/src/badguy/spiky.cpp +++ b/src/badguy/spiky.cpp @@ -26,13 +26,6 @@ Spiky::Spiky(const Reader& reader) max_drop_height = 600; } -void -Spiky::freeze() -{ - WalkingBadguy::freeze(); - sprite->set_action(dir == LEFT ? "iced-left" : "iced-right"); -} - bool Spiky::is_freezable() const { diff --git a/src/badguy/spiky.hpp b/src/badguy/spiky.hpp index 122d72098..e1cd6f530 100644 --- a/src/badguy/spiky.hpp +++ b/src/badguy/spiky.hpp @@ -24,7 +24,6 @@ class Spiky : public WalkingBadguy public: Spiky(const Reader& reader); - void freeze(); bool is_freezable() const; private: diff --git a/src/badguy/sspiky.cpp b/src/badguy/sspiky.cpp index cea68ddeb..013d8347f 100644 --- a/src/badguy/sspiky.cpp +++ b/src/badguy/sspiky.cpp @@ -99,7 +99,6 @@ void SSpiky::freeze() { WalkingBadguy::freeze(); - sprite->set_action(dir == LEFT ? "iced-left" : "iced-right"); state = SSPIKY_WALKING; // if we get hit while sleeping, wake up :) } diff --git a/src/badguy/stumpy.cpp b/src/badguy/stumpy.cpp index 8c47c6636..f06f20efe 100644 --- a/src/badguy/stumpy.cpp +++ b/src/badguy/stumpy.cpp @@ -159,4 +159,10 @@ Stumpy::collision_badguy(BadGuy& badguy, const CollisionHit& hit) return CONTINUE; } +bool +Stumpy::is_freezable() const +{ + return true; +} + /* EOF */ diff --git a/src/badguy/stumpy.hpp b/src/badguy/stumpy.hpp index d85036d38..37b0dc3c4 100644 --- a/src/badguy/stumpy.hpp +++ b/src/badguy/stumpy.hpp @@ -30,6 +30,8 @@ public: void collision_solid(const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); + bool is_freezable() const; + protected: enum MyState { STATE_INVINCIBLE, STATE_NORMAL diff --git a/src/badguy/toad.cpp b/src/badguy/toad.cpp index 9fc27c6fc..f70f87a81 100644 --- a/src/badguy/toad.cpp +++ b/src/badguy/toad.cpp @@ -55,10 +55,12 @@ Toad::initialize() void Toad::set_state(ToadState newState) { + if (newState == IDLE) { physic.set_velocity_x(0); physic.set_velocity_y(0); - sprite->set_action(dir == LEFT ? "idle-left" : "idle-right"); + if (!frozen) + sprite->set_action(dir == LEFT ? "idle-left" : "idle-right"); recover_timer.start(TOAD_RECOVER_TIME); } else @@ -90,6 +92,13 @@ Toad::collision_squished(GameObject& object) void Toad::collision_solid(const CollisionHit& hit) { + // default behavior when frozen + if (frozen) + { + BadGuy::collision_solid(hit); + return; + } + // just default behaviour (i.e. stop at floor/walls) when squished if (BadGuy::get_state() == STATE_SQUISHED) { BadGuy::collision_solid(hit); @@ -141,18 +150,32 @@ Toad::active_update(float elapsed_time) { BadGuy::active_update(elapsed_time); - // change sprite when we are falling - if ((state == JUMPING) && (physic.get_velocity_y() > 0)) { + + // change sprite when we are falling and not frozen + if ((state == JUMPING) && (physic.get_velocity_y() > 0) && !frozen) { set_state(FALLING); return; } - // jump when fully recovered - if ((state == IDLE) && (recover_timer.check())) { + // jump when fully recovered and if not frozen + if ((state == IDLE) && (recover_timer.check() && !frozen)) { set_state(JUMPING); return; } } +void +Toad::unfreeze() +{ + BadGuy::unfreeze(); + initialize(); +} + +bool +Toad::is_freezable() const +{ + return true; +} + /* EOF */ diff --git a/src/badguy/toad.hpp b/src/badguy/toad.hpp index 39a53f359..1b483b1ed 100644 --- a/src/badguy/toad.hpp +++ b/src/badguy/toad.hpp @@ -34,6 +34,9 @@ public: bool collision_squished(GameObject& object); void active_update(float elapsed_time); + void unfreeze(); + bool is_freezable() const; + protected: enum ToadState { IDLE, diff --git a/src/badguy/walkingleaf.cpp b/src/badguy/walkingleaf.cpp index 25931370b..08c93af80 100644 --- a/src/badguy/walkingleaf.cpp +++ b/src/badguy/walkingleaf.cpp @@ -41,4 +41,9 @@ WalkingLeaf::collision_squished(GameObject& object) return true; } +bool +WalkingLeaf::is_freezable() const +{ + return true; +} /* EOF */ diff --git a/src/badguy/walkingleaf.hpp b/src/badguy/walkingleaf.hpp index 88d1d7120..ef7e0c26a 100644 --- a/src/badguy/walkingleaf.hpp +++ b/src/badguy/walkingleaf.hpp @@ -28,6 +28,8 @@ public: WalkingLeaf(const Reader& reader); WalkingLeaf(const Vector& pos, Direction d); + bool is_freezable() const; + protected: bool collision_squished(GameObject& object); diff --git a/src/badguy/zeekling.cpp b/src/badguy/zeekling.cpp index 8fff3eac3..0ca8a561c 100644 --- a/src/badguy/zeekling.cpp +++ b/src/badguy/zeekling.cpp @@ -69,6 +69,11 @@ Zeekling::collision_squished(GameObject& object) void Zeekling::onBumpHorizontal() { + if (frozen) + { + physic.set_velocity_x(0); + return; + } if (state == FLYING) { dir = (dir == LEFT ? RIGHT : LEFT); sprite->set_action(dir == LEFT ? "left" : "right"); @@ -92,6 +97,12 @@ Zeekling::onBumpHorizontal() { void Zeekling::onBumpVertical() { + if (frozen) + { + physic.set_velocity_y(0); + physic.set_velocity_x(0); + return; + } if (state == FLYING) { physic.set_velocity_y(0); } else @@ -127,6 +138,8 @@ Zeekling::collision_solid(const CollisionHit& hit) */ bool Zeekling::should_we_dive() { + if (frozen) + return false; const MovingObject* player = this->get_nearest_player(); if (player && last_player && (player == last_player)) { @@ -200,4 +213,26 @@ Zeekling::active_update(float elapsed_time) { } } +void +Zeekling::freeze() +{ + BadGuy::freeze(); + physic.enable_gravity(true); +} + +void +Zeekling::unfreeze() +{ + BadGuy::unfreeze(); + physic.enable_gravity(false); + state = FLYING; + initialize(); +} + +bool +Zeekling::is_freezable() const +{ + return true; +} + /* EOF */ diff --git a/src/badguy/zeekling.hpp b/src/badguy/zeekling.hpp index 0f68f8a86..bd8548b49 100644 --- a/src/badguy/zeekling.hpp +++ b/src/badguy/zeekling.hpp @@ -30,6 +30,10 @@ public: void collision_solid(const CollisionHit& hit); void active_update(float elapsed_time); + void freeze(); + void unfreeze(); + bool is_freezable() const; + private: bool collision_squished(GameObject& object); bool should_we_dive(); -- 2.11.0