(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)
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)
{
{
public:
BouncingSnowball(LispReader& reader);
+ BouncingSnowball(float pos_x, float pos_y);
void activate();
void write(LispWriter& writer);
--- /dev/null
+#include <config.h>
+
+#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;
+}
--- /dev/null
+#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
+
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
#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"
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) {
#include "utils/lispwriter.h"
#include "gameloop.h"
+#define MESSAGE_TIME 3
+
SecretAreaTrigger::SecretAreaTrigger(LispReader& reader)
{
reader.read_float("x", bbox.p1.x);
#include "app/globals.h"
#include "timer.h"
-#define MESSAGE_TIME 3
-
class SecretAreaTrigger : public TriggerBase, public Serializable
{
public: