pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r2908 - in branches/pingus_sdl/src: . worldobjs


From: grumbel at BerliOS
Subject: [Pingus-CVS] r2908 - in branches/pingus_sdl/src: . worldobjs
Date: Tue, 14 Aug 2007 19:46:59 +0200

Author: grumbel
Date: 2007-08-14 19:46:58 +0200 (Tue, 14 Aug 2007)
New Revision: 2908

Added:
   branches/pingus_sdl/src/worldobjs/teleporter_target.cpp
   branches/pingus_sdl/src/worldobjs/teleporter_target.hpp
Modified:
   branches/pingus_sdl/src/SConscript
   branches/pingus_sdl/src/world.cpp
   branches/pingus_sdl/src/world.hpp
   branches/pingus_sdl/src/worldobj.cpp
   branches/pingus_sdl/src/worldobj.hpp
   branches/pingus_sdl/src/worldobj_factory.cpp
   branches/pingus_sdl/src/worldobjs/exit.hpp
   branches/pingus_sdl/src/worldobjs/teleporter.cpp
   branches/pingus_sdl/src/worldobjs/teleporter.hpp
Log:
- changed the way teleporter targets are handled

Modified: branches/pingus_sdl/src/SConscript
===================================================================
--- branches/pingus_sdl/src/SConscript  2007-08-14 16:45:18 UTC (rev 2907)
+++ branches/pingus_sdl/src/SConscript  2007-08-14 17:46:58 UTC (rev 2908)
@@ -300,7 +300,8 @@
 'worldobjs/starfield_background_stars.cpp', 
 'worldobjs/surface_background.cpp', 
 'worldobjs/switch_door.cpp', 
-'worldobjs/teleporter.cpp', 
+'worldobjs/teleporter.cpp',
+'worldobjs/teleporter_target.cpp', 
 'worldobjs/thunderstorm_background.cpp', 
 'worldobjs/woodthing.cpp',
 

Modified: branches/pingus_sdl/src/world.cpp
===================================================================
--- branches/pingus_sdl/src/world.cpp   2007-08-14 16:45:18 UTC (rev 2907)
+++ branches/pingus_sdl/src/world.cpp   2007-08-14 17:46:58 UTC (rev 2908)
@@ -300,4 +300,15 @@
   colmap->remove(mask, x, y);
 }
 
+WorldObj*
+World::get_worldobj(const std::string& id)
+{
+  for(WorldObjIter obj = world_obj.begin(); obj != world_obj.end(); ++obj)
+    {
+      if ((*obj)->get_id() == id) 
+        return *obj;
+    }
+  return 0;
+}
+
 /* EOF */

Modified: branches/pingus_sdl/src/world.hpp
===================================================================
--- branches/pingus_sdl/src/world.hpp   2007-08-14 16:45:18 UTC (rev 2907)
+++ branches/pingus_sdl/src/world.hpp   2007-08-14 17:46:58 UTC (rev 2908)
@@ -135,6 +135,8 @@
   void remove(int x, int y);
   void remove(const CollisionMask&, int x, int y);
 
+  WorldObj* get_worldobj(const std::string& id);
+
   /** @return A pointer to the worlds pingu particle holder */
   Particles::PinguParticleHolder* get_pingu_particle_holder () { return 
pingu_particle_holder; }
 

Modified: branches/pingus_sdl/src/worldobj.cpp
===================================================================
--- branches/pingus_sdl/src/worldobj.cpp        2007-08-14 16:45:18 UTC (rev 
2907)
+++ branches/pingus_sdl/src/worldobj.cpp        2007-08-14 17:46:58 UTC (rev 
2908)
@@ -32,6 +32,11 @@
   world = arg_world;
 }
 
+WorldObj::WorldObj(const FileReader& reader)
+{
+  reader.read_string("id", id);
+}
+
 WorldObj::WorldObj()
 {
   // z_pos = 0;

Modified: branches/pingus_sdl/src/worldobj.hpp
===================================================================
--- branches/pingus_sdl/src/worldobj.hpp        2007-08-14 16:45:18 UTC (rev 
2907)
+++ branches/pingus_sdl/src/worldobj.hpp        2007-08-14 17:46:58 UTC (rev 
2908)
@@ -25,6 +25,7 @@
 #include "sprite.hpp"
 #include "collision_mask.hpp"
 
+class FileReader;
 class SceneContext;
 class SmallMap;
 class World;
@@ -39,7 +40,7 @@
 protected:
   /** The World all WorldObjects live in. */
   static World*  world;
-
+  
 public:
   /** Set the world pointer for all world objects */
   static void   set_world(World*);
@@ -47,9 +48,13 @@
   /** Return the current active world */
   static World* get_world () { return world; }
 
+private:
+  std::string id;
+
 public:
   /** Creates a new WorldObj*/
   WorldObj ();
+  WorldObj(const FileReader& reader);
 
   WorldObj (const WorldObj&)       { }
   WorldObj& operator= (const WorldObj&) { return *this; }
@@ -57,6 +62,8 @@
   /** Destroys a world object */
   virtual ~WorldObj ();
 
+  std::string get_id() const { return id; }
+
   /** Returns the $z$-position of this object. */
   virtual float get_z_pos () const =0;
 

Modified: branches/pingus_sdl/src/worldobj_factory.cpp
===================================================================
--- branches/pingus_sdl/src/worldobj_factory.cpp        2007-08-14 16:45:18 UTC 
(rev 2907)
+++ branches/pingus_sdl/src/worldobj_factory.cpp        2007-08-14 17:46:58 UTC 
(rev 2908)
@@ -42,6 +42,7 @@
 #include "worldobjs/surface_background.hpp"
 #include "worldobjs/switch_door.hpp"
 #include "worldobjs/teleporter.hpp"
+#include "worldobjs/teleporter_target.hpp"
 #include "worldobjs/thunderstorm_background.hpp"
 #include "worldobjs/woodthing.hpp"
 
@@ -117,6 +118,7 @@
       new WorldObjFactoryImpl<IceBlock>("iceblock");
       new WorldObjFactoryImpl<ConveyorBelt>("conveyorbelt");
       new WorldObjFactoryImpl<Teleporter>("teleporter");
+      new WorldObjFactoryImpl<TeleporterTarget>("teleporter-target");
 
       // Backgrounds
       new WorldObjFactoryImpl<SurfaceBackground>("surface-background");

Modified: branches/pingus_sdl/src/worldobjs/exit.hpp
===================================================================
--- branches/pingus_sdl/src/worldobjs/exit.hpp  2007-08-14 16:45:18 UTC (rev 
2907)
+++ branches/pingus_sdl/src/worldobjs/exit.hpp  2007-08-14 17:46:58 UTC (rev 
2908)
@@ -23,10 +23,6 @@
 #include "../res_descriptor.hpp"
 #include "../worldobj.hpp"
 
-namespace WorldObjsData {
-class ExitData;
-}
-
 namespace WorldObjs {
 
 class Exit : public WorldObj

Modified: branches/pingus_sdl/src/worldobjs/teleporter.cpp
===================================================================
--- branches/pingus_sdl/src/worldobjs/teleporter.cpp    2007-08-14 16:45:18 UTC 
(rev 2907)
+++ branches/pingus_sdl/src/worldobjs/teleporter.cpp    2007-08-14 17:46:58 UTC 
(rev 2908)
@@ -23,19 +23,16 @@
 #include "../pingu_holder.hpp"
 #include "../world.hpp"
 #include "../resource.hpp"
+#include "teleporter_target.hpp"
 #include "teleporter.hpp"
 
 namespace WorldObjs {
 
 Teleporter::Teleporter(const FileReader& reader)
-  : sprite(Resource::load_sprite("worldobjs/teleporter")),
-    target_sprite(Resource::load_sprite("worldobjs/teleportertarget"))
+  : sprite(Resource::load_sprite("worldobjs/teleporter"))
 {
-  FileReader subreader;
-
-  reader.read_vector   ("position", pos);
-  reader.read_section  ("target",   subreader);
-  subreader.read_vector("position", target_pos);
+  reader.read_vector("position", pos);
+  reader.read_string("target-id", target_id);
 }
 
 float
@@ -48,26 +45,42 @@
 Teleporter::draw (SceneContext& gc)
 {
   gc.color().draw(sprite, pos);
-  gc.color().draw(target_sprite, target_pos);
 }
 
 void
+Teleporter::on_startup()
+{
+  if (target_id.empty())
+    {
+      std::cout << "Teleporter: target-id is empty" << std::endl;
+    }
+  else
+    {
+      // FIXME: find the target
+      target = dynamic_cast<TeleporterTarget*>(world->get_worldobj(target_id));
+      if (!target)
+        std::cout << "Teleporter: Couldn't find matching target-id or object 
isn't a TeleporterTarget" << std::endl;
+    }
+}
+
+void
 Teleporter::update ()
 {
   sprite.update();
-  target_sprite.update();
 
-  PinguHolder* holder = world->get_pingus();
-
-  for (PinguIter pingu = holder->begin (); pingu != holder->end (); ++pingu)
+  if (target)
     {
-      if (   (*pingu)->get_x() > pos.x - 3  && (*pingu)->get_x() < pos.x + 3
-            && (*pingu)->get_y() > pos.y - 52 && (*pingu)->get_y() < pos.y)
-       {
-         (*pingu)->set_pos (target_pos.x, target_pos.y);
-         sprite.restart();
-          target_sprite.restart();
-       }
+      PinguHolder* holder = world->get_pingus();
+      for (PinguIter pingu = holder->begin (); pingu != holder->end (); 
++pingu)
+        {
+          if (   (*pingu)->get_x() > pos.x - 3  && (*pingu)->get_x() < pos.x + 
3
+                 && (*pingu)->get_y() > pos.y - 52 && (*pingu)->get_y() < 
pos.y)
+            {
+              (*pingu)->set_pos(target->get_pos().x, target->get_pos().y);
+              target->teleporter_used();
+              sprite.restart();
+            }
+        }
     }
 }
 

Modified: branches/pingus_sdl/src/worldobjs/teleporter.hpp
===================================================================
--- branches/pingus_sdl/src/worldobjs/teleporter.hpp    2007-08-14 16:45:18 UTC 
(rev 2907)
+++ branches/pingus_sdl/src/worldobjs/teleporter.hpp    2007-08-14 17:46:58 UTC 
(rev 2908)
@@ -22,27 +22,25 @@
 
 #include "../worldobj.hpp"
 
-namespace WorldObjsData {
-class TeleporterData;
-}
-
 namespace WorldObjs {
 
+class TeleporterTarget;
+
 class Teleporter : public WorldObj
 {
 private:
   Vector3f pos;
-  Vector3f target_pos;
-
   Sprite sprite;
-  Sprite target_sprite;
+  std::string target_id;
+  TeleporterTarget* target;
 
 public:
   Teleporter(const FileReader& reader);
 
-  void  draw (SceneContext& gc);
-  void  update ();
-       float get_z_pos () const;
+  void  draw(SceneContext& gc);
+  void  update();
+  float get_z_pos() const;
+  void  on_startup();
 
 private:
   Teleporter (const Teleporter&);

Added: branches/pingus_sdl/src/worldobjs/teleporter_target.cpp
===================================================================
--- branches/pingus_sdl/src/worldobjs/teleporter_target.cpp     2007-08-14 
16:45:18 UTC (rev 2907)
+++ branches/pingus_sdl/src/worldobjs/teleporter_target.cpp     2007-08-14 
17:46:58 UTC (rev 2908)
@@ -0,0 +1,63 @@
+//  $Id$
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
+//
+//  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 <iostream>
+#include "../display/scene_context.hpp"
+#include "../pingu.hpp"
+#include "../pingu_holder.hpp"
+#include "../world.hpp"
+#include "../resource.hpp"
+#include "teleporter_target.hpp"
+
+namespace WorldObjs {
+
+TeleporterTarget::TeleporterTarget(const FileReader& reader)
+  : WorldObj(reader),
+    sprite(Resource::load_sprite("worldobjs/teleportertarget"))
+{
+  reader.read_vector("position", pos);
+}
+
+float
+TeleporterTarget::get_z_pos () const
+{
+  return pos.z;
+}
+
+void
+TeleporterTarget::draw (SceneContext& gc)
+{
+  gc.color().draw(sprite, pos);
+}
+
+void
+TeleporterTarget::update ()
+{
+  sprite.update();
+}
+
+void
+TeleporterTarget::teleporter_used()
+{
+  sprite.restart();
+}
+
+} // namespace WorldObjs
+
+/* EOF */


Property changes on: branches/pingus_sdl/src/worldobjs/teleporter_target.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: branches/pingus_sdl/src/worldobjs/teleporter_target.hpp
===================================================================
--- branches/pingus_sdl/src/worldobjs/teleporter_target.hpp     2007-08-14 
16:45:18 UTC (rev 2907)
+++ branches/pingus_sdl/src/worldobjs/teleporter_target.hpp     2007-08-14 
17:46:58 UTC (rev 2908)
@@ -0,0 +1,50 @@
+//  $Id$
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
+//
+//  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 HEADER_PINGUS_WORLDOBJS_TELEPORTER_TARGET_HXX
+#define HEADER_PINGUS_WORLDOBJS_TELEPORTER_TARGET_HXX
+
+#include "../worldobj.hpp"
+
+namespace WorldObjs {
+
+class TeleporterTarget : public WorldObj
+{
+private:
+  Vector3f pos;
+  Sprite   sprite;
+
+public:
+  TeleporterTarget(const FileReader& reader);
+
+  void  draw (SceneContext& gc);
+  void  update ();
+  float get_z_pos () const;
+  Vector3f get_pos() const { return pos; }
+  void  teleporter_used();
+private:
+  TeleporterTarget (const TeleporterTarget&);
+  TeleporterTarget& operator= (const TeleporterTarget&);
+};
+
+} // namespace WorldObjs
+
+#endif
+
+/* EOF */


Property changes on: branches/pingus_sdl/src/worldobjs/teleporter_target.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native





reply via email to

[Prev in Thread] Current Thread [Next in Thread]