From: Marek Moeckel Date: Wed, 24 Nov 2004 18:19:51 +0000 (+0000) Subject: dispenser can now launch snowballs and bouncingsnowballs X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=db274bd420ddc2568985296cf293003099033001;p=supertux.git dispenser can now launch snowballs and bouncingsnowballs SVN-Revision: 2172 --- diff --git a/data/levels/test/bonusblock.stl b/data/levels/test/bonusblock.stl index 11dd329ee..842c3f634 100644 --- a/data/levels/test/bonusblock.stl +++ b/data/levels/test/bonusblock.stl @@ -10,7 +10,7 @@ (background (image "arctis.jpg") (speed 0.5)) (secretarea (x 400) (y 128) (message "You found a secret area!")) - (dispenser (x 500) (y 128) (badguy "snowball") (cycle 3)) + (dispenser (x 500) (y 128) (badguy "bouncingsnowball") (cycle 2)) (spawn-points (name "main") (x 100) diff --git a/src/badguy/badguy.h b/src/badguy/badguy.h index d92d6b2ff..c0904083c 100644 --- a/src/badguy/badguy.h +++ b/src/badguy/badguy.h @@ -84,11 +84,12 @@ protected: * initial position of the enemy. Also the position where enemy respawns when * after being deactivated. */ + bool is_offscreen(); + Vector start_position; Direction dir; private: - bool is_offscreen(); void try_activate(); State state; diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp index e9e45ec2e..d8ec81257 100644 --- a/src/badguy/dispenser.cpp +++ b/src/badguy/dispenser.cpp @@ -2,6 +2,8 @@ #include "dispenser.h" #include "badguy/bouncing_snowball.h" +#include "badguy/snowball.h" + Dispenser::Dispenser(LispReader& reader) { @@ -10,6 +12,7 @@ Dispenser::Dispenser(LispReader& reader) reader.read_float("cycle", cycle); reader.read_string("badguy", badguy); bbox.set_size(32, 32); + //FIXME: Create dispenser sprite sprite = sprite_manager->create("snowball"); } @@ -28,8 +31,9 @@ Dispenser::write(LispWriter& writer) void Dispenser::activate() -{ +{ dispense_timer.start(cycle, true); + launch_badguy(); } bool @@ -44,7 +48,7 @@ void Dispenser::active_action(float elapsed_time) { if (dispense_timer.check()) { - Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y)); + launch_badguy(); } } @@ -61,3 +65,21 @@ Dispenser::collision_solid(GameObject& , const CollisionHit& hit) return CONTINUE; } + +//TODO: Add launching velocity to badguys +// Add more badguys and randomizer +// Clean up stuff I copied without understanding what it does :) +// Lots-O-Stuff (tm) +void +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)); + else if (badguy == "bouncingsnowball") + Sector::current()->add_object(new BouncingSnowball(get_pos().x-2, get_pos().y)); + else if (badguy == "random") + {} + } +} diff --git a/src/badguy/dispenser.h b/src/badguy/dispenser.h index 76abc28bf..6c83a28d8 100644 --- a/src/badguy/dispenser.h +++ b/src/badguy/dispenser.h @@ -16,6 +16,7 @@ public: protected: bool collision_squished(Player& player); + void launch_badguy(); float cycle; std::string badguy; Timer2 dispense_timer; diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 5c1e70735..dbf23b712 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -13,6 +13,14 @@ MrBomb::MrBomb(LispReader& reader) sprite = sprite_manager->create("mrbomb"); } +MrBomb::MrBomb(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("mrbomb"); +} + void MrBomb::write(LispWriter& writer) { diff --git a/src/badguy/mrbomb.h b/src/badguy/mrbomb.h index a20b253d3..c097ad138 100644 --- a/src/badguy/mrbomb.h +++ b/src/badguy/mrbomb.h @@ -7,6 +7,7 @@ class MrBomb : public BadGuy { public: MrBomb(LispReader& reader); + MrBomb(float pos_x, float pos_y); void activate(); void write(LispWriter& writer); diff --git a/src/badguy/snowball.cpp b/src/badguy/snowball.cpp index ce5ac61d4..ac9b27704 100644 --- a/src/badguy/snowball.cpp +++ b/src/badguy/snowball.cpp @@ -12,6 +12,14 @@ SnowBall::SnowBall(LispReader& reader) sprite = sprite_manager->create("snowball"); } +SnowBall::SnowBall(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("snowball"); +} + void SnowBall::write(LispWriter& writer) { diff --git a/src/badguy/snowball.h b/src/badguy/snowball.h index 99a65d651..4d2a403b0 100644 --- a/src/badguy/snowball.h +++ b/src/badguy/snowball.h @@ -7,6 +7,7 @@ class SnowBall : public BadGuy { public: SnowBall(LispReader& reader); + SnowBall(float pos_x, float pos_y); void activate(); void write(LispWriter& writer);