added simple enemy dispenser (can only dispense bouncing snowballs so far and looks...
authorMarek Moeckel <wansti@gmx.de>
Wed, 24 Nov 2004 17:33:50 +0000 (17:33 +0000)
committerMarek Moeckel <wansti@gmx.de>
Wed, 24 Nov 2004 17:33:50 +0000 (17:33 +0000)
it's in data/test/bonusblocks.stl, right behind the secret area ;-)
fixed typo(?) in mrbomb.cpp

SVN-Revision: 2170

data/levels/test/bonusblock.stl
src/badguy/bouncing_snowball.cpp
src/badguy/bouncing_snowball.h
src/badguy/dispenser.cpp [new file with mode: 0644]
src/badguy/dispenser.h [new file with mode: 0644]
src/badguy/mrbomb.cpp
src/sector.cpp
src/trigger/secretarea_trigger.cpp
src/trigger/secretarea_trigger.h

index ffa1bb2..0ffa4c0 100644 (file)
@@ -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)
index 734e60a..4f9334d 100644 (file)
@@ -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)
 {
index 5bc7c11..7aea25d 100644 (file)
@@ -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 (file)
index 0000000..84f7e2a
--- /dev/null
@@ -0,0 +1,63 @@
+#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;
+}
diff --git a/src/badguy/dispenser.h b/src/badguy/dispenser.h
new file mode 100644 (file)
index 0000000..571954f
--- /dev/null
@@ -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
+
index 1bc384c..5c1e707 100644 (file)
@@ -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
index 52f154b..c5b81a8 100644 (file)
@@ -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) {
index 9fd16bf..0420b09 100644 (file)
@@ -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);
index d16377c..d8fad64 100644 (file)
@@ -8,8 +8,6 @@
 #include "app/globals.h"
 #include "timer.h"
 
-#define MESSAGE_TIME 3
-
 class SecretAreaTrigger : public TriggerBase, public Serializable
 {
 public: