# HG changeset patch # User terom # Date 1228684689 0 # Node ID 215de3d4de60dacb443b7d05831c776a56be4c6b # Parent 8c999cf4c182e4c8f4e8762bd74822f389694f48 change facingRight from a bool to an diff -r 8c999cf4c182 -r 215de3d4de60 src/Network/Client.cc --- a/src/Network/Client.cc Sun Dec 07 21:10:04 2008 +0000 +++ b/src/Network/Client.cc Sun Dec 07 21:18:09 2008 +0000 @@ -139,7 +139,11 @@ // Engine::log(INFO, "client_player.on_position") << "obj=" << obj << ", position=" << position << ", velocity=" << velocity << ", aim=" << aim << ", [" << flags << "]"; // just update... - updatePhysics(position, velocity, flags & NETWORK_PHYSICS_INAIR, flags & NETWORK_PHYSICS_FACE_RIGHT, aim); + updatePhysics(position, velocity, + flags & NETWORK_PHYSICS_INAIR, + flags & NETWORK_PHYSICS_FACE_RIGHT ? FACING_RIGHT : FACING_LEFT, + aim + ); } void NetworkClientPlayerHelper::on_dig (NetworkPacketInput &pkt) { diff -r 8c999cf4c182 -r 215de3d4de60 src/Network/Server.cc --- a/src/Network/Server.cc Sun Dec 07 21:10:04 2008 +0000 +++ b/src/Network/Server.cc Sun Dec 07 21:18:09 2008 +0000 @@ -213,7 +213,9 @@ void NetworkServerPlayer::send_position_update (void) { NetworkPacket pkt; - int flags = (inAir ? NETWORK_PHYSICS_INAIR : 0) | (facingRight ? NETWORK_PHYSICS_FACE_RIGHT : 0); + int flags = + (inAir ? NETWORK_PHYSICS_INAIR : 0) | + (facing == FACING_RIGHT ? NETWORK_PHYSICS_FACE_RIGHT : 0); pkt.write_vector(position); pkt.write_vector(velocity); diff -r 8c999cf4c182 -r 215de3d4de60 src/PhysicsObject.cc --- a/src/PhysicsObject.cc Sun Dec 07 21:10:04 2008 +0000 +++ b/src/PhysicsObject.cc Sun Dec 07 21:18:09 2008 +0000 @@ -5,7 +5,7 @@ #include PhysicsObject::PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity, bool enabled) : - world(world), position(position), velocity(velocity), mass(mass), inAir(true), aim(0), facingRight(true), + world(world), position(position), velocity(velocity), mass(mass), inAir(true), aim(0), facing(FACING_RIGHT), alive(false), shouldDelete(false), pivot(NULL) { if (enabled) @@ -300,16 +300,15 @@ //Engine::log(DEBUG, "PhysicsObject.changeAim") << "Player aim: " << this->aim; } -void PhysicsObject::setFacing(bool facingRight) { - //Engine::log(DEBUG, "PhysicsObject.setFacing") << "Facing: " << right; - this->facingRight = facingRight; +void PhysicsObject::setFacing (FacingDirection facing) { + this->facing = facing; } -void PhysicsObject::updatePhysics (Vector position, Vector velocity, bool inAir, bool facingRight, float aim) { +void PhysicsObject::updatePhysics (Vector position, Vector velocity, bool inAir, FacingDirection facing, float aim) { this->position = position; this->velocity = velocity; this->inAir = inAir; - this->facingRight = facingRight; + this->facing = facing; this->aim = aim; } @@ -325,8 +324,8 @@ return velocity; } -bool PhysicsObject::getFacing (void) const { - return facingRight; +FacingDirection PhysicsObject::getFacing (void) const { + return facing; } float PhysicsObject::getAim (void) const { @@ -334,7 +333,7 @@ } Vector PhysicsObject::getDirection (void) const { - return facingRight ? Vector(cos(aim), -sin(aim)) : Vector(-cos(aim), -sin(aim)); + return facing == FACING_RIGHT ? Vector(cos(aim), -sin(aim)) : Vector(-cos(aim), -sin(aim)); } const std::vector& PhysicsObject::getShape () const { @@ -392,31 +391,7 @@ } } -float PhysicsObject::getPivotForce (PhysicsObject *bob) { return 0.0; } - -void PhysicsObject::draw(CL_GraphicContext *gc) { - CL_Quad player( - (position+shape[0]).x, (position+shape[0]).y, - (position+shape[1]).x, (position+shape[1]).y, - (position+shape[2]).x, (position+shape[2]).y, - (position+shape[3]).x, (position+shape[3]).y - ); - - gc->fill_quad(player, CL_Color::green); - - const uint16_t chlen = 10; - uint16_t x = player.center().x; - uint16_t y = player.center().y; - if (facingRight) { - gc->draw_line(x, y, - x + std::cos(aim)*chlen, - y - std::sin(aim)*chlen, - CL_Color::black); - } else { - gc->draw_line(x, y, - x - std::cos(aim)*chlen, - y - std::sin(aim)*chlen, - CL_Color::black); - } +float PhysicsObject::getPivotForce (PhysicsObject *bob) { + return 0.0; } diff -r 8c999cf4c182 -r 215de3d4de60 src/PhysicsObject.hh --- a/src/PhysicsObject.hh Sun Dec 07 21:10:04 2008 +0000 +++ b/src/PhysicsObject.hh Sun Dec 07 21:18:09 2008 +0000 @@ -15,6 +15,10 @@ // Type definitions typedef Vector Force; +enum FacingDirection { + FACING_LEFT, + FACING_RIGHT +}; /** * PhysicObject class. A basic PhysicsObject class. @@ -29,7 +33,7 @@ // Attributes for players float aim; // Aim direction (half circle) - bool facingRight; // Player facing + FacingDirection facing; // Player facing bool alive; bool shouldDelete; @@ -60,7 +64,7 @@ * * @param facingRight True if player is facing right. */ - void setFacing(bool facingRight); + void setFacing (FacingDirection facing); /** * Makes the player jump in the air. @@ -84,7 +88,7 @@ * @param facingRight New facingRight value * @param aim New aim */ - virtual void updatePhysics(Vector position, Vector velocity, bool inAir, bool facingRight, float aim); + virtual void updatePhysics(Vector position, Vector velocity, bool inAir, FacingDirection facing, float aim); /** * Put object to the objects list so that its movement will be calculated. @@ -197,7 +201,7 @@ * * @return Object facing (true if facing right) */ - bool getFacing() const; + FacingDirection getFacing() const; /** * Return object aim angle. @@ -240,13 +244,6 @@ * Update object in physics simulation. */ virtual void tick (TimeMS tick_length); - - /** - * Draw object - * - * @param gc CL_GraphicContext - */ - virtual void draw(CL_GraphicContext *gc); }; struct Derivative { diff -r 8c999cf4c182 -r 215de3d4de60 src/Player.cc --- a/src/Player.cc Sun Dec 07 21:10:04 2008 +0000 +++ b/src/Player.cc Sun Dec 07 21:18:09 2008 +0000 @@ -114,14 +114,14 @@ if (velocity.x > -PLAYER_MAX_SPEED) move_force.x -= PLAYER_MOVE_FORCE; - setFacing(false); + setFacing(FACING_LEFT); } if (input & INPUT_MOVE_RIGHT) { if (velocity.x < PLAYER_MAX_SPEED) move_force.x += PLAYER_MOVE_FORCE; - setFacing(true); + setFacing(FACING_RIGHT); } } @@ -205,10 +205,10 @@ // calulate where to draw the worm CL_Rectf destination( - position.x + (getFacing() ? -1 : 1) * img_width / 2 - camera.x, - position.y - img_height / 2 - camera.y, - position.x + (getFacing() ? 1 : -1) * img_width / 2 - camera.x, - position.y + img_height / 2 - camera.y + position.x + (facing == FACING_RIGHT ? -1 : 1) * img_width / 2 - camera.x, + position.y - img_height / 2 - camera.y, + position.x + (facing == FACING_RIGHT ? 1 : -1) * img_width / 2 - camera.x, + position.y + img_height / 2 - camera.y ); // draw the correct animation frame from the skin diff -r 8c999cf4c182 -r 215de3d4de60 src/Rope.cc --- a/src/Rope.cc Sun Dec 07 21:10:04 2008 +0000 +++ b/src/Rope.cc Sun Dec 07 21:18:09 2008 +0000 @@ -101,7 +101,7 @@ player.setPivot(NULL); // update position stuff - updatePhysics(position, velocity, true, false, 0); + updatePhysics(position, velocity, true, FACING_RIGHT, 0); // update vars this->state = new_state;