# HG changeset patch # User ekku # Date 1228750654 0 # Node ID c080c8c703333226011a621dcb7aee4f32e3a20b # Parent 27ce69fd1e06fcbe6f8acc1b16cb230fbc206ea1 Previous position added, and unsigned int bug fixed diff -r 27ce69fd1e06 -r c080c8c70333 src/PhysicsObject.cc --- a/src/PhysicsObject.cc Mon Dec 08 15:02:05 2008 +0000 +++ b/src/PhysicsObject.cc Mon Dec 08 15:37:34 2008 +0000 @@ -9,6 +9,7 @@ float collision_elasticity, bool enabled) : world(world), position(position), + previousPosition(position), velocity(velocity), mass(mass), inAir(true), @@ -79,9 +80,8 @@ void PhysicsObject::walk (TimeMS dt, bool right) { float velocity = PLAYER_WALK_SPEED; float walkAmount = (velocity*dt)/1000; - Vector reached = this->position; - while (walkAmount > 0 && !this->inAir) { - this->position = walk_one_step((1 < walkAmount ? 1 : walkAmount), right); + while (walkAmount > 0){// && !this->inAir) { + setPosition (walk_one_step((1 < walkAmount ? 1 : walkAmount), right)); walkAmount--; } // TODO: Should the remaining walkAmount be handled somehow? @@ -240,11 +240,11 @@ // This means everything was ok, so no need to do anything } - this->position = newPosition; + setPosition (newPosition); } else { newPosition = reached; - this->position = newPosition; + setPosition (newPosition); // the following may delete this object, so it must be the last thing called onCollision(collisionPoint, NULL); @@ -327,7 +327,7 @@ } void PhysicsObject::updatePhysics (Vector position, Vector velocity, bool inAir, FacingDirection facing, float aim) { - this->position = position; + setPosition (position); this->velocity = velocity; this->inAir = inAir; this->facing = facing; @@ -338,6 +338,15 @@ return position; } +Vector PhysicsObject::getPreviousPosition (void) const { + return previousPosition; +} + +void PhysicsObject::setPosition (Vector pos) { + this->previousPosition = this->position; + this->position = pos; +} + PixelCoordinate PhysicsObject::getCoordinate (void) const { return world.getPixelCoordinate(position); } diff -r 27ce69fd1e06 -r c080c8c70333 src/PhysicsObject.hh --- a/src/PhysicsObject.hh Mon Dec 08 15:02:05 2008 +0000 +++ b/src/PhysicsObject.hh Mon Dec 08 15:37:34 2008 +0000 @@ -32,6 +32,7 @@ protected: Vector position; + Vector previousPosition; Vector velocity; float mass; bool inAir; // Is the object "on the ground" @@ -177,6 +178,20 @@ Vector getPosition (void) const; /** + * Set previous object position. + * + * @param Position vector + */ + void setPosition (Vector pos); + + /** + * Get previous object position. + * + * @return Position vector + */ + Vector getPreviousPosition (void) const; + + /** * Get current object screen coordinates * * @return PixelCoordinate position diff -r 27ce69fd1e06 -r c080c8c70333 src/Rope.cc --- a/src/Rope.cc Mon Dec 08 15:02:05 2008 +0000 +++ b/src/Rope.cc Mon Dec 08 15:37:34 2008 +0000 @@ -24,7 +24,7 @@ length = ROPE_LENGTH; // copy position + velocity from player - position = player.getPosition(); + setPosition (player.getPosition()); velocity = player.getVelocity() + player.getDirection() * ROPE_VELOCITY; // we are FLYING @@ -45,7 +45,7 @@ // Ropes location will be used as the pivot point, so move the location to the collisionPoint. // Currently the position is something like one pixel away from the collisionPoint where there isn't ground. - this->position = collisionPoint; + setPosition (collisionPoint); // set player's pivot player.setPivot(this); diff -r 27ce69fd1e06 -r c080c8c70333 src/Terrain.cc --- a/src/Terrain.cc Mon Dec 08 15:02:05 2008 +0000 +++ b/src/Terrain.cc Mon Dec 08 15:37:34 2008 +0000 @@ -179,7 +179,7 @@ PixelCoordinate Terrain::getPixelCoordinate (Vector point) const { // XXX: assume 1:1 - return PixelCoordinate((unsigned int) point.x, (unsigned int) point.y); + return PixelCoordinate((int) point.x, (int) point.y); } PixelCoordinate Terrain::getDimensions (void) const {