(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")
(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")
#include "badguy/snowball.h"
#include "badguy/mrbomb.h"
#include "badguy/mriceblock.h"
+#include "badguy/mrrocket.h"
Dispenser::Dispenser(const lisp::Lisp& reader)
{
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;
}
}
}
-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")
{}
}
void activate();
void write(lisp::Writer& writer);
- HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
void active_action(float elapsed_time);
protected:
--- /dev/null
+#include <config.h>
+
+#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")
--- /dev/null
+#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
+
--- /dev/null
+#include <config.h>
+
+#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();
+}
+
--- /dev/null
+#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
+