equal
deleted
inserted
replaced
5 #include <cmath> |
5 #include <cmath> |
6 |
6 |
7 PhysicsObject::PhysicsObject (PhysicsWorld &world, float mass, |
7 PhysicsObject::PhysicsObject (PhysicsWorld &world, float mass, |
8 Vector position, Vector velocity) |
8 Vector position, Vector velocity) |
9 : world(world), position(position), velocity(velocity), |
9 : world(world), position(position), velocity(velocity), |
10 mass(mass), inAir(true), aim(0), facingRight(true), reloadTimer(0) { |
10 mass(mass), inAir(true), aim(0), facingRight(true) { |
11 // TODO: Is thir the right way to do this? |
11 // TODO: Is thir the right way to do this? |
12 //world.addPlayerObject(this); |
12 //world.addPlayerObject(this); |
13 } |
13 } |
14 |
14 |
15 /** |
15 /** |
62 } |
62 } |
63 void PhysicsObject::walk (TimeMS dt, bool right) { |
63 void PhysicsObject::walk (TimeMS dt, bool right) { |
64 float velocity = PLAYER_WALK_SPEED; |
64 float velocity = PLAYER_WALK_SPEED; |
65 float walkAmount = (velocity*dt)/1000; |
65 float walkAmount = (velocity*dt)/1000; |
66 Vector reached = this->position; |
66 Vector reached = this->position; |
67 while(walkAmount > 0 && !this->inAir) { |
67 while (walkAmount > 0 && !this->inAir) { |
68 this->position = walk_one_step((1 < walkAmount ? 1 : walkAmount), right); |
68 this->position = walk_one_step((1 < walkAmount ? 1 : walkAmount), right); |
69 walkAmount--; |
69 walkAmount--; |
70 } |
70 } |
71 // TODO: Should the remaining walkAmount be handled somehow? |
71 // TODO: Should the remaining walkAmount be handled somehow? |
72 } |
72 } |
110 /** |
110 /** |
111 * Updates object speed and position. This function organises force |
111 * Updates object speed and position. This function organises force |
112 * integration and collision detection. |
112 * integration and collision detection. |
113 */ |
113 */ |
114 void PhysicsObject::updatePosition (TimeMS dt) { |
114 void PhysicsObject::updatePosition (TimeMS dt) { |
115 |
|
116 // Reloads weapon if not reloaded |
|
117 reloadTimer -= dt; |
|
118 if(reloadTimer < 0) |
|
119 reloadTimer = 0; |
|
120 |
|
121 // Add gravity to the force queue |
115 // Add gravity to the force queue |
122 forceq.push(world.gravity); |
116 forceq.push(world.gravity); |
123 |
117 |
124 // Go trough every force in the queue |
118 // Go trough every force in the queue |
125 Force total; |
119 Force total; |
328 |
322 |
329 void PhysicsObject::tick (TimeMS tick_length) { |
323 void PhysicsObject::tick (TimeMS tick_length) { |
330 this->updatePosition(tick_length); |
324 this->updatePosition(tick_length); |
331 } |
325 } |
332 |
326 |
333 bool PhysicsObject::canShoot() { |
|
334 return this->reloadTimer <= 0; |
|
335 } |
|
336 |
|
337 void PhysicsObject::draw(CL_GraphicContext *gc) { |
327 void PhysicsObject::draw(CL_GraphicContext *gc) { |
338 CL_Quad player( |
328 CL_Quad player( |
339 (position+shape[0]).x, (position+shape[0]).y, |
329 (position+shape[0]).x, (position+shape[0]).y, |
340 (position+shape[1]).x, (position+shape[1]).y, |
330 (position+shape[1]).x, (position+shape[1]).y, |
341 (position+shape[2]).x, (position+shape[2]).y, |
331 (position+shape[2]).x, (position+shape[2]).y, |