# HG changeset patch # User ekku # Date 1227302302 0 # Node ID 0a6d675099dc7e2e3d2888ea21228c4997c86179 # Parent c1a072928790cc74a297537b6ed30d4a410bc0be Mato salmiakin muotoiseksi diff -r c1a072928790 -r 0a6d675099dc src/proto2/GameState.hh --- a/src/proto2/GameState.hh Thu Nov 20 23:54:41 2008 +0000 +++ b/src/proto2/GameState.hh Fri Nov 21 21:18:22 2008 +0000 @@ -25,9 +25,17 @@ bool visible; public: + Player(GameState &state, Vector position, bool visible) : + PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) { - Player(GameState &state, Vector position, bool visible) : - PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) { } + std::vector shape(4); + shape[0] = Vector(0,-6); + shape[1] = Vector(4,0); + shape[2] = Vector(0,6); + shape[3] = Vector(-4,0); + // Initialize the shape of the player (salmiakki shape) + setShape(shape); + } }; diff -r c1a072928790 -r 0a6d675099dc src/proto2/Graphics.cc --- a/src/proto2/Graphics.cc Thu Nov 20 23:54:41 2008 +0000 +++ b/src/proto2/Graphics.cc Fri Nov 21 21:18:22 2008 +0000 @@ -31,8 +31,6 @@ } terrain = CL_Surface(terr); - Engine::log(DEBUG, "Graphics") << "Taalla ollaan."; - // connect timer signal slots.connect(update_timer.sig_timer(), this, &Graphics::on_update); @@ -89,12 +87,16 @@ for (std::list::iterator it = state.player_list.begin(); it != state.player_list.end(); it++) { Player *p = *it; - // draw square - gc->fill_rect( - CL_Rect( - p->getPosition().x * factorX - 5, p->getPosition().y * factorY - 5, - p->getPosition().x * factorX + 5, p->getPosition().y * factorY + 5 - ), CL_Color::black + Vector loc = p->getPosition(); + std::vector &shape = p->getShape(); + // draw quad + gc->fill_quad( + CL_Quad( + (loc.x-shape[0].x) * factorX, (loc.y-shape[0].y) * factorY, + (loc.x-shape[1].x) * factorX, (loc.y-shape[1].y) * factorY, + (loc.x-shape[2].x) * factorX, (loc.y-shape[2].y) * factorY, + (loc.x-shape[3].x) * factorX, (loc.y-shape[3].y) * factorY + ), CL_Color::green ); } diff -r c1a072928790 -r 0a6d675099dc src/proto2/Physics.cc --- a/src/proto2/Physics.cc Thu Nov 20 23:54:41 2008 +0000 +++ b/src/proto2/Physics.cc Fri Nov 21 21:18:22 2008 +0000 @@ -28,7 +28,7 @@ } PhysicsObject::PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity) - : world(world), mass(mass), position(position), velocity(velocity) { + : world(world), mass(mass), position(position), velocity(velocity) { world.addObject(this); } @@ -179,6 +179,14 @@ return this->position; } +std::vector& PhysicsObject::getShape () { + return this->shape; +} + +void PhysicsObject::setShape (std::vector shape) { + this->shape = shape; +} + void PhysicsObject::tick () { this->updatePosition(); } @@ -219,7 +227,6 @@ type = ROCK; } - Engine::log(DEBUG, "PhysicsObject.generta") << "Dims: " << dimensions.x << " " << dimensions.y; // loops for every pixel of circle for(int x = std::max(0, midx-range); x < std::min((int)dimensions.x, midx+range); x++) { for(int y = std::max(0, midy-range); y < std::min((int)dimensions.y, midy+range); y++) { diff -r c1a072928790 -r 0a6d675099dc src/proto2/Physics.hh --- a/src/proto2/Physics.hh Thu Nov 20 23:54:41 2008 +0000 +++ b/src/proto2/Physics.hh Fri Nov 21 21:18:22 2008 +0000 @@ -59,15 +59,19 @@ // or firmly on the ground. Affects to physics. bool inAir; - // Shape of the object. - // //TODO - std::vector edges; + // Shape of the object. We use a polygon with 4 edges + // to make easy to draw with Clanlib. The coordinates + // are relative to the center point. + std::vector shape; // Force queue that is emptied on every tick std::queue forceq; Vector posAfterTick; Vector velAfterTick; + /** + * @param shape Corners of the four sided polygon. + */ PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity); virtual void applyForce (Force force, TimeMS dt); @@ -85,6 +89,8 @@ public: Vector getPosition (void); + std::vector& getShape(void); + void setShape (std::vector shape); void tick (void); };