added MrRocket badguy and added him to the Dispenser.
authorMarek Moeckel <wansti@gmx.de>
Mon, 4 Apr 2005 15:22:53 +0000 (15:22 +0000)
committerMarek Moeckel <wansti@gmx.de>
Mon, 4 Apr 2005 15:22:53 +0000 (15:22 +0000)
Try in the NolokTest level

SVN-Revision: 2326

13 files changed:
data/images/shared/mrrocket-0.png [new file with mode: 0644]
data/images/shared/mrrocket-collision.png [new file with mode: 0644]
data/images/shared/mrrocket-explosion-1.png [new file with mode: 0644]
data/images/shared/mrrocket-explosion.png [new file with mode: 0644]
data/images/shared/mrrocket-squished.png [new file with mode: 0644]
data/images/supertux.strf
data/levels/test/noloktest.stl
src/badguy/dispenser.cpp
src/badguy/dispenser.h
src/badguy/mrrocket.cpp [new file with mode: 0644]
src/badguy/mrrocket.h [new file with mode: 0644]
src/badguy/rocketexplosion.cpp [new file with mode: 0644]
src/badguy/rocketexplosion.h [new file with mode: 0644]

diff --git a/data/images/shared/mrrocket-0.png b/data/images/shared/mrrocket-0.png
new file mode 100644 (file)
index 0000000..4c04c06
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 (file)
index 0000000..e204f4f
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 (file)
index 0000000..d7f047d
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 (file)
index 0000000..37f1a7b
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 (file)
index 0000000..99e7f52
Binary files /dev/null and b/data/images/shared/mrrocket-squished.png differ
index c421b58..3b22127 100644 (file)
           (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")
index f832cea..9e4011e 100644 (file)
@@ -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")
index 0a92074..2ff06b8 100644 (file)
@@ -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")
     {}
   }
index 3dd2489..a749885 100644 (file)
@@ -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 (file)
index 0000000..1c2a955
--- /dev/null
@@ -0,0 +1,81 @@
+#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")
diff --git a/src/badguy/mrrocket.h b/src/badguy/mrrocket.h
new file mode 100644 (file)
index 0000000..4582a04
--- /dev/null
@@ -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 (file)
index 0000000..e7aaed3
--- /dev/null
@@ -0,0 +1,68 @@
+#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();
+}
+
diff --git a/src/badguy/rocketexplosion.h b/src/badguy/rocketexplosion.h
new file mode 100644 (file)
index 0000000..ffa2dee
--- /dev/null
@@ -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
+