[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/worldobjs teleporter.cxx,1.7,1.8 tele
From: |
torangan |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/worldobjs teleporter.cxx,1.7,1.8 teleporter.hxx,1.10,1.11 |
Date: |
9 Sep 2002 16:13:46 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/worldobjs
In directory dark:/tmp/cvs-serv6312/worldobjs
Modified Files:
teleporter.cxx teleporter.hxx
Log Message:
split teleporter, some cleanup/cosmetic changes
Index: teleporter.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldobjs/teleporter.cxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- teleporter.cxx 5 Sep 2002 11:26:35 -0000 1.7
+++ teleporter.cxx 9 Sep 2002 16:13:44 -0000 1.8
@@ -18,246 +18,59 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <fstream>
+#include "teleporter.hxx"
#include "../world.hxx"
-#include "../pingus_resource.hxx"
#include "../pingu_holder.hxx"
-#include "../xml_helper.hxx"
-#include "../editor/editor_view.hxx"
-#include "teleporter.hxx"
#include "../pingu.hxx"
+#include "../worldobjsdata/teleporter_data.hxx"
-TeleporterData::TeleporterData (const TeleporterData& data) :
WorldObjData(data),
- pos(data.pos),
-
target_pos(data.target_pos)
-{
-}
-
-TeleporterData
-TeleporterData::operator= (const TeleporterData& data)
-{
- if (this == &data)
- return *this;
-
- WorldObjData::operator=(data);
-
- pos = data.pos;
- target_pos = data.target_pos;
-
- return *this;
-}
-
-void
-TeleporterData::write_xml(std::ostream& xml)
-{
- xml << " <worldobj type=\"teleporter\">";
- XMLhelper::write_vector_xml (xml, pos);
- xml << " <target>" << std::endl;
- XMLhelper::write_vector_xml (xml, target_pos);
- xml << " </target>" << std::endl;
- xml << " </worldobj>" << std::endl;
-}
-
-TeleporterData::TeleporterData (xmlDocPtr doc, xmlNodePtr cur)
-{
- cur = cur->children;
-
- while (cur != NULL)
- {
- if (xmlIsBlankNode(cur))
- {
- cur = cur->next;
- continue;
- }
-
- if (strcmp((char*)cur->name, "position") == 0)
- {
- pos = XMLhelper::parse_vector (doc, cur);
- }
- else if (strcmp((char*)cur->name, "target") == 0)
- {
- xmlNodePtr ncur = cur->children;
-
- if (xmlIsBlankNode(ncur)) ncur = ncur->next;
-
- if (ncur != NULL)
- target_pos = XMLhelper::parse_vector (doc, ncur);
- else
- std::cout << "TeleporterData::create (): <target> is empty" <<
std::endl;
- }
- else
- {
- std::cout << "TeleportData::create (): Unhandled " << cur->name <<
std::endl;
- }
-
- cur = cur->next;
- }
-}
-
-WorldObj*
-TeleporterData::create_WorldObj ()
-{
- return new Teleporter (*this);
-}
-
-EditorObjLst
-TeleporterData::create_EditorObj ()
-{
- std::cout << "TeleportData::create_EditorObj () " << std::endl;
- EditorObjLst objs;
-
- EditorTeleporterObj* teleporter = new EditorTeleporterObj (*this);
- EditorTeleporterTargetObj* teleporter_target = new EditorTeleporterTargetObj
(teleporter);
-
- objs.push_back ( (teleporter));
- objs.push_back ( (teleporter_target));
-
- std::cout << "TeleportData::create_EditorObj (): done" << std::endl;
-
- return objs;
-}
-
-/**************/
-/* Teleporter */
-/**************/
-
-Teleporter::Teleporter (const TeleporterData& data)
- : sprite ("teleporter", "worldobjs", 20.0f, Sprite::NONE, Sprite::ONCE),
- target_sprite ("teleportertarget", "worldobjs", 20.0f, Sprite::NONE,
Sprite::ONCE)
-{
- sprite.set_align_center_bottom ();
- target_sprite.set_align_center ();
-
- //FIXME: we need a Sprite::set_frame()
-
- pos = data.pos;
- target_pos = data.target_pos;
-
- std::cout << "Teleporter: pos: " << pos.x << " " << pos.y << " " << pos.z
<< std::endl;
-}
-
-void
-Teleporter::draw (GraphicContext& gc)
-{
- gc.draw (sprite, pos);
- gc.draw (target_sprite, target_pos);
-}
-
-void
-Teleporter::update (float delta)
-{
- sprite.update (delta);
- target_sprite.update (delta);
-
- PinguHolder* holder = world->get_pingu_p();
-
- 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 && (*pingu)->get_y() > pos.y - 52)
- {
- (*pingu)->set_pos (int(target_pos.x), int(target_pos.y));
- sprite.reset ();
- target_sprite.reset ();
- }
- }
-}
-
-/********************/
-/* EditorTeleporter */
-/********************/
-
-EditorTeleporterObj::EditorTeleporterObj (const TeleporterData& data)
- : SpriteEditorObj ("teleporter", "worldobjs", pos)
-{
- sprite.set_align_center_bottom ();
-
- pos = data.pos;
- target_pos = data.target_pos;
-}
-
-EditorObj*
-EditorTeleporterObj::duplicate()
-{
- std::cout << "EditorTeleporterObj::duplicate(): not implemented" <<
std::endl;
- return 0;
-}
-
-EditorObjLst
-EditorTeleporterObj::create (const TeleporterData& data)
-{
- EditorObjLst objs;
-
- EditorTeleporterObj* teleporter=new EditorTeleporterObj (data);
- EditorTeleporterTargetObj* teleporter_target=new EditorTeleporterTargetObj
(teleporter);
-
- objs.push_back (teleporter);
- objs.push_back (teleporter_target);
-
- return objs;
-}
+namespace WorldObjs {
-EditorObjLst
-EditorTeleporterObj::create (const CL_Vector& pos)
-{
- TeleporterData data;
+ Teleporter::Teleporter (WorldObjsData::TeleporterData* data_)
+ : data(new WorldObjsData::TeleporterData(*data_))
- std::cout << "EditorTeleporterObj: creating..." << std::endl;
+ {
+ data->sprite.set_align_center_bottom();
+ data->target_sprite.set_align_center();
- data.pos = pos;
- data.target_pos.x = pos.x + 50;
- data.target_pos.y = pos.y + 50;
+ //FIXME: we need a Sprite::set_frame()
- return data.create_EditorObj ();
-}
+ std::cout << "Teleporter: pos: " << data->pos.x << " " << data->pos.y <<
" " << data->pos.z << std::endl;
+ }
-void
-EditorTeleporterObj::draw (EditorView * view)
-{
- //std::cout << "Drawing line" << std::endl;
- view->draw_line (int(pos.x),
- int(pos.y),
- int(target_pos.x),
- int(target_pos.y),
- 0.0, 1.0, 0.0, 0.5);
- SpriteEditorObj::draw (view);
-}
+ float
+ Teleporter::get_z_pos () const
+ {
+ return data->pos.z;
+ }
-void
-EditorTeleporterObj::save_xml (std::ostream& xml)
-{
- // Before we write down the xml stuff, we need to get the positions
- // of the objects
- // TeleporterData::target_pos = target->get_position ();
- this->write_xml (xml);
-}
+ void
+ Teleporter::draw (GraphicContext& gc)
+ {
+ gc.draw(data->sprite, data->pos);
+ gc.draw(data->target_sprite, data->target_pos);
+ }
-std::string
-EditorTeleporterObj::status_line()
-{
- char str[128];
- snprintf (str, 128, "Teleporter - %f %f %f",
- pos.x, pos.y, pos.z);
- return str;
-}
+ void
+ Teleporter::update (float delta)
+ {
+ data->sprite.update(delta);
+ data->target_sprite.update(delta);
-/*****************************/
-/* EditorTeleporterTargetObj */
-/*****************************/
+ PinguHolder* holder = world->get_pingu_p();
-EditorTeleporterTargetObj::EditorTeleporterTargetObj (EditorTeleporterObj*
arg_teleporter)
- : SpriteEditorObj ("teleporter2", "worldobjs",
arg_teleporter->get_target_pos_ref ()),
- teleporter (arg_teleporter)
-{
- sprite.set_align_center();
-}
+ for (PinguIter pingu = holder->begin (); pingu != holder->end (); ++pingu)
+ {
+ if ( (*pingu)->get_x() > data->pos.x - 3 && (*pingu)->get_x() <
data->pos.x + 3
+ && (*pingu)->get_y() > data->pos.y - 52 && (*pingu)->get_y() <
data->pos.y)
+ {
+ (*pingu)->set_pos (static_cast<int>(data->target_pos.x),
static_cast<int>(data->target_pos.y));
+ data->sprite.reset ();
+ data->target_sprite.reset ();
+ }
+ }
+ }
-std::string
-EditorTeleporterTargetObj::status_line()
-{
- char str[128];
- snprintf (str, 128, "TeleporterTarget - %f %f %f",
- pos_ref.x, pos_ref.y, pos_ref.z);
- return str;
}
/* EOF */
Index: teleporter.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldobjs/teleporter.hxx,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- teleporter.hxx 6 Sep 2002 17:33:29 -0000 1.10
+++ teleporter.hxx 9 Sep 2002 16:13:44 -0000 1.11
@@ -21,109 +21,32 @@
#define HEADER_PINGUS_WORLDOBJS_TELEPORTER_HXX
#include "../worldobj.hxx"
-#include "../worldobj_data.hxx"
-#include "../editor/sprite_editorobj.hxx"
-#include "../libxmlfwd.hxx"
-
-class EditorTeleporterObj;
-
-class TeleporterData : public WorldObjData
-{
-public:
- CL_Vector pos;
- CL_Vector target_pos;
-
- TeleporterData () {}
- TeleporterData (xmlDocPtr doc, xmlNodePtr cur);
-
- TeleporterData (const TeleporterData& data);
- TeleporterData operator= (const TeleporterData& data);
-
- /** Write the content of this object formatted as xml to the given
- stream */
- void write_xml(std::ostream& xml);
-
- /** Create an WorldObj from the given data object */
- WorldObj* create_WorldObj ();
- /** Create an EditorObj from the given data object */
- EditorObjLst create_EditorObj ();
-};
-
-class Teleporter : private TeleporterData,
- public WorldObj
-{
-private:
- Sprite sprite;
- Sprite target_sprite;
-
-public:
- Teleporter (const TeleporterData& data);
-
- int get_z_pos() { return 0; }
- void draw (GraphicContext& gc);
- void update(float delta);
- float get_z_pos() const { return (int) pos.z; }
-
-private:
- Teleporter (const Teleporter&);
- Teleporter operator= (const Teleporter&);
-};
-
-class EditorTeleporterTargetObj;
-
-class EditorTeleporterObj : public SpriteEditorObj,
- public TeleporterData
-{
-private:
- EditorTeleporterTargetObj* target;
-
-public:
- EditorTeleporterObj (const TeleporterData& data);
-
- CL_Vector& get_target_pos_ref () { return target_pos; }
-
- EditorObj* duplicate();
- static EditorObjLst create (const TeleporterData& data);
-
- void write_xml(std::ostream& xml) { TeleporterData::write_xml(xml); }
+namespace WorldObjsData {
+ class TeleporterData;
+}
- /** Create this object (and child objects) with reasonable defaults
- for the editor */
- static EditorObjLst create (const CL_Vector& pos);
+namespace WorldObjs {
- void draw (EditorView * view);
- void save_xml (std::ostream& xml);
- std::string status_line();
-
-private:
- EditorTeleporterObj (const EditorTeleporterObj&);
- EditorTeleporterObj operator= (const EditorTeleporterObj&);
-};
+ class Teleporter : public WorldObj
+ {
+ private:
+ WorldObjsData::TeleporterData* const data;
+ public:
+ Teleporter (WorldObjsData::TeleporterData* data_);
-/** A pseudo object to represent the teleporter target; all the
- data itself is handled inside the EditorTeleporterObj, but we
- need this helper object to be able to show and move the
- teleporter target inside the editor */
-class EditorTeleporterTargetObj : public SpriteEditorObj
-{
-private:
- EditorTeleporterObj* teleporter;
+ int get_z_pos () { return 0; }
+
+ void draw (GraphicContext& gc);
+ void update (float delta);
+ float get_z_pos () const;
-public:
- /// Basic constructor
- EditorTeleporterTargetObj (EditorTeleporterObj* obj);
-
- EditorObj* duplicate() { return teleporter->duplicate (); }
+ private:
+ Teleporter (const Teleporter&);
+ Teleporter operator= (const Teleporter&);
+ };
- /// The saving will be done in EditorTeleporterObj::save_xml
- void write_xml (std::ostream& xml) { UNUSED_ARG(xml); }
- std::string status_line();
-
-private:
- EditorTeleporterTargetObj (const EditorTeleporterTargetObj&);
- EditorTeleporterTargetObj operator= (const EditorTeleporterTargetObj&);
-};
+}
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/worldobjs teleporter.cxx,1.7,1.8 teleporter.hxx,1.10,1.11,
torangan <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src/editor editorobj.hxx,1.13,1.14 object_selector.cxx,1.11,1.12
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src/editorobjs Makefile.am,1.1,1.2 bumper_obj.cxx,1.3,1.4 bumper_obj.hxx,1.2,1.3 fake_exit_obj.cxx,1.3,1.4 fake_exit_obj.hxx,1.2,1.3 guillotine_obj.cxx,1.3,1.4 guillotine_obj.hxx,1.2,1.3 hammer_obj.cxx,1.3,1.4 hammer_obj.hxx,1.2,1.3 laser_exit_obj.cxx,1.3,1.4 laser_exit_obj.hxx,1.2,1.3 smasher_obj.cxx,1.3,1.4 smasher_obj.hxx,1.2,1.3 spike_obj.cxx,1.3,1.4 spike_obj.hxx,1.2,1.3
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src/editor editorobj.hxx,1.13,1.14 object_selector.cxx,1.11,1.12
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src/editorobjs Makefile.am,1.1,1.2 bumper_obj.cxx,1.3,1.4 bumper_obj.hxx,1.2,1.3 fake_exit_obj.cxx,1.3,1.4 fake_exit_obj.hxx,1.2,1.3 guillotine_obj.cxx,1.3,1.4 guillotine_obj.hxx,1.2,1.3 hammer_obj.cxx,1.3,1.4 hammer_obj.hxx,1.2,1.3 laser_exit_obj.cxx,1.3,1.4 laser_exit_obj.hxx,1.2,1.3 smasher_obj.cxx,1.3,1.4 smasher_obj.hxx,1.2,1.3 spike_obj.cxx,1.3,1.4 spike_obj.hxx,1.2,1.3
- Index(es):