--- 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<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);
+ }
};
--- 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<Player*>::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<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
);
}
--- 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<Vector>& PhysicsObject::getShape () {
+ return this->shape;
+}
+
+void PhysicsObject::setShape (std::vector<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++) {
--- 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<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<Vector> shape;
// Force queue that is emptied on every tick
std::queue<Force> 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<Vector>& getShape(void);
+ void setShape (std::vector<Vector> shape);
void tick (void);
};