[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/worldmap path.cxx,1.5,1.6 pingus.cxx,
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/worldmap path.cxx,1.5,1.6 pingus.cxx,1.23,1.24 pingus.hxx,1.19,1.20 |
Date: |
26 Nov 2002 21:30:39 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/worldmap
In directory dark:/tmp/cvs-serv14946/src/worldmap
Modified Files:
path.cxx pingus.cxx pingus.hxx
Log Message:
- added direction handling for sprite on worldmap
Index: path.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/path.cxx,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- path.cxx 20 Oct 2002 18:28:49 -0000 1.5
+++ path.cxx 26 Nov 2002 21:30:37 -0000 1.6
@@ -63,7 +63,7 @@
Vec::iterator prev = vec.begin();
for(Vec::iterator next = prev + 1; next != vec.end(); ++next)
{
- length += Vector::distance(*prev, *next);
+ length += Vector::distance2d(*prev, *next);
prev = next;
}
return length;
@@ -81,7 +81,7 @@
float comp_length = 0.0f;
while (next != vec.end())
{
- float length = Vector::distance(*current, *next);
+ float length = Vector::distance2d(*current, *next);
// The pingu is between current and next
if (comp_length + length > vec_position)
Index: pingus.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pingus.cxx,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- pingus.cxx 29 Oct 2002 12:48:33 -0000 1.23
+++ pingus.cxx 26 Nov 2002 21:30:37 -0000 1.24
@@ -22,6 +22,7 @@
#include "../boost/smart_ptr.hpp"
#include "../graphic_context.hxx"
#include "dot.hxx"
+#include "../math.hxx"
#include "pingus.hxx"
namespace WorldMapNS {
@@ -45,6 +46,16 @@
void
Pingus::draw (GraphicContext& gc)
{
+ // FIXME: Our sprite class is quite a bit sucky...
+ if (!is_walking())
+ sprite.set_frame(5);
+
+ // FIXME: Replace the sprite and add up/down here
+ float direction = get_direction();
+ if (direction >= 0 && direction < 180)
+ sprite.set_direction(Sprite::RIGHT);
+ else
+ sprite.set_direction(Sprite::LEFT);
gc.draw(sprite, pos);
}
@@ -54,7 +65,7 @@
float delta = 0.025f;
sprite.update ();
- if (current_node == NoNode)
+ if (is_walking())
update_walk(delta);
}
@@ -80,9 +91,17 @@
}
// Recalc pingu position on the screen
+ last_pos = pos;
pos = calc_pos ();
}
+float
+Pingus::get_direction() const
+{
+ return (atan2(last_pos.x - pos.x,
+ -(last_pos.y - pos.y)) / Math::pi * 180.0f) + 180.0f;
+}
+
bool
Pingus::walk_to_node (NodeId target)
{
@@ -196,8 +215,11 @@
float
Pingus::get_z_pos() const
{
- // FIXME: Should should be interpolated from the given position on the path
- return 10.0f;
+ /** We add 1.0f here so that the pingu is guranteed to stay above
+ the level-dots (this is a hack), but I currently don't know a
+ better way, since both pingu and level dot have the same
+ z-pos */
+ return pos.z + 10.0f;
}
void
Index: pingus.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pingus.hxx,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- pingus.hxx 2 Nov 2002 14:46:29 -0000 1.19
+++ pingus.hxx 26 Nov 2002 21:30:37 -0000 1.20
@@ -75,6 +75,10 @@
/** Current position of the pingu, only for caching purpose */
Vector pos;
+ /** The position the pingu had before his current position, used to
+ calculate its current direction */
+ Vector last_pos;
+
public:
/** */
Pingus (PathGraph* arg_path);
@@ -86,9 +90,6 @@
/** @return true if the node is reachable, false otherwise */
bool walk_to_node (NodeId target);
- /** calculate the position of the pingu */
- Vector calc_pos ();
-
bool is_walking();
/** @return the node on which the pingu is currently standing, 0 is
@@ -99,11 +100,21 @@
/** Set the pingu to the position of a given node */
void set_position (NodeId node);
+
+ /** return the current position in world coordinates */
Vector get_pos() const { return pos; }
+ /** Used for z-ordering for drawing */
float get_z_pos() const;
-
+
private:
+ /** Calculate the direction in which the pingu is heading, return
+ value is in degrees => [0,360[, 0=north, 180=south, 270=east, 90=west */
+ float get_direction() const;
+
+ /** calculate the position of the pingu */
+ Vector calc_pos ();
+
void update_walk (float delta);
void update_edge_path();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/worldmap path.cxx,1.5,1.6 pingus.cxx,1.23,1.24 pingus.hxx,1.19,1.20,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src math.hxx,1.4,1.5 pingu_action.cxx,1.20,1.21 sprite.cxx,1.10,1.11 sprite.hxx,1.8,1.9
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/data/levels/multiplayer - New directory
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src math.hxx,1.4,1.5 pingu_action.cxx,1.20,1.21 sprite.cxx,1.10,1.11 sprite.hxx,1.8,1.9
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/data/levels/multiplayer - New directory
- Index(es):