[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/worldmap graph.hxx,1.7,1.8 pingus.hxx
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/worldmap graph.hxx,1.7,1.8 pingus.hxx,1.9,1.10 worldmap.cxx,1.10,1.11 worldmap.hxx,1.9,1.10 |
Date: |
8 Sep 2002 18:13:06 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/worldmap
In directory dark:/tmp/cvs-serv696/src/worldmap
Modified Files:
graph.hxx pingus.hxx worldmap.cxx worldmap.hxx
Log Message:
- fixed trap in the editor (well, moving them is still broken now)
- some worldmap rewrite stuff, completly #ifdef'ed out at the moment
Index: graph.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/graph.hxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- graph.hxx 7 Sep 2002 23:33:47 -0000 1.7
+++ graph.hxx 8 Sep 2002 18:13:04 -0000 1.8
@@ -79,35 +79,8 @@
@param offset FIXME: should be handled by GraphicContext instead */
void draw (const CL_Vector& offset);
- /** Some functions to parse the data out of an xml file
-
- File Syntax (FIXME: the current implementation is different):
-
- <pingus-worldmap>
- <graph>
- <nodes>
- <node id="node_1">
- <position>...</>
- <data><tube>...</></>
- </node>
- <node id="node_2">
- <position>...</>
- <data><level>...</></>
- </node>
- ...
- <nodes>
- <edges>
- <edge id="egde_1" source="1" destination="2">
- <!-- The path which connect two nodes -->
- <data>
- <position>...</>
- <position>...</>
- </data>
- </edge>
- </edges>
- <graph>
- </pingus-worldmap>
-
+ /** Some functions to parse the data out of an xml file.
+ For syntax description see doc/worldmap.xml
@{ */
void parse_file (std::string filename);
private:
Index: pingus.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pingus.hxx,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- pingus.hxx 7 Sep 2002 23:33:47 -0000 1.9
+++ pingus.hxx 8 Sep 2002 18:13:04 -0000 1.10
@@ -37,6 +37,151 @@
class Pingus
{
private:
+#if TODO
+ /** The node on which the pingu currently stands, 0 if the pingu is
+ currently on the move to another node */
+ Node* current_node;
+
+ /** The node from which the pingu as started its walk to the
+ target_node, value is undefined when the pingu is currently
+ standing on a node */
+ Node* source_node;
+
+ /** The node to which the pingu is currently walking, value is
+ undefined when the pingu is currently standing on a node */
+ Node* target_node;
+
+ /** The node path to walk. The edge between two nodes is itself
+ represented as a array of positions */
+ std::vector<Node*> node_path;
+
+ /** The path which represents an edge between two nodes */
+ std::vector<CL_Vector> edge_path;
+
+ /** The length of the edge_path in pixels */
+ float edge_path_length;
+
+ /** The position in the edge_path, 0 means the pingu is on the
+ source_node, edge_path_length means that the pingu has reached
+ the target node. Position between edge_path nodes is
+ interpolated. */
+ float edge_path_position;
+
+ /** Current position of the pingu, only for caching purpose */
+ CL_Vector pos;
+
+ void draw (GraphicContext& gc);
+
+ void update_walk (float delta)
+ {
+ // Update the position
+ edge_path_position += velocity * delta;
+
+ if (edge_path_position > edge_path_length) // target reached
+ {
+ if (node_path.empty ()) // final target reached
+ {
+ current_node = target_node;
+ }
+ else // edge is traveled, now go to the next node
+ {
+ source_node = target_node;
+ target_node = node_path.top ();
+ node_path.pop ();
+
+ edge_path_position = 0.0f;
+ edge_path = get_edge (source_node, target_node)->data;
+ edge_path_lenght = calc_edge_path_length ();
+ }
+ }
+
+ // Recalc pingu position on the screen
+ pos = calc_pos ();
+ }
+
+ /** @return true if the node is reachable, false otherwise */
+ bool walk_to_node (Node* target)
+ {
+ if (current_node) // pingu stands still
+ {
+ node_path = worldmap->find_path (current_node, target);
+ }
+ else // pingu between two nodes
+ {
+ node_path1 = worldmap->find_path (source_node, target);
+ node_path2 = worldmap->find_path (target_node, target);
+
+ // Select the shorter path
+ if (length (node_path1) < length (node_path2))
+ { // walk to source node, which means to reverse the pingu
+ node_path = node_path1;
+
+ // Reverse the pingu
+ swap(target_node, source_node);
+ std::reverse(edge_path.begin (), edge_path.end ());
+ edge_path_position = edge_path_lenght - edge_path_position;
+ }
+ else
+ { // walk to target_node
+ node_path = node_path2;
+ }
+ }
+ }
+
+ /** calculate the position of the pingu */
+ CL_Vector calc_pos ()
+ {
+ if (current_node) // pingu stands still
+ {
+ return current_node->get_pos ();
+ }
+ else // between two nodes
+ {
+ iterator current = edge_path.begin ();
+ iterator next = edge_path.begin () + 1;
+
+ float comp_length = 0.0f;
+ while (next != end)
+ {
+ float length = line_length (current, next);
+
+ if (comp_length + length > edge_path_position)
+ {
+ float perc = (edge_path_position - comp_length) // length to
walk from current node
+ / length;
+
+ return interpol (current, next, perc);
+ }
+
+ ++current;
+ ++next;
+ }
+ assert (!"This shouldn't happen, traveled bejoint target node");
+ return target_node->get_pos ();
+ }
+ }
+
+ void update (float delta)
+ {
+ sprite.update (delta);
+
+ if (current_node)
+ {
+ // do stuff when pingu is on a node
+ }
+ else // pingu walking
+ {
+ walk (delta);
+ }
+ }
+
+ /** @return the node on which the pingu is currently standing, 0 is
+ returned if the pingu is currently between two nodes */
+ Node* get_node () {
+ return current_node;
+ }
+#endif
+
Sprite sprite;
CL_Vector pos;
std::queue<Node*> targets;
Index: worldmap.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/worldmap.cxx,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- worldmap.cxx 7 Sep 2002 23:33:47 -0000 1.10
+++ worldmap.cxx 8 Sep 2002 18:13:04 -0000 1.11
@@ -223,15 +223,6 @@
gc.print_center (Fonts::pingus_small,
CL_Display::get_width ()/2, CL_Display::get_height () -
40,
last_node->get_string().c_str ());
-
- /*
- if (last_node->finished)
- font->print_center (CL_Display::get_width ()/2, CL_Display::get_height
() - 20,
- "100%");
- else
- font->print_center (CL_Display::get_width ()/2, CL_Display::get_height
() - 20,
- "0%");
- */
}
graph_data.draw(offset);
Index: worldmap.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/worldmap.hxx,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- worldmap.hxx 7 Sep 2002 23:33:47 -0000 1.9
+++ worldmap.hxx 8 Sep 2002 18:13:04 -0000 1.10
@@ -39,6 +39,35 @@
events (successfull level completions). */
class WorldMap
{
+#if TODO
+ WorldMap () {
+ load_graph ();
+ load_objects ();
+ }
+
+ void draw (GraphicContext& gc)
+ {
+ for (iterator drawables.begin (); i != drawables.end (); ++i)
+ {
+ i->draw (gc);
+ }
+ }
+
+ void update (float delta)
+ {
+ for (iterator drawables.begin (); i != drawables.end (); ++i)
+ {
+ i->update (delta);
+ }
+ }
+
+ /** @return the shortest path between node1 and node2 */
+ std::vector<Edge*> find_path (Node* node1, Node* node2);
+
+ /** @return the node as the given position. x and y are in
+ world-COs, not screen. */
+ Node* get_node (int x, int y);
+#endif
private:
CL_Surface background;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/worldmap graph.hxx,1.7,1.8 pingus.hxx,1.9,1.10 worldmap.cxx,1.10,1.11 worldmap.hxx,1.9,1.10,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src/editor object_selector.cxx,1.10,1.11 object_selector.hxx,1.8,1.9
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src/editorobjs bumper_obj.cxx,1.1,1.2 bumper_obj.hxx,1.1,1.2 fake_exit_obj.cxx,1.1,1.2 fake_exit_obj.hxx,1.1,1.2 guillotine_obj.cxx,1.1,1.2 guillotine_obj.hxx,1.1,1.2 hammer_obj.cxx,1.1,1.2 hammer_obj.hxx,1.1,1.2 laser_exit_obj.cxx,1.1,1.2 laser_exit_obj.hxx,1.1,1.2 smasher_obj.cxx,1.1,1.2 smasher_obj.hxx,1.1,1.2 spike_obj.cxx,1.1,1.2 spike_obj.hxx,1.1,1.2
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src/editor object_selector.cxx,1.10,1.11 object_selector.hxx,1.8,1.9
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src/editorobjs bumper_obj.cxx,1.1,1.2 bumper_obj.hxx,1.1,1.2 fake_exit_obj.cxx,1.1,1.2 fake_exit_obj.hxx,1.1,1.2 guillotine_obj.cxx,1.1,1.2 guillotine_obj.hxx,1.1,1.2 hammer_obj.cxx,1.1,1.2 hammer_obj.hxx,1.1,1.2 laser_exit_obj.cxx,1.1,1.2 laser_exit_obj.hxx,1.1,1.2 smasher_obj.cxx,1.1,1.2 smasher_obj.hxx,1.1,1.2 spike_obj.cxx,1.1,1.2 spike_obj.hxx,1.1,1.2
- Index(es):