From f41a5719a2dc1a50674c69fa511c38a152cc4b03 Mon Sep 17 00:00:00 2001 From: Marek Moeckel Date: Thu, 25 Nov 2004 16:22:05 +0000 Subject: [PATCH] updated dispenser -- can summon mriceblock, snowball, bouncing_snowball and mrbomb now fixed message display of the secret area trigger ended some more of Nolok's minor troubles :) SVN-Revision: 2192 --- data/levels/test/bonusblock.stl | 1 + src/badguy/dispenser.cpp | 14 ++++++++++---- src/badguy/mrbomb.cpp | 6 +++++- src/badguy/mrbomb.h | 4 +++- src/badguy/mriceblock.cpp | 13 +++++++++++++ src/badguy/mriceblock.h | 3 +++ src/badguy/nolok_01.cpp | 27 +++++++++++++++++---------- src/badguy/nolok_01.h | 4 ++-- src/badguy/snowball.cpp | 6 +++++- src/badguy/snowball.h | 4 +++- src/trigger/secretarea_trigger.cpp | 14 +++++++++++--- src/trigger/secretarea_trigger.h | 1 + 12 files changed, 74 insertions(+), 23 deletions(-) diff --git a/data/levels/test/bonusblock.stl b/data/levels/test/bonusblock.stl index cf8cdadef..f8203cc0f 100644 --- a/data/levels/test/bonusblock.stl +++ b/data/levels/test/bonusblock.stl @@ -14,6 +14,7 @@ (x 100) (y 170) ) + (secretarea (x 100) (y 170) (message "This is a Secret Area Test")) (tilemap (layer "background") (solid #f) diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp index 953a32137..c2ba901ff 100644 --- a/src/badguy/dispenser.cpp +++ b/src/badguy/dispenser.cpp @@ -3,6 +3,8 @@ #include "dispenser.h" #include "badguy/bouncing_snowball.h" #include "badguy/snowball.h" +#include "badguy/mrbomb.h" +#include "badguy/mriceblock.h" Dispenser::Dispenser(LispReader& reader) @@ -69,9 +71,9 @@ Dispenser::collision_solid(GameObject& , const CollisionHit& hit) } //TODO: Add launching velocity to badguys -// Add more badguys and randomizer +// Add randomizer // Clean up stuff I copied without understanding what it does :) -// Stop dispensing when game is paused +// Stop dispensing when game is paused (timer related problem) // Lots-O-Stuff (tm) void Dispenser::launch_badguy() @@ -79,9 +81,13 @@ Dispenser::launch_badguy() //FIXME: Does is_offscreen() work right here? if (!is_offscreen()) { if (badguy == "snowball") - Sector::current()->add_object(new SnowBall(get_pos().x-2, get_pos().y)); + Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y, dir)); else if (badguy == "bouncingsnowball") - Sector::current()->add_object(new BouncingSnowball(get_pos().x-2, get_pos().y, dir)); + Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y, dir)); + else if (badguy == "mrbomb") + Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y, dir)); + else if (badguy == "mriceblock") + Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y, dir)); else if (badguy == "random") {} } diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 6a9ca03e9..b7a443d33 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -11,14 +11,17 @@ MrBomb::MrBomb(LispReader& reader) reader.read_float("y", start_position.y); bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("mrbomb"); + set_direction = false; } -MrBomb::MrBomb(float pos_x, float pos_y) +MrBomb::MrBomb(float pos_x, float pos_y, Direction d) { start_position.x = pos_x; start_position.y = pos_y; bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("mrbomb"); + set_direction = true; + initial_direction = d; } void @@ -35,6 +38,7 @@ MrBomb::write(LispWriter& writer) void MrBomb::activate() { + if (set_direction) {dir = initial_direction;} physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); } diff --git a/src/badguy/mrbomb.h b/src/badguy/mrbomb.h index c097ad138..257716fb3 100644 --- a/src/badguy/mrbomb.h +++ b/src/badguy/mrbomb.h @@ -7,7 +7,7 @@ class MrBomb : public BadGuy { public: MrBomb(LispReader& reader); - MrBomb(float pos_x, float pos_y); + MrBomb(float pos_x, float pos_y, Direction d); void activate(); void write(LispWriter& writer); @@ -15,6 +15,8 @@ public: protected: bool collision_squished(Player& player); + bool set_direction; + Direction initial_direction; }; #endif diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index cfda395fb..72a007cbb 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -13,6 +13,18 @@ MrIceBlock::MrIceBlock(LispReader& reader) reader.read_float("y", start_position.y); bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("mriceblock"); + set_direction = false; +} + +MrIceBlock::MrIceBlock(float pos_x, float pos_y, Direction d) + : ice_state(ICESTATE_NORMAL), squishcount(0) +{ + start_position.x = pos_x; + start_position.y = pos_y; + bbox.set_size(31.8, 31.8); + sprite = sprite_manager->create("mriceblock"); + set_direction = true; + initial_direction = d; } void @@ -29,6 +41,7 @@ MrIceBlock::write(LispWriter& writer) void MrIceBlock::activate() { + if (set_direction) {dir = initial_direction;} physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); } diff --git a/src/badguy/mriceblock.h b/src/badguy/mriceblock.h index 3b9169003..7275c0ee2 100644 --- a/src/badguy/mriceblock.h +++ b/src/badguy/mriceblock.h @@ -7,6 +7,7 @@ class MrIceBlock : public BadGuy { public: MrIceBlock(LispReader& reader); + MrIceBlock(float pos_x, float pos_y, Direction d); void activate(); void write(LispWriter& writer); @@ -26,6 +27,8 @@ private: IceState ice_state; Timer2 flat_timer; int squishcount; + bool set_direction; + Direction initial_direction; }; #endif diff --git a/src/badguy/nolok_01.cpp b/src/badguy/nolok_01.cpp index b8499c544..1090d972d 100644 --- a/src/badguy/nolok_01.cpp +++ b/src/badguy/nolok_01.cpp @@ -11,7 +11,6 @@ static const float WALKSPEED = 90; //TODO: Create sprite, give multiple hitpoints, limit max number of snowballs -// Can only be killed when jumping, no idea why // Stop actions when pause button is hit (probably a general problem of timers) Nolok_01::Nolok_01(LispReader& reader) { @@ -52,27 +51,35 @@ Nolok_01::activate() void Nolok_01::active_action(float elapsed_time) { - movement = physic.get_movement(elapsed_time); if (action_timer.check()) { - if (action == WALKING) { - physic.set_velocity_y(700); - action = JUMPING; - action_timer.start(JUMP_TIME); - } - else if (action == JUMPING) { + switch (action) { + case WALKING: + { + physic.set_velocity_y(700); + action = JUMPING; + action_timer.start(JUMP_TIME); + break; + } + case JUMPING: + { sprite->set_action("throw"); action = SHOOTING; action_timer.start(SHOOT_TIME); - } - else if (action == SHOOTING) { + break; + } + case SHOOTING: + { Sector::current()->add_object(new BouncingSnowball(get_pos().x - 64, get_pos().y, LEFT)); Sector::current()->add_object(new BouncingSnowball(get_pos().x + 64, get_pos().y, RIGHT)); physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); action = WALKING; action_timer.start(WALK_TIME); + break; + } } } + movement = physic.get_movement(elapsed_time); } bool diff --git a/src/badguy/nolok_01.h b/src/badguy/nolok_01.h index 61011aa0a..b35ca369b 100644 --- a/src/badguy/nolok_01.h +++ b/src/badguy/nolok_01.h @@ -18,8 +18,8 @@ public: protected: bool collision_squished(Player& player); Timer2 action_timer; - enum { WALKING, JUMPING, SHOOTING }; - int action; + enum Actions { WALKING, JUMPING, SHOOTING }; + Actions action; }; #endif diff --git a/src/badguy/snowball.cpp b/src/badguy/snowball.cpp index b16e8cfb5..de77435b7 100644 --- a/src/badguy/snowball.cpp +++ b/src/badguy/snowball.cpp @@ -10,14 +10,17 @@ SnowBall::SnowBall(LispReader& reader) reader.read_float("y", start_position.y); bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("snowball"); + set_direction = false; } -SnowBall::SnowBall(float pos_x, float pos_y) +SnowBall::SnowBall(float pos_x, float pos_y, Direction d) { start_position.x = pos_x; start_position.y = pos_y; bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("snowball"); + set_direction = true; + initial_direction = d; } void @@ -34,6 +37,7 @@ SnowBall::write(LispWriter& writer) void SnowBall::activate() { + if (set_direction) {dir = initial_direction;} physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); } diff --git a/src/badguy/snowball.h b/src/badguy/snowball.h index 4d2a403b0..55bf56c7f 100644 --- a/src/badguy/snowball.h +++ b/src/badguy/snowball.h @@ -7,7 +7,7 @@ class SnowBall : public BadGuy { public: SnowBall(LispReader& reader); - SnowBall(float pos_x, float pos_y); + SnowBall(float pos_x, float pos_y, Direction d); void activate(); void write(LispWriter& writer); @@ -15,6 +15,8 @@ public: protected: bool collision_squished(Player& player); + bool set_direction; + Direction initial_direction; }; #endif diff --git a/src/trigger/secretarea_trigger.cpp b/src/trigger/secretarea_trigger.cpp index 0420b0992..b57624c39 100644 --- a/src/trigger/secretarea_trigger.cpp +++ b/src/trigger/secretarea_trigger.cpp @@ -4,8 +4,9 @@ #include "utils/lispwriter.h" #include "gameloop.h" -#define MESSAGE_TIME 3 +#define MESSAGE_TIME 3.5 +//TODO: Count numbers of triggered/total secret areas SecretAreaTrigger::SecretAreaTrigger(LispReader& reader) { reader.read_float("x", bbox.p1.x); @@ -13,6 +14,7 @@ SecretAreaTrigger::SecretAreaTrigger(LispReader& reader) bbox.set_size(32, 32); reader.read_string("message", message); + message_displayed = false; } SecretAreaTrigger::SecretAreaTrigger(const Vector& pos) @@ -20,6 +22,7 @@ SecretAreaTrigger::SecretAreaTrigger(const Vector& pos) bbox.set_pos(pos); bbox.set_size(32, 32); message = "You found a secret area!"; + message_displayed = false; } SecretAreaTrigger::~SecretAreaTrigger() @@ -44,9 +47,11 @@ void SecretAreaTrigger::draw(DrawingContext& context) { if (message_timer.started()) { + context.push_transform(); + context.set_translation(Vector(0, 0)); Vector pos = Vector(0, screen->h/2 - gold_text->get_height()/2); context.draw_center_text(gold_text, message, pos, LAYER_GUI); - //TODO: Prevent text from scrolling with the rest of the level + context.pop_transform(); } if (message_timer.check()) { remove_me(); @@ -57,6 +62,9 @@ void SecretAreaTrigger::event(Player& , EventType type) { if(type == EVENT_TOUCH) { - message_timer.start(MESSAGE_TIME); + if (!message_displayed) { + message_timer.start(MESSAGE_TIME); + message_displayed = true; + } } } diff --git a/src/trigger/secretarea_trigger.h b/src/trigger/secretarea_trigger.h index d8fad64fc..945c0619b 100644 --- a/src/trigger/secretarea_trigger.h +++ b/src/trigger/secretarea_trigger.h @@ -22,6 +22,7 @@ public: private: std::string message; Timer2 message_timer; + bool message_displayed; }; #endif -- 2.11.0