From: Marek Moeckel Date: Mon, 4 Apr 2005 15:22:53 +0000 (+0000) Subject: added MrRocket badguy and added him to the Dispenser. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=bb5bf44283e1ca2a3cc306f557cef5dbc8c20a22;p=supertux.git added MrRocket badguy and added him to the Dispenser. Try in the NolokTest level SVN-Revision: 2326 --- diff --git a/data/images/shared/mrrocket-0.png b/data/images/shared/mrrocket-0.png new file mode 100644 index 000000000..4c04c06ee Binary files /dev/null and b/data/images/shared/mrrocket-0.png differ diff --git a/data/images/shared/mrrocket-collision.png b/data/images/shared/mrrocket-collision.png new file mode 100644 index 000000000..e204f4fbe Binary files /dev/null and b/data/images/shared/mrrocket-collision.png differ diff --git a/data/images/shared/mrrocket-explosion-1.png b/data/images/shared/mrrocket-explosion-1.png new file mode 100644 index 000000000..d7f047d99 Binary files /dev/null and b/data/images/shared/mrrocket-explosion-1.png differ diff --git a/data/images/shared/mrrocket-explosion.png b/data/images/shared/mrrocket-explosion.png new file mode 100644 index 000000000..37f1a7b8b Binary files /dev/null and b/data/images/shared/mrrocket-explosion.png differ diff --git a/data/images/shared/mrrocket-squished.png b/data/images/shared/mrrocket-squished.png new file mode 100644 index 000000000..99e7f52ac Binary files /dev/null and b/data/images/shared/mrrocket-squished.png differ diff --git a/data/images/supertux.strf b/data/images/supertux.strf index c421b5891..3b22127fc 100644 --- a/data/images/supertux.strf +++ b/data/images/supertux.strf @@ -1098,7 +1098,62 @@ (name "broken") (x-offset 0) (y-offset 0) - (images "shared/dispenser-broken.png"))) + (images "shared/dispenser-broken.png"))) + + ; MrRocket + (sprite (name "mrrocket") + (action + (name "left") + (fps 10.0) + (x-offset 3) + (y-offset 12) + (images "shared/mrrocket-0.png")) + + (action + (name "right") + (fps 10.0) + (x-offset 7) + (y-offset 12) + (mirror-action "left")) + + (action + (name "squished-left") + (x-offset 7) + (y-offset 0) + (images "shared/mrrocket-squished.png")) + + (action + (name "squished-right") + (x-offset 7) + (y-offset 0) + (mirror-action "squished-left")) + + (action + (name "collision-left") + (x-offset 3) + (y-offset 12) + (images "shared/mrrocket-collision.png")) + + (action + (name "collision-right") + (x-offset 3) + (y-offset 12) + (mirror-action "squished-left"))) + + (sprite (name "rocketexplosion") + (action + (name "explosion-left") + (fps 15.0) + (x-offset 0) + (y-offset 32) + (images "shared/mrrocket-explosion.png" + "shared/mrrocket-explosion-1.png")) + (action + (name "explosion-right") + (fps 15.0) + (x-offset 0) + (y-offset 32) + (mirror-action "explosion-left"))) ; Dummyguy (sprite (name "dummyguy") diff --git a/data/levels/test/noloktest.stl b/data/levels/test/noloktest.stl index f832cea59..9e4011e6e 100644 --- a/data/levels/test/noloktest.stl +++ b/data/levels/test/noloktest.stl @@ -50,7 +50,7 @@ (speed 0.5)) (spawnpoint (name "main2") (x 100) (y 100)) (secretarea (x 100) (y 100) (message "You found a secret area!")) - (dispenser (x 700) (y 500) (badguy "snowball") (cycle 2)) + (dispenser (x 700) (y 500) (badguy "mrrocket") (cycle 2)) (jumpy (x 500) (y 400)) (tilemap (layer "background") diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp index 0a92074dc..2ff06b83c 100644 --- a/src/badguy/dispenser.cpp +++ b/src/badguy/dispenser.cpp @@ -5,6 +5,7 @@ #include "badguy/snowball.h" #include "badguy/mrbomb.h" #include "badguy/mriceblock.h" +#include "badguy/mrrocket.h" Dispenser::Dispenser(const lisp::Lisp& reader) { @@ -40,10 +41,11 @@ Dispenser::activate() bool Dispenser::collision_squished(Player& player) { - //FIXME: Should act like a normal tile when killed + //TODO: Should it act like a normal tile when killed? sprite->set_action("broken"); dispense_timer.start(0); player.bounce(*this); + kill_squished(player); return true; } @@ -55,38 +57,23 @@ Dispenser::active_action(float ) } } -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; -} - -//TODO: Add launching velocity to badguys -// Add randomizer -// Clean up stuff I copied without understanding what it does :) -// Stop dispensing when game is paused (timer related problem) -// Lots-O-Stuff (tm) +//TODO: Add launching velocity to certain badguys +// Add randomizer (themed to match tileset) 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, get_pos().y, dir)); + Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir)); else if (badguy == "bouncingsnowball") - Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y, dir)); + Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir)); else if (badguy == "mrbomb") - Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y, dir)); + Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y+32, dir)); else if (badguy == "mriceblock") - Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y, dir)); + Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir)); + else if (badguy == "mrrocket") + Sector::current()->add_object(new MrRocket(get_pos().x, get_pos().y+32, dir)); else if (badguy == "random") {} } diff --git a/src/badguy/dispenser.h b/src/badguy/dispenser.h index 3dd24899e..a749885cc 100644 --- a/src/badguy/dispenser.h +++ b/src/badguy/dispenser.h @@ -11,7 +11,6 @@ public: void activate(); void write(lisp::Writer& writer); - HitResponse collision_solid(GameObject& other, const CollisionHit& hit); void active_action(float elapsed_time); protected: diff --git a/src/badguy/mrrocket.cpp b/src/badguy/mrrocket.cpp new file mode 100644 index 000000000..1c2a95564 --- /dev/null +++ b/src/badguy/mrrocket.cpp @@ -0,0 +1,81 @@ +#include + +#include "mrrocket.h" + +static const float SPEED = 200; + +MrRocket::MrRocket(const lisp::Lisp& reader) +{ + reader.get("x", start_position.x); + reader.get("y", start_position.y); + bbox.set_size(31.8, 31.8); + sprite = sprite_manager->create("mrrocket"); + set_direction = false; +} + +MrRocket::MrRocket(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("mrrocket"); + set_direction = true; + initial_direction = d; +} + +void +MrRocket::write(lisp::Writer& writer) +{ + writer.start_list("mrrocket"); + + writer.write_float("x", start_position.x); + writer.write_float("y", start_position.y); + + writer.end_list("mrrocket"); +} + +void +MrRocket::activate() +{ + if (set_direction) {dir = initial_direction;} + physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED); + physic.enable_gravity(false); + sprite->set_action(dir == LEFT ? "left" : "right"); +} + +void +MrRocket::active_action(float elapsed_time) +{ + if (collision_timer.check()) { + Sector::current()->add_object(new RocketExplosion(get_pos(), dir)); + kill_fall(); + } + else if (!collision_timer.started()) { + movement=physic.get_movement(elapsed_time); + sprite->set_action(dir == LEFT ? "left" : "right"); + } +} + +bool +MrRocket::collision_squished(Player& player) +{ + sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); + kill_squished(player); + return true; +} + +HitResponse +MrRocket::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 + sprite->set_action(dir == LEFT ? "collision-left" : "collision-right"); + physic.set_velocity_x(0); + collision_timer.start(0.2, true); + } + + return CONTINUE; +} + +IMPLEMENT_FACTORY(MrRocket, "mrrocket") diff --git a/src/badguy/mrrocket.h b/src/badguy/mrrocket.h new file mode 100644 index 000000000..4582a04a8 --- /dev/null +++ b/src/badguy/mrrocket.h @@ -0,0 +1,27 @@ +#ifndef __MRROCKET_H__ +#define __MRROCKET_H__ + +#include "badguy.h" +#include "timer.h" +#include "rocketexplosion.h" + +class MrRocket : public BadGuy +{ +public: + MrRocket(const lisp::Lisp& reader); + MrRocket(float pos_x, float pos_y, Direction d); + + void activate(); + void active_action(float elapsed_time); + void write(lisp::Writer& writer); + HitResponse collision_solid(GameObject& other, const CollisionHit& hit); + +protected: + bool collision_squished(Player& player); + bool set_direction; + Direction initial_direction; + Timer2 collision_timer; +}; + +#endif + diff --git a/src/badguy/rocketexplosion.cpp b/src/badguy/rocketexplosion.cpp new file mode 100644 index 000000000..e7aaed36a --- /dev/null +++ b/src/badguy/rocketexplosion.cpp @@ -0,0 +1,68 @@ +#include + +#include "rocketexplosion.h" + +static const float EXPLOSIONTIME = 1; + +RocketExplosion::RocketExplosion(const Vector& pos, Direction dir) +{ + start_position = pos; + bbox.set_pos(pos); + bbox.set_size(31.8, 31.8); + sprite = sprite_manager->create("rocketexplosion"); + this->dir = dir; + explode(); +} + +void +RocketExplosion::write(lisp::Writer& ) +{ + // bombs are only temporarily so don't write them out... +} + +HitResponse +RocketExplosion::collision_solid(GameObject& , const CollisionHit& hit) +{ + if(fabsf(hit.normal.y) > .5) + physic.set_velocity_y(0); + + return CONTINUE; +} + +HitResponse +RocketExplosion::collision_player(Player& player, const CollisionHit& ) +{ + player.kill(Player::SHRINK); + return ABORT_MOVE; +} + +HitResponse +RocketExplosion::collision_badguy(BadGuy& badguy, const CollisionHit& ) +{ + badguy.kill_fall(); + return ABORT_MOVE; +} + +void +RocketExplosion::active_action(float elapsed_time) +{ + if(timer.check()) { + remove_me(); + } +} + +void +RocketExplosion::explode() +{ + sprite->set_action(dir == LEFT ? "explosion-left" : "explosion-right"); + SoundManager::get()->play_sound(IDToSound(SND_EXPLODE), get_pos(), + Sector::current()->player->get_pos()); + timer.start(EXPLOSIONTIME, true); +} + +void +RocketExplosion::kill_fall() +{ + explode(); +} + diff --git a/src/badguy/rocketexplosion.h b/src/badguy/rocketexplosion.h new file mode 100644 index 000000000..ffa2dee8b --- /dev/null +++ b/src/badguy/rocketexplosion.h @@ -0,0 +1,24 @@ +#ifndef __BOMB_H__ +#define __BOMB_H__ + +#include "badguy.h" + +class RocketExplosion : public BadGuy +{ +public: + RocketExplosion(const Vector& pos, Direction dir); + + void write(lisp::Writer& writer); + HitResponse collision_solid(GameObject& other, const CollisionHit& hit); + HitResponse collision_player(Player& player, const CollisionHit& hit); + HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); + void active_action(float elapsed_time); + void kill_fall(); + void explode(); + +private: + Timer2 timer; +}; + +#endif +