From: Marek Moeckel Date: Wed, 24 Nov 2004 17:33:50 +0000 (+0000) Subject: added simple enemy dispenser (can only dispense bouncing snowballs so far and looks... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=3f1a54cc4a2b8deb8ebb31061a00ffcec5fb3169;p=supertux.git added simple enemy dispenser (can only dispense bouncing snowballs so far and looks like a snowball) it's in data/test/bonusblocks.stl, right behind the secret area ;-) fixed typo(?) in mrbomb.cpp SVN-Revision: 2170 --- diff --git a/data/levels/test/bonusblock.stl b/data/levels/test/bonusblock.stl index ffa1bb294..0ffa4c016 100644 --- a/data/levels/test/bonusblock.stl +++ b/data/levels/test/bonusblock.stl @@ -9,7 +9,8 @@ (gravity 10.000000) (background (image "arctis.jpg") (speed 0.5)) - (secretarea (x 128) (y 128) (message "You found a secret area!")) + (secretarea (x 400) (y 128) (message "You found a secret area!")) + (dispenser (x 500) (y 128) (badguy "snowball")) (spawn-points (name "main") (x 100) diff --git a/src/badguy/bouncing_snowball.cpp b/src/badguy/bouncing_snowball.cpp index 734e60a37..4f9334d7b 100644 --- a/src/badguy/bouncing_snowball.cpp +++ b/src/badguy/bouncing_snowball.cpp @@ -13,6 +13,14 @@ BouncingSnowball::BouncingSnowball(LispReader& reader) sprite = sprite_manager->create("bouncingsnowball"); } +BouncingSnowball::BouncingSnowball(float pos_x, float pos_y) +{ + start_position.x = pos_x; + start_position.y = pos_y; + bbox.set_size(32, 32); + sprite = sprite_manager->create("bouncingsnowball"); +} + void BouncingSnowball::write(LispWriter& writer) { diff --git a/src/badguy/bouncing_snowball.h b/src/badguy/bouncing_snowball.h index 5bc7c1156..7aea25dae 100644 --- a/src/badguy/bouncing_snowball.h +++ b/src/badguy/bouncing_snowball.h @@ -7,6 +7,7 @@ class BouncingSnowball : public BadGuy { public: BouncingSnowball(LispReader& reader); + BouncingSnowball(float pos_x, float pos_y); void activate(); void write(LispWriter& writer); diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp new file mode 100644 index 000000000..84f7e2a04 --- /dev/null +++ b/src/badguy/dispenser.cpp @@ -0,0 +1,63 @@ +#include + +#include "dispenser.h" +#include "badguy/bouncing_snowball.h" + +#define DISPENSE_TIME 3 + +Dispenser::Dispenser(LispReader& reader) +{ + reader.read_float("x", start_position.x); + reader.read_float("y", start_position.y); + reader.read_string("badguy", badguy); + bbox.set_size(32, 32); + sprite = sprite_manager->create("snowball"); +} + +void +Dispenser::write(LispWriter& writer) +{ + writer.start_list("dispenser"); + + writer.write_float("x", get_pos().x); + writer.write_float("y", get_pos().y); + writer.write_string("badguy", badguy); + + writer.end_list("dispenser"); +} + +void +Dispenser::activate() +{ + dispense_timer.start(DISPENSE_TIME, true); +} + +bool +Dispenser::collision_squished(Player& player) +{ + remove_me(); + player.bounce(*this); + return true; +} + +void +Dispenser::active_action(float elapsed_time) +{ + if (dispense_timer.check()) { + Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y)); + } +} + +HitResponse +Dispenser::collision_solid(GameObject& , const CollisionHit& hit) +{ + if(fabsf(hit.normal.y) > .5) { // hit floor or roof? + physic.set_velocity_y(0); + } else { // hit right or left + dir = dir == LEFT ? RIGHT : LEFT; + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } + + return CONTINUE; +} diff --git a/src/badguy/dispenser.h b/src/badguy/dispenser.h new file mode 100644 index 000000000..571954f1b --- /dev/null +++ b/src/badguy/dispenser.h @@ -0,0 +1,24 @@ +#ifndef __DISPENSER_H__ +#define __DISPENSER_H__ + +#include "badguy.h" +#include "timer.h" + +class Dispenser : public BadGuy +{ +public: + Dispenser(LispReader& reader); + + void activate(); + void write(LispWriter& writer); + HitResponse collision_solid(GameObject& other, const CollisionHit& hit); + void active_action(float elapsed_time); + +protected: + bool collision_squished(Player& player); + std::string badguy; + Timer2 dispense_timer; +}; + +#endif + diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 1bc384c40..5c1e70735 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -16,12 +16,12 @@ MrBomb::MrBomb(LispReader& reader) void MrBomb::write(LispWriter& writer) { - writer.start_list("snowball"); + writer.start_list("mrbomb"); writer.write_float("x", get_pos().x); writer.write_float("y", get_pos().y); - writer.end_list("snowball"); + writer.end_list("mrbomb"); } void diff --git a/src/sector.cpp b/src/sector.cpp index 52f154b85..c5b81a8f3 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -54,6 +54,7 @@ #include "badguy/flame.h" #include "badguy/mriceblock.h" #include "badguy/mrbomb.h" +#include "badguy/dispenser.h" #include "trigger/sequence_trigger.h" #include "trigger/secretarea_trigger.h" @@ -152,6 +153,8 @@ Sector::parseObject(const std::string& name, LispReader& reader) return new MrIceBlock(reader); } else if(name == "mrbomb") { return new MrBomb(reader); + } else if(name == "dispenser") { + return new Dispenser(reader); } #if 0 else if(badguykind_from_string(name) != BAD_INVALID) { diff --git a/src/trigger/secretarea_trigger.cpp b/src/trigger/secretarea_trigger.cpp index 9fd16bfcd..0420b0992 100644 --- a/src/trigger/secretarea_trigger.cpp +++ b/src/trigger/secretarea_trigger.cpp @@ -4,6 +4,8 @@ #include "utils/lispwriter.h" #include "gameloop.h" +#define MESSAGE_TIME 3 + SecretAreaTrigger::SecretAreaTrigger(LispReader& reader) { reader.read_float("x", bbox.p1.x); diff --git a/src/trigger/secretarea_trigger.h b/src/trigger/secretarea_trigger.h index d16377c29..d8fad64fc 100644 --- a/src/trigger/secretarea_trigger.h +++ b/src/trigger/secretarea_trigger.h @@ -8,8 +8,6 @@ #include "app/globals.h" #include "timer.h" -#define MESSAGE_TIME 3 - class SecretAreaTrigger : public TriggerBase, public Serializable { public: