* Implemented StayOnPlatform on badguys where useful
authorOndřej Hošek <ondra.hosek@gmail.com>
Fri, 14 Apr 2006 22:48:51 +0000 (22:48 +0000)
committerOndřej Hošek <ondra.hosek@gmail.com>
Fri, 14 Apr 2006 22:48:51 +0000 (22:48 +0000)
* "Outsourced" FallingCoin
* Mac header fix
* Level script import path fix

SVN-Revision: 3342

19 files changed:
data/levels/world2/level2.stl
src/badguy/dispenser.cpp
src/badguy/mrtree.cpp
src/badguy/nolok_01.cpp
src/badguy/poisonivy.cpp
src/badguy/poisonivy.hpp
src/badguy/snowball.cpp
src/badguy/snowball.hpp
src/badguy/snowsnail.cpp
src/badguy/snowsnail.hpp
src/badguy/spiky.cpp
src/badguy/spiky.hpp
src/badguy/sspiky.cpp
src/badguy/sspiky.hpp
src/object/falling_coin.cpp [new file with mode: 0644]
src/object/falling_coin.hpp [new file with mode: 0644]
src/object/player.cpp
src/object/player.hpp
src/worldmap/level.cpp

index 6901b9a..b830769 100644 (file)
        )
        (init-script "
           import(\"levels/world2/default.nut\");
-          import(\"script/default.nut\");
+          import(\"scripts/default.nut\");
           level2_init();
         ")
        (secretarea (x 673.0)
index 8e0f3de..ec8653f 100644 (file)
@@ -92,7 +92,7 @@ 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+32, dir));
+      Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir, false));
     else if (badguy == "bouncingsnowball")
       Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir));
     else if (badguy == "mrbomb")
@@ -100,23 +100,23 @@ Dispenser::launch_badguy()
     else if (badguy == "mriceblock")
       Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir, false));
     else if (badguy == "snowsnail")
-      Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir));
+      Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir, false));
     else if (badguy == "mrrocket") {
       Sector::current()->add_object(new MrRocket(get_pos().x+(dir == LEFT ? -32 : 32), get_pos().y, dir));}
     else if (badguy == "poisonivy")
-      Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir));
+      Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir, false));
     else if (badguy == "skullyhop")
       Sector::current()->add_object(new SkullyHop(get_pos().x, get_pos().y+44, dir));
     else if (badguy == "random")
     {
       switch (rand()%7)
       {
-        case 0: Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir)); break;
+        case 0: Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir, false)); break;
         case 1: Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir)); break;
         case 2: Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y+32, dir, false)); break;
         case 3: Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir, false)); break;
-        case 4: Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir)); break;
-        case 5: Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir)); break;
+        case 4: Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir, false)); break;
+        case 5: Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir, false)); break;
         case 6: Sector::current()->add_object(new SkullyHop(get_pos().x, get_pos().y+44, dir)); break;
       }
     }
index 496f092..dbcc450 100644 (file)
@@ -106,12 +106,12 @@ MrTree::collision_squished(Player& player)
 
     Rect leaf1_bbox = Rect(pos.x-32-1, pos.y-23+1, pos.x-32-1+32, pos.y-23+1+32);
     if (Sector::current()->is_free_space(leaf1_bbox)) {
-      PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1.x, leaf1_bbox.p1.y, LEFT);
+      PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1.x, leaf1_bbox.p1.y, LEFT, true);
       Sector::current()->add_object(leaf1);
     }
     Rect leaf2_bbox = Rect(pos.x+42+1, pos.y-23+1, pos.x+32+1+32, pos.y-23+1+32);
     if (Sector::current()->is_free_space(leaf2_bbox)) {
-      PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1.x, leaf2_bbox.p1.y, RIGHT);
+      PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1.x, leaf2_bbox.p1.y, RIGHT, true);
       Sector::current()->add_object(leaf2);
     }
 
index aa07791..c97ae4e 100644 (file)
@@ -94,8 +94,8 @@ Nolok_01::active_update(float elapsed_time)
        }
        case SHOOTING:
        {
-        Sector::current()->add_object(new SnowSnail(get_pos().x - 64, get_pos().y, LEFT));
-        Sector::current()->add_object(new SnowSnail(get_pos().x + 64, get_pos().y, RIGHT));
+        Sector::current()->add_object(new SnowSnail(get_pos().x - 64, get_pos().y, LEFT, true));
+        Sector::current()->add_object(new SnowSnail(get_pos().x + 64, get_pos().y, RIGHT, true));
         physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
         sprite->set_action(dir == LEFT ? "left" : "right");
         action = WALKING;
index cad1a64..c93f42e 100644 (file)
@@ -27,15 +27,18 @@ PoisonIvy::PoisonIvy(const lisp::Lisp& reader)
 {
   reader.get("x", start_position.x);
   reader.get("y", start_position.y);
+  stay_on_platform = false;
+  reader.get("stay-on-platform", stay_on_platform);
   bbox.set_size(31.8, 31.8);
   sprite = sprite_manager->create("images/creatures/poison_ivy/poison_ivy.sprite");
   set_direction = false;
 }
 
-PoisonIvy::PoisonIvy(float pos_x, float pos_y, Direction d)
+PoisonIvy::PoisonIvy(float pos_x, float pos_y, Direction d, bool stay_on_plat = false)
 {
   start_position.x = pos_x;
   start_position.y = pos_y;
+  stay_on_platform = stay_on_plat;
   bbox.set_size(31.8, 31.8);
   sprite = sprite_manager->create("images/creatures/poison_ivy/poison_ivy.sprite");
   set_direction = true;
@@ -49,6 +52,7 @@ PoisonIvy::write(lisp::Writer& writer)
 
   writer.write_float("x", start_position.x);
   writer.write_float("y", start_position.y);
+  if (stay_on_platform) writer.write_bool("stay-on-platform", true);
 
   writer.end_list("poisonivy");
 }
@@ -61,6 +65,17 @@ PoisonIvy::activate()
   sprite->set_action(dir == LEFT ? "left" : "right");
 }
 
+void
+PoisonIvy::active_update(float elapsed_time)
+{
+  if (stay_on_platform && may_fall_off_platform())
+  {
+    dir = (dir == LEFT ? RIGHT : LEFT);
+    sprite->set_action(dir == LEFT ? "left" : "right");
+    physic.set_velocity_x(-physic.get_velocity_x());
+  }
+}
+
 bool
 PoisonIvy::collision_squished(Player& player)
 {
index 33d7e2c..710c6ff 100644 (file)
@@ -26,16 +26,18 @@ class PoisonIvy : public BadGuy
 {
 public:
   PoisonIvy(const lisp::Lisp& reader);
-  PoisonIvy(float pos_x, float pos_y, Direction d);
+  PoisonIvy(float pos_x, float pos_y, Direction d, bool stay_on_plat);
 
   void activate();
   void write(lisp::Writer& writer);
+  void active_update(float elapsed_time);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit);
   
 protected:
   bool collision_squished(Player& player);
   bool set_direction;
+  bool stay_on_platform;
   Direction initial_direction;  
 };
 
index 1c2e6b6..357c152 100644 (file)
@@ -30,16 +30,19 @@ SnowBall::SnowBall(const lisp::Lisp& reader)
   //This is for a hidden badguy :)
   fluffy = false;  
   reader.get("fluffy",fluffy);
+  stay_on_platform = false;
+  reader.get("stay-on-platform", stay_on_platform);
   bbox.set_size(31.8, 31.8);
   if (fluffy) sprite = sprite_manager->create("images/creatures/fluffy/fluffy.sprite");
   else sprite = sprite_manager->create("images/creatures/snowball/snowball.sprite");
   set_direction = false;
 }
 
-SnowBall::SnowBall(float pos_x, float pos_y, Direction d)
+SnowBall::SnowBall(float pos_x, float pos_y, Direction d, bool stay_on_plat = false)
 {
   start_position.x = pos_x;
   start_position.y = pos_y;
+  stay_on_platform = stay_on_plat;
   bbox.set_size(31.8, 31.8);
   sprite = sprite_manager->create("images/creatures/snowball/snowball.sprite");
   set_direction = true;
@@ -58,6 +61,9 @@ SnowBall::write(lisp::Writer& writer)
     writer.write_bool("fluffy", true);
   }
 
+  if (stay_on_platform)
+    writer.write_bool("stay-on-platform", true);
+
   writer.end_list("snowball");
 }
 
@@ -69,6 +75,17 @@ SnowBall::activate()
   sprite->set_action(dir == LEFT ? "left" : "right");
 }
 
+void
+SnowBall::active_update(float elapsed_time)
+{
+  if (stay_on_platform && may_fall_off_platform())
+  {
+    dir = (dir == LEFT ? RIGHT : LEFT);
+    sprite->set_action(dir == LEFT ? "left" : "right");
+    physic.set_velocity_x(-physic.get_velocity_x());
+  }
+}
+
 bool
 SnowBall::collision_squished(Player& player)
 {
index ce642fb..370ae16 100644 (file)
@@ -26,16 +26,18 @@ class SnowBall : public BadGuy
 {
 public:
   SnowBall(const lisp::Lisp& reader);
-  SnowBall(float pos_x, float pos_y, Direction d);
+  SnowBall(float pos_x, float pos_y, Direction d, bool stay_on_plat);
 
   void activate();
   void write(lisp::Writer& writer);
+  void active_update(float elapsed_time);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit);
   
 protected:
   bool collision_squished(Player& player);
   bool set_direction;
+  bool stay_on_platform;
   Direction initial_direction;  
   bool fluffy;
 };
index 6799885..bd68f59 100644 (file)
@@ -31,16 +31,19 @@ SnowSnail::SnowSnail(const lisp::Lisp& reader)
 {
   reader.get("x", start_position.x);
   reader.get("y", start_position.y);
+  stay_on_platform = false;
+  reader.get("stay-on-platform", stay_on_platform);
   bbox.set_size(31.8, 31.8);
   sprite = sprite_manager->create("images/creatures/snowsnail/snowsnail.sprite");
   set_direction = false;
 }
 
-SnowSnail::SnowSnail(float pos_x, float pos_y, Direction d)
+SnowSnail::SnowSnail(float pos_x, float pos_y, Direction d, bool stay_on_plat = false)
   : ice_state(ICESTATE_NORMAL), squishcount(0)
 {
   start_position.x = pos_x;
   start_position.y = pos_y;
+  stay_on_platform = stay_on_plat;
   bbox.set_size(31.8, 31.8);
   sprite = sprite_manager->create("images/creatures/snowsnail/snowsnail.sprite");
   set_direction = true;
@@ -54,6 +57,7 @@ SnowSnail::write(lisp::Writer& writer)
 
   writer.write_float("x", start_position.x);
   writer.write_float("y", start_position.y);
+  if (stay_on_platform) writer.write_bool("stay-on-platform", true);
 
   writer.end_list("snowsnail");
 }
@@ -77,6 +81,13 @@ SnowSnail::active_update(float elapsed_time)
     physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
     sprite->set_action(dir == LEFT ? "left" : "right");
   }
+  if(ice_state == ICESTATE_NORMAL && stay_on_platform
+     && may_fall_off_platform())
+  {
+    dir = (dir == LEFT ? RIGHT : LEFT);
+    sprite->set_action(dir == LEFT ? "left" : "right");
+    physic.set_velocity_x(-physic.get_velocity_x());
+  }
   BadGuy::active_update(elapsed_time);
 }
 
index 4a304d3..7364b49 100644 (file)
@@ -26,7 +26,7 @@ class SnowSnail : public BadGuy
 {
 public:
   SnowSnail(const lisp::Lisp& reader);
-  SnowSnail(float pos_x, float pos_y, Direction d);
+  SnowSnail(float pos_x, float pos_y, Direction d, bool stay_on_plat);
 
   void activate();
   void write(lisp::Writer& writer);
@@ -48,6 +48,7 @@ private:
   Timer flat_timer;
   int squishcount;
   bool set_direction;
+  bool stay_on_platform;
   Direction initial_direction;  
 };
 
index 7dbe450..81e94dc 100644 (file)
@@ -27,6 +27,8 @@ Spiky::Spiky(const lisp::Lisp& reader)
 {
   reader.get("x", start_position.x);
   reader.get("y", start_position.y);
+  stay_on_platform = false;
+  reader.get("stay-on-platform", stay_on_platform);
   bbox.set_size(31.8, 31.8);
   sprite = sprite_manager->create("images/creatures/spiky/spiky.sprite");
 }
@@ -38,6 +40,7 @@ Spiky::write(lisp::Writer& writer)
 
   writer.write_float("x", start_position.x);
   writer.write_float("y", start_position.y);
+  if (stay_on_platform) writer.write_bool("stay-on-platform", true);
 
   writer.end_list("spiky");
 }
@@ -49,6 +52,17 @@ Spiky::activate()
   sprite->set_action(dir == LEFT ? "left" : "right");
 }
 
+void
+Spiky::active_update(float elapsed_time)
+{
+  if (stay_on_platform && may_fall_off_platform())
+  {
+    dir = (dir == LEFT ? RIGHT : LEFT);
+    sprite->set_action(dir == LEFT ? "left" : "right");
+    physic.set_velocity_x(-physic.get_velocity_x());
+  }
+}
+
 HitResponse
 Spiky::collision_solid(GameObject& , const CollisionHit& hit)
 {
index 579df98..fc04ffb 100644 (file)
@@ -29,8 +29,11 @@ public:
 
   void activate();
   void write(lisp::Writer& writer);
+  void active_update(float elapsed_time);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
+private:
+  bool stay_on_platform;
 };
 
 #endif
index 7c77d26..0170230 100644 (file)
@@ -28,6 +28,8 @@ SSpiky::SSpiky(const lisp::Lisp& reader)
 {
   reader.get("x", start_position.x);
   reader.get("y", start_position.y);
+  stay_on_platform = false;
+  reader.get("stay-on-platform", stay_on_platform);
   bbox.set_size(31.8, 31.8);
   sprite = sprite_manager->create("images/creatures/sspiky/sspiky.sprite");
   state = SSPIKY_SLEEPING;
@@ -40,6 +42,7 @@ SSpiky::write(lisp::Writer& writer)
 
   writer.write_float("x", start_position.x);
   writer.write_float("y", start_position.y);
+  if (stay_on_platform) writer.write_bool("stay-on-platform", true);
 
   writer.end_list("sspiky");
 }
@@ -55,6 +58,8 @@ SSpiky::activate()
   sprite->set_action(dir == LEFT ? "sleeping-left" : "sleeping-right");
 }
 
+
+
 HitResponse
 SSpiky::collision_solid(GameObject& , const CollisionHit& hit)
 {
@@ -117,6 +122,12 @@ SSpiky::active_update(float elapsed_time) {
     }
   }
 
+  if (state == SSPIKY_WALKING && stay_on_platform && may_fall_off_platform())
+  {
+    dir = (dir == LEFT ? RIGHT : LEFT);
+    sprite->set_action(dir == LEFT ? "left" : "right");
+    physic.set_velocity_x(-physic.get_velocity_x());
+  }
 }
 
 IMPLEMENT_FACTORY(SSpiky, "sspiky")
index 3a546f6..8aa24b3 100644 (file)
@@ -42,7 +42,8 @@ protected:
     SSPIKY_WALKING
   };
   SSpikyState state;
-  
+private:
+  bool stay_on_platform;  
 };
 
 #endif
diff --git a/src/object/falling_coin.cpp b/src/object/falling_coin.cpp
new file mode 100644 (file)
index 0000000..e6f79a4
--- /dev/null
@@ -0,0 +1,53 @@
+//  $Id: infoblock.cpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
+//
+//  SuperTux
+//  Copyright (C) 2006 Ondrej Hosek <ondra.hosek@gmail.com>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#include <config.h>
+
+#include "falling_coin.hpp"
+#include "player.hpp"
+#include "sprite/sprite_manager.hpp"
+#include "resources.hpp"
+#include "main.hpp"
+
+FallingCoin::FallingCoin(const Vector& start_position, const int vel_x)
+{
+  pos = start_position;
+  sprite = sprite_manager->create("images/objects/coin/coin.sprite");
+  physic.set_velocity_y(800);
+  physic.set_velocity_x(vel_x);
+}
+
+FallingCoin::~FallingCoin()
+{
+  delete sprite;
+}
+
+void
+FallingCoin::draw(DrawingContext& context)
+{
+  sprite->draw(context, pos, LAYER_OBJECTS + 5);
+}
+
+void
+FallingCoin::update(float elapsed_time)
+{
+  pos += physic.get_movement(elapsed_time);
+  if (pos.y > SCREEN_HEIGHT)
+    remove_me();
+}
diff --git a/src/object/falling_coin.hpp b/src/object/falling_coin.hpp
new file mode 100644 (file)
index 0000000..c801902
--- /dev/null
@@ -0,0 +1,43 @@
+//  $Id: infoblock.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
+//
+//  SuperTux
+//  Copyright (C) 2006 Ondrej Hosek <ondra.hosek@gmail.com>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#ifndef __FALLING_COIN_H__
+#define __FALLING_COIN_H__
+
+#include "game_object.hpp"
+#include "math/vector.hpp"
+#include "sprite/sprite.hpp"
+#include "video/drawing_context.hpp"
+#include "physic.hpp"
+
+class FallingCoin : public GameObject
+{
+public:
+  FallingCoin(const Vector& start_position, const int x_vel);
+  ~FallingCoin();
+
+  void draw(DrawingContext& context);
+  void update(float elapsed_time);
+private:
+  Vector  pos;
+  Sprite* sprite;
+  Physic  physic;
+};
+
+#endif
index dcdb852..b0579d2 100644 (file)
@@ -48,6 +48,7 @@
 #include "badguy/badguy.hpp"
 #include "player_status.hpp"
 #include "log.hpp"
+#include "falling_coin.hpp"
 
 static const int TILES_FOR_BUTTJUMP = 3;
 static const float SHOOTING_TIME = .150;
@@ -101,33 +102,6 @@ TuxBodyParts::draw(DrawingContext& context, const Vector& pos, int layer)
     feet->draw(context, pos, layer-2);
 }
 
-FallingCoin::FallingCoin(const Vector& start_position, const int vel_x)
-{
-  pos = start_position;
-  sprite = sprite_manager->create("images/objects/coin/coin.sprite");
-  physic.set_velocity_y(800);
-  physic.set_velocity_x(vel_x);
-}
-
-FallingCoin::~FallingCoin()
-{
-  delete sprite;
-}
-
-void
-FallingCoin::draw(DrawingContext& context)
-{
-  sprite->draw(context, pos, LAYER_OBJECTS + 5);
-}
-
-void
-FallingCoin::update(float elapsed_time)
-{
-  pos += physic.get_movement(elapsed_time);
-  if (pos.y > SCREEN_HEIGHT)
-    remove_me();
-}
-
 Player::Player(PlayerStatus* _player_status)
   : player_status(_player_status), grabbed_object(0)
 {
index cc250cb..09b95dd 100644 (file)
@@ -81,20 +81,6 @@ extern TuxBodyParts* big_tux;
 extern TuxBodyParts* fire_tux;
 extern TuxBodyParts* ice_tux;
 
-class FallingCoin : public GameObject
-{
-public:
-  FallingCoin(const Vector& start_position, const int x_vel);
-  ~FallingCoin();
-
-  void draw(DrawingContext& context);
-  void update(float elapsed_time);
-private:
-  Vector  pos;
-  Sprite* sprite;
-  Physic  physic;
-};
-
 class Player : public MovingObject, public Scripting::Player, public ScriptInterface
 {
 public:
index c4fc951..e6c7429 100644 (file)
@@ -19,6 +19,7 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include <config.h>
 
+#include <stddef.h>
 #include <physfs.h>
 #include "level.hpp"
 #include "sprite/sprite_manager.hpp"