add a handful of consts to PhysicsObject and modify draw to use getCoordinate, and replace old skin.png with new skin.png
authorterom
Sun, 07 Dec 2008 20:25:57 +0000
changeset 257 549783d71e51
parent 256 eb4975026402
child 258 833ad8d7db8b
add a handful of consts to PhysicsObject and modify draw to use getCoordinate, and replace old skin.png with new skin.png
data/share/skin.png
data/skin.png
src/GameState.cc
src/PhysicsObject.cc
src/PhysicsObject.hh
src/Player.cc
src/Projectile.cc
src/Rope.cc
Binary file data/share/skin.png has changed
Binary file data/skin.png has changed
--- a/src/GameState.cc	Sun Dec 07 20:08:28 2008 +0000
+++ b/src/GameState.cc	Sun Dec 07 20:25:57 2008 +0000
@@ -35,7 +35,7 @@
 }
     
 void GameState::draw(Graphics *g, bool displayWeapon) {
-    PixelCoordinate camera = world.getPixelCoordinate(local_player->getPosition()) - world.getDimensions() / 2;
+    PixelCoordinate camera = local_player->getCoordinate() - world.getDimensions() / 2;
 
     // Draw world/terrain
     world.draw(g, camera);
--- a/src/PhysicsObject.cc	Sun Dec 07 20:08:28 2008 +0000
+++ b/src/PhysicsObject.cc	Sun Dec 07 20:25:57 2008 +0000
@@ -313,28 +313,32 @@
     this->aim = aim;
 }
 
-Vector PhysicsObject::getPosition () {
-    return this->position;
+Vector PhysicsObject::getPosition (void) const {
+    return position;
 }
-
-Vector PhysicsObject::getVelocity () {
-    return this->velocity;
+    
+PixelCoordinate PhysicsObject::getCoordinate (void) const {
+    return world.getPixelCoordinate(position);
 }
 
-bool PhysicsObject::getFacing() {
-    return this->facingRight;
+Vector PhysicsObject::getVelocity (void) const {
+    return velocity;
 }
 
-float PhysicsObject::getAim() {
-    return this->aim;
+bool PhysicsObject::getFacing (void) const {
+    return facingRight;
 }
 
-Vector PhysicsObject::getDirection (void) {
+float PhysicsObject::getAim (void) const {
+    return aim;
+}
+
+Vector PhysicsObject::getDirection (void) const {
     return facingRight ? Vector(cos(aim), -sin(aim)) : Vector(-cos(aim), -sin(aim));
 }
 
-std::vector<Vector>& PhysicsObject::getShape () {
-    return this->shape;
+const std::vector<Vector>& PhysicsObject::getShape () const {
+    return shape;
 }
 
 void PhysicsObject::setShape (std::vector<Vector> shape) {
--- a/src/PhysicsObject.hh	Sun Dec 07 20:08:28 2008 +0000
+++ b/src/PhysicsObject.hh	Sun Dec 07 20:25:57 2008 +0000
@@ -162,28 +162,28 @@
      *
      * @return Position vector
      */
-    Vector getPosition (void);
+    Vector getPosition (void) const;
 
     /**
      * Get current object screen coordinates
      *
      * @return PixelCoordinate position
      */
-    PixelCoordinate getCoordinate (void);
+    PixelCoordinate getCoordinate (void) const;
 
     /**
      * Get current object velocity.
      *
      * @return Velocity vector
      */
-    Vector getVelocity();
+    Vector getVelocity() const;
 
     /**
      * Return object shape.
      *
      * @return Polygon points
      */
-    std::vector<Vector>& getShape();
+    const std::vector<Vector>& getShape() const;
 
     /**
      * Set object shape.
@@ -197,19 +197,19 @@
      *
      * @return Object facing (true if facing right)
      */
-    bool getFacing();
+    bool getFacing() const;
 
     /**
      * Return object aim angle.
      *
      * @return Object aim angle
      */
-    float getAim();
+    float getAim() const;
 
     /**
      * Returns facing+aim as a unit vector
      */
-    Vector getDirection (void);
+    Vector getDirection (void) const;
 
     /**
      *  Mark object as destroyed, it will be delete'd later
--- a/src/Player.cc	Sun Dec 07 20:08:28 2008 +0000
+++ b/src/Player.cc	Sun Dec 07 20:25:57 2008 +0000
@@ -215,11 +215,8 @@
     // draw "crosshair", a half-line from our position to 10px away
     Vector crosshair = getDirection() * PLAYER_CROSSHAIR_LENGTH;
 
-    PixelCoordinate aim_start = state.world.getPixelCoordinate(
-            position + crosshair / 2) - camera;
-
-    PixelCoordinate aim_end = state.world.getPixelCoordinate(
-            position + crosshair) - camera;
+    PixelCoordinate aim_start = getCoordinate() + world.getPixelCoordinate(crosshair / 2) - camera;
+    PixelCoordinate aim_end = getCoordinate() + world.getPixelCoordinate(crosshair) - camera;
     
     gc->draw_line(aim_start.x, aim_start.y, aim_end.x, aim_end.y, CL_Color::black);
     
@@ -235,7 +232,7 @@
     if (displayWeapon && getCurrentWeapon()) {
         const std::string weaponName = getCurrentWeapon()->getName();
 
-        const PixelCoordinate pc = state.world.getPixelCoordinate(position) - camera;
+        PixelCoordinate pc = getCoordinate() - camera;
         
         // XXX: fix magic constants once we know how big the worm is
         g->getSimpleFont().draw(
--- a/src/Projectile.cc	Sun Dec 07 20:08:28 2008 +0000
+++ b/src/Projectile.cc	Sun Dec 07 20:25:57 2008 +0000
@@ -46,7 +46,7 @@
     CL_GraphicContext *gc = g->get_gc();
 
     if (visible) {
-        PixelCoordinate pos = state.world.getPixelCoordinate(position) - camera;
+        PixelCoordinate pos = getCoordinate() - camera;
 
         CL_Quad projectile(
                 pos.x + 1, pos.y + 1,
--- a/src/Rope.cc	Sun Dec 07 20:08:28 2008 +0000
+++ b/src/Rope.cc	Sun Dec 07 20:25:57 2008 +0000
@@ -124,13 +124,13 @@
     if (state == ROPE_FOLDED)
         return;
 
-    PixelCoordinate player_pos = world.getPixelCoordinate(player.getPosition()) - camera;
-    PixelCoordinate self_pos = world.getPixelCoordinate(getPosition()) - camera;
+    PixelCoordinate player_pos = player.getCoordinate() - camera;
+    PixelCoordinate self_pos = getCoordinate() - camera;
 
     g->get_gc()->draw_line(
-            player_pos.x, player_pos.y,
-            self_pos.x, self_pos.y,
-            CL_Color::black
+        player_pos.x, player_pos.y,
+        self_pos.x, self_pos.y,
+        CL_Color::black
     );
 }