[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/worldobjs switch_door.cxx,1.13,1.14 s
From: |
torangan |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/worldobjs switch_door.cxx,1.13,1.14 switch_door.hxx,1.10,1.11 |
Date: |
11 Sep 2002 15:27:21 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/worldobjs
In directory dark:/tmp/cvs-serv15619/worldobjs
Modified Files:
switch_door.cxx switch_door.hxx
Log Message:
splitted SwitchDoor
Index: switch_door.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldobjs/switch_door.cxx,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- switch_door.cxx 11 Sep 2002 12:45:59 -0000 1.13
+++ switch_door.cxx 11 Sep 2002 15:27:19 -0000 1.14
@@ -21,176 +21,50 @@
#include "../col_map.hxx"
#include "../world.hxx"
#include "../pingu_holder.hxx"
-#include "../pingus_resource.hxx"
-#include "../editor/editor_view.hxx"
#include "../xml_helper.hxx"
-#include "switch_door.hxx"
#include "../pingu.hxx"
+#include "../worldobjsdata/switch_door_data.hxx"
+#include "switch_door.hxx"
-namespace WorldObjsData {
-
-SwitchDoorData::SwitchDoorData () : door_height(10)
-{
-}
-
-SwitchDoorData::SwitchDoorData (xmlDocPtr doc, xmlNodePtr cur)
-{
- cur = cur->children;
-
- while (cur)
- {
- if (xmlIsBlankNode(cur)) {
- cur = cur->next;
- continue;
- }
-
- if (XMLhelper::equal_str(cur->name, "switch"))
- {
- xmlNodePtr subcur = cur->children;
-
- while (subcur)
- {
- if (xmlIsBlankNode(subcur)) {
- subcur = subcur->next;
- continue;
- }
-
- if (XMLhelper::equal_str(subcur->name, "position"))
- {
- switch_pos = XMLhelper::parse_vector (doc, subcur);
- }
- else
- std::cout << "SwitchDoorData: switch: Unhandled " <<
subcur->name << std::endl;
-
- subcur = subcur->next;
- }
- }
- else if (XMLhelper::equal_str(cur->name, "door"))
- {
- xmlNodePtr subcur = cur->children;
-
- while (subcur)
- {
- if (xmlIsBlankNode(subcur)) {
- subcur = subcur->next;
- continue;
- }
-
- if (XMLhelper::equal_str(subcur->name, "position"))
- {
- door_pos = XMLhelper::parse_vector (doc, subcur);
- }
- else if (XMLhelper::equal_str(subcur->name, "height"))
- {
- door_height = XMLhelper::parse_int (doc, subcur);
- }
- else
- std::cout << "SwitchDoor::door: Unhandled " << subcur->name <<
std::endl;
-
- subcur = subcur->next;
- }
- }
- cur = cur->next;
- }
-}
-
-SwitchDoorData::SwitchDoorData (const SwitchDoorData& old) : WorldObjData(old),
-
door_pos(old.door_pos),
-
switch_pos(old.switch_pos),
-
door_height(old.door_height)
-{
-}
-
-SwitchDoorData
-SwitchDoorData::operator= (const SwitchDoorData& old)
-{
- if (this == &old)
- return *this;
-
- WorldObjData::operator=(old);
-
- door_pos = old.door_pos;
- switch_pos = old.switch_pos;
- door_height = old.door_height;
-
- return *this;
-}
-
-void
-SwitchDoorData::write_xml(std::ostream& xml)
-{
- xml << " <worldobj type=\"switchdoor\">\n";
- xml << " <switch>\n";
- XMLhelper::write_vector_xml (xml, switch_pos);
- xml << " </switch>\n"
- << " <door>\n"
- << " <height>\n" << door_height << "</height>\n";
- XMLhelper::write_vector_xml (xml, door_pos);
- xml << " </door>\n"
- << " </worldobj>\n" << std::endl;
-}
-
-/** Create an WorldObj from the given data object */
-WorldObj*
-SwitchDoorData::create_WorldObj ()
-{
- return new WorldObjs::SwitchDoor (*this);
-}
-
-/** Create an EditorObj from the given data object */
-EditorObjLst
-SwitchDoorData::create_EditorObj ()
-{
- EditorObjLst lst;
- EditorObjs::EditorSwitchDoorObj* obj = new EditorObjs::EditorSwitchDoorObj
(*this);
- lst.push_back(obj);
- lst.push_back(new EditorObjs::EditorSwitchDoorSwitchObj (obj));
- return lst;
-}
-
-} // namespace WorldObjsData
-
-////////////////
-// SwitchDoor //
-////////////////
namespace WorldObjs {
-SwitchDoor::SwitchDoor (const SwitchDoorData& data)
- : SwitchDoorData (data)
+SwitchDoor::SwitchDoor (WorldObjsData::SwitchDoorData* data_)
+ : is_opening(false),
+ current_door_height(data->door_height),
+ data(new WorldObjsData::SwitchDoorData(*data_))
{
- door_box = PingusResource::load_surface("switchdoor_box", "worldobjs");
- door_tile = PingusResource::load_surface("switchdoor_tile", "worldobjs");
- door_tile_cmap = PingusResource::load_surface("switchdoor_tile_cmap",
"worldobjs");
- switch_sur = PingusResource::load_surface("switchdoor_switch", "worldobjs");
- is_opening = false;
-
- current_door_height = door_height;
}
void
-SwitchDoor::draw_colmap()
+SwitchDoor::draw_colmap ()
{
- world->get_colmap ()->put (door_box, int(door_pos.x), int(door_pos.y),
GroundpieceData::GP_SOLID);
- for (int i=0; i < door_height; ++i)
- world->get_colmap ()->put (door_tile_cmap,
- int(door_pos.x),
- int(door_pos.y) + i * door_tile.get_height () +
door_box.get_height (),
- GroundpieceData::GP_SOLID);
+ world->get_colmap()->put(data->door_box,
+ static_cast<int>(data->door_pos.x),
+ static_cast<int>(data->door_pos.y),
+ GroundpieceData::GP_SOLID);
+
+ for (int i=0; i < data->door_height; ++i)
+ world->get_colmap()->put(data->door_tile_cmap,
+ static_cast<int>(data->door_pos.x),
+ static_cast<int>(data->door_pos.y) + i *
data->door_tile.get_height()
+ +
data->door_box.get_height(),
+ GroundpieceData::GP_SOLID);
}
void
SwitchDoor::draw (GraphicContext& gc)
{
- gc.draw (door_box, door_pos);
+ gc.draw (data->door_box, data->door_pos);
for (int i=0; i < current_door_height; ++i)
- gc.draw (door_tile,
- int(door_pos.x),
- int(door_pos.y) + i * door_tile.get_height () +
door_box.get_height ());
- gc.draw (switch_sur, switch_pos);
+ gc.draw(data->door_tile,
+ static_cast<int>(data->door_pos.x),
+ static_cast<int>(data->door_pos.y) + i *
data->door_tile.get_height()
+ + data->door_box.get_height());
+ gc.draw(data->switch_sur, data->switch_pos);
}
void
-SwitchDoor::update(float /*delta*/)
+SwitchDoor::update (float /*delta*/)
{
if (current_door_height > 0)
{
@@ -201,10 +75,10 @@
for (PinguIter pingu = holder->begin (); pingu != holder->end ();
++pingu)
{
- if ((*pingu)->get_x() > switch_pos.x
- && (*pingu)->get_x() < switch_pos.x + (int)
switch_sur.get_width ()
- && (*pingu)->get_y() > switch_pos.y
- && (*pingu)->get_y() < switch_pos.y + (int)
switch_sur.get_height ())
+ if ((*pingu)->get_x() > data->switch_pos.x
+ && (*pingu)->get_x() < data->switch_pos.x +
static_cast<int>(data->switch_sur.get_width())
+ && (*pingu)->get_y() > data->switch_pos.y
+ && (*pingu)->get_y() < data->switch_pos.y +
static_cast<int>(data->switch_sur.get_height()))
{
is_opening = true;
}
@@ -213,132 +87,27 @@
else
{
// Open the door
- current_door_height -= 1;
+ --current_door_height;
// If the door is opend enough, so that a pingus fits under
// it, we remove the door from the colmap
- if (current_door_height + 10 < door_height)
+ if (current_door_height + 10 < data->door_height)
{
- world->get_colmap ()->put (door_box, int(door_pos.x),
int(door_pos.y), GroundpieceData::GP_NOTHING);
- for (int i=0; i < door_height; ++i)
- world->get_colmap ()->put (door_tile_cmap,
- int(door_pos.x),
- int(door_pos.y) + i *
door_tile.get_height () + door_box.get_height (),
- GroundpieceData::GP_NOTHING);
+ world->get_colmap()->put(data->door_box,
+ static_cast<int>(data->door_pos.x),
+ static_cast<int>(data->door_pos.y),
+ GroundpieceData::GP_NOTHING);
+ for (int i=0; i < data->door_height; ++i)
+ world->get_colmap()->put(data->door_tile_cmap,
+ static_cast<int>(data->door_pos.x),
+ static_cast<int>(data->door_pos.y) + i
* data->door_tile.get_height()
+ +
data->door_box.get_height(),
+ GroundpieceData::GP_NOTHING);
}
}
}
}
} // namespace WorldObjs
-
-///////////////////////////////
-// EditorSwitchDoorSwitchObj //
-///////////////////////////////
-
-namespace EditorObjs {
-
-EditorSwitchDoorSwitchObj::EditorSwitchDoorSwitchObj (EditorSwitchDoorObj*
data)
- : SpriteEditorObj ("switchdoor_switch", "worldobjs"),
- door (data)
-{
- pos_ref = &door->switch_pos;
-}
-
-std::string
-EditorSwitchDoorSwitchObj::status_line()
-{
- return "--- EditorSwitchDoorSwitchObj ---";
-}
-
-EditorObj*
-EditorSwitchDoorSwitchObj::duplicate()
-{
- return door->duplicate ();
-}
-
-/////////////////////////
-// EditorSwitchDoorObj //
-/////////////////////////
-
-EditorSwitchDoorObj::EditorSwitchDoorObj (const SwitchDoorData& data)
- : SwitchDoorData (data)
-{
- door_box = PingusResource::load_surface("switchdoor_box", "worldobjs");
- door_tile = PingusResource::load_surface("switchdoor_tile", "worldobjs");
-}
-
-EditorObj*
-EditorSwitchDoorObj::duplicate()
-{
- std::cout << "EditorSwitchDoorObj::duplicate(): not implemented" <<
std::endl;
- return 0;
-}
-
-/** Create this object (and child objects) with resonable defaults
- for the editor */
-EditorObjLst
-EditorSwitchDoorObj::create (const CL_Vector& pos)
-{
- SwitchDoorData data;
-
- data.door_pos = pos;
- data.switch_pos = pos;
- data.door_height = 15;
-
- return data.create_EditorObj ();
-}
-
-void
-EditorSwitchDoorObj::save_xml (std::ostream& xml)
-{
- write_xml (xml);
-}
-
-std::string
-EditorSwitchDoorObj::status_line()
-{
- char str[128];
- snprintf (str, 128, "SwitchDoor - (%f %f %f)",
- door_pos.x, door_pos.y, door_pos.z);
- return str;
-}
-
-void
-EditorSwitchDoorObj::draw (EditorNS::EditorView * view)
-{
- view->draw_line (door_pos, switch_pos, 1.0, 0.0, 0.0);
-
- view->draw (door_box, int(door_pos.x), int(door_pos.y));
-
- for (int i = 0; i < door_height; ++i)
- {
- view->draw (door_tile,
- int(door_pos.x),
- int(door_pos.y + (i * door_tile.get_height ())
- + door_box.get_height ()));
- }
-}
-
-void
-EditorSwitchDoorObj::make_larger ()
-{
- door_height += 1;
-}
-
-void
-EditorSwitchDoorObj::make_smaller ()
-{
- if (door_height > 1)
- door_height -= 1;
-}
-
-void
-EditorSwitchDoorObj::set_position_offset(const CL_Vector& offset)
-{
- door_pos += offset;
-}
-
-} // namespace EditorObjs
/* EOF */
Index: switch_door.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldobjs/switch_door.hxx,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- switch_door.hxx 11 Sep 2002 12:45:59 -0000 1.10
+++ switch_door.hxx 11 Sep 2002 15:27:19 -0000 1.11
@@ -21,59 +21,18 @@
#define HEADER_PINGUS_WORLDOBJS_SWITCH_DOOR_HXX
#include "../worldobj.hxx"
-#include "../worldobj_data.hxx"
-#include "../editor/sprite_editorobj.hxx"
-
-#include "../libxmlfwd.hxx"
namespace WorldObjsData {
-
-/** A variable height door which can block the way and which can be
- opened by a switch */
-class SwitchDoorData : public WorldObjData
-{
-public:
- /// The upper/middle pos of the door
- CL_Vector door_pos;
-
- /// The bottom/middle pos of the switch
- CL_Vector switch_pos;
-
- // The height of the door in graphic tiles
- int door_height;
-
- SwitchDoorData ();
- SwitchDoorData (xmlDocPtr doc, xmlNodePtr cur);
-
- SwitchDoorData (const SwitchDoorData& old);
- SwitchDoorData operator= (const SwitchDoorData& old);
-
- /** 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 SwitchDoorData;
} // namespace WorldObjsData
namespace WorldObjs {
/** A door and a switch, if a pingu is passing the switch, the door
will open. */
-class SwitchDoor : public WorldObjsData::SwitchDoorData,
- public WorldObj
+class SwitchDoor : public WorldObj
{
private:
- CL_Surface door_box;
- CL_Surface door_tile;
- CL_Surface door_tile_cmap;
- CL_Surface switch_sur;
-
/** True if the door is opening */
bool is_opening;
@@ -81,12 +40,15 @@
is opening, it will be zero when the door is fully opened */
int current_door_height;
+ WorldObjsData::SwitchDoorData* const data;
+
public:
- SwitchDoor (const SwitchDoorData&);
+ SwitchDoor (WorldObjsData::SwitchDoorData* data_);
- void draw_colmap();
+ void draw_colmap ();
void draw (GraphicContext& gc);
- void update(float delta);
+ void update (float delta);
+
/// The switch and the door should stay above the pingus
float get_z_pos() const { return 100; }
@@ -96,71 +58,6 @@
};
} // namespace WorldObjs
-
-
-namespace EditorObjs {
-
-class EditorSwitchDoorObj;
-
-/** A dummy object to represent the switch for a switchdoor, all real
- work is done inside EditorSwitchDoorObj */
-class EditorSwitchDoorSwitchObj : public SpriteEditorObj
-{
-private:
- EditorSwitchDoorObj* door;
-
-public:
- EditorSwitchDoorSwitchObj (EditorSwitchDoorObj* data);
-
- EditorObj* duplicate();
-
- void write_xml (std::ostream& /*xml*/) {}
- std::string status_line();
-
-private:
- EditorSwitchDoorSwitchObj (const EditorSwitchDoorSwitchObj&);
- EditorSwitchDoorSwitchObj operator= (const EditorSwitchDoorSwitchObj&);
-};
-
-class EditorSwitchDoorObj : public WorldObjsData::SwitchDoorData,
- public RectEditorObj
-{
-private:
- CL_Surface door_box;
- CL_Surface door_tile;
-
-public:
- friend class EditorSwitchDoorSwitchObj;
-
- EditorSwitchDoorObj (const SwitchDoorData&);
-
- /** Create this object (and child objects) with reasonable defaults
- for the editor */
- static EditorObjLst create (const CL_Vector& pos);
-
- EditorObj* duplicate();
- float get_z_pos() { return door_pos.z; }
-
- int get_width() { return door_box.get_width (); }
- int get_height() { return door_box.get_height (); }
-
- void make_larger ();
- void make_smaller ();
- void write_xml (std::ostream& xml) { SwitchDoorData::write_xml (xml); }
- CL_Vector get_upper_left_corner() { return door_pos; }
-
- void set_position_offset(const CL_Vector &);
-
- void draw (EditorNS::EditorView * view);
- void save_xml (std::ostream& xml);
- std::string status_line();
-
-private:
- EditorSwitchDoorObj (const EditorSwitchDoorObj&);
- EditorSwitchDoorObj operator= (const EditorSwitchDoorObj&);
-};
-
-} // namespace EditorObjs
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/worldobjs switch_door.cxx,1.13,1.14 switch_door.hxx,1.10,1.11,
torangan <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src/worldobjsdata switch_door_data.cxx,NONE,1.1 switch_door_data.hxx,NONE,1.1 Makefile.am,1.2,1.3
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src/editorobjs switch_door_obj.cxx,NONE,1.1 switch_door_obj.hxx,NONE,1.1 switch_door_switch_obj.cxx,NONE,1.1 switch_door_switch_obj.hxx,NONE,1.1 Makefile.am,1.2,1.3
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src/worldobjsdata switch_door_data.cxx,NONE,1.1 switch_door_data.hxx,NONE,1.1 Makefile.am,1.2,1.3
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src/editorobjs switch_door_obj.cxx,NONE,1.1 switch_door_obj.hxx,NONE,1.1 switch_door_switch_obj.cxx,NONE,1.1 switch_door_switch_obj.hxx,NONE,1.1 Makefile.am,1.2,1.3
- Index(es):