From 88e85d929e3352302da5faeb812b3f7673b70180 Mon Sep 17 00:00:00 2001 From: florianf Date: Fri, 26 Feb 2010 19:48:40 +0000 Subject: [PATCH] IceCrusher: Implemented a cooldown timer. The timing is probably awful, but the code is there and fine-tuning the timing should be easy now. git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6405 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/object/icecrusher.cpp | 17 ++++++++++++++++- src/object/icecrusher.hpp | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/object/icecrusher.cpp b/src/object/icecrusher.cpp index 38e25070c..d97b4b0f9 100644 --- a/src/object/icecrusher.cpp +++ b/src/object/icecrusher.cpp @@ -28,13 +28,15 @@ namespace { const float MAX_DROP_SPEED = 10.0; const float RECOVER_SPEED = -3.125; const float ACTIVATION_DISTANCE = 4.0; +const float PAUSE_TIME = 0.5; } IceCrusher::IceCrusher(const Reader& reader) : MovingSprite(reader, "images/creatures/icecrusher/icecrusher.sprite", LAYER_OBJECTS, COLGROUP_STATIC), state(IDLE), start_position(), - physic() + physic(), + cooldown_timer(0.0) { start_position = get_bbox().p1; set_state(state, true); @@ -110,6 +112,7 @@ IceCrusher::collision_solid(const CollisionHit& hit) break; case CRUSHING: if (hit.bottom) { + cooldown_timer = PAUSE_TIME; set_state(RECOVERING); } break; @@ -124,6 +127,17 @@ IceCrusher::collision_solid(const CollisionHit& hit) void IceCrusher::update(float elapsed_time) { + if (cooldown_timer >= elapsed_time) + { + cooldown_timer -= elapsed_time; + return; + } + else if (cooldown_timer != 0.0) + { + elapsed_time -= cooldown_timer; + cooldown_timer = 0.0; + } + switch(state) { case IDLE: movement = Vector (0, 0); @@ -139,6 +153,7 @@ IceCrusher::update(float elapsed_time) if (get_bbox().p1.y <= start_position.y+1) { set_pos(start_position); movement = Vector (0, 0); + cooldown_timer = PAUSE_TIME; set_state(IDLE); } else { diff --git a/src/object/icecrusher.hpp b/src/object/icecrusher.hpp index 2a0c5f90a..096fdfb5c 100644 --- a/src/object/icecrusher.hpp +++ b/src/object/icecrusher.hpp @@ -51,6 +51,7 @@ protected: IceCrusherState state; Vector start_position; Physic physic; + float cooldown_timer; Player* get_nearest_player(); bool found_victim(); -- 2.11.0