--- a/src/proto2/GameState.cc Tue Dec 02 01:46:18 2008 +0000
+++ b/src/proto2/GameState.cc Wed Dec 03 12:09:42 2008 +0000
@@ -2,6 +2,10 @@
#include "GameState.hh"
#include "Engine.hh"
+void Player::shoot (void) {
+ this->state.addProjectile(new Shot(this->state, this->position, true));
+}
+
void Player::handleMove (PlayerInput_Move input) {
float fx = 0; // Force in x-direction
float da = 0; // Crosshair angle
--- a/src/proto2/GameState.hh Tue Dec 02 01:46:18 2008 +0000
+++ b/src/proto2/GameState.hh Wed Dec 03 12:09:42 2008 +0000
@@ -31,10 +31,8 @@
}
void debugInfo ();
-
-public:
virtual void handleMove (PlayerInput_Move input);
-
+ void shoot (void);
};
--- a/src/proto2/Graphics.cc Tue Dec 02 01:46:18 2008 +0000
+++ b/src/proto2/Graphics.cc Wed Dec 03 12:09:42 2008 +0000
@@ -51,6 +51,11 @@
if (keyboard.get_keycode(CL_KEY_I))
player->debugInfo();
+
+ if (keyboard.get_keycode(CL_KEY_F)) {
+ Engine::log(DEBUG, "Graphics.check_input") << "Fire!";
+ player->shoot();
+ }
if (keyboard.get_keycode(CL_KEY_M))
input_move |= INPUT_MOVE_DIG;
@@ -75,6 +80,12 @@
p->draw(gc);
}
+ // Draw projectiles
+ for (std::list<PhysicsObject*>::iterator it = state.projectiles.begin(); it != state.projectiles.end(); it++) {
+ PhysicsObject *po = *it;
+ po->draw(gc);
+ }
+
// Flip window buffer, LIEK NAO
win.flip(0);
}
--- a/src/proto2/Physics.cc Tue Dec 02 01:46:18 2008 +0000
+++ b/src/proto2/Physics.cc Wed Dec 03 12:09:42 2008 +0000
@@ -20,6 +20,10 @@
objects.push_back(object);
}
+void PhysicsWorld::addProjectile (PhysicsObject *projectile) {
+ projectiles.push_back(projectile);
+}
+
void PhysicsWorld::tick () {
// Engine::log(DEBUG, "physics.apply_force") << "*tick*";
--- a/src/proto2/Physics.hh Tue Dec 02 01:46:18 2008 +0000
+++ b/src/proto2/Physics.hh Wed Dec 03 12:09:42 2008 +0000
@@ -3,6 +3,7 @@
#include <vector>
#include <queue>
+#include <list>
#include <ClanLib/core.h>
#include <ClanLib/display.h>
@@ -37,7 +38,6 @@
protected:
//std::vector<PlayerObject*> players;
- //std::vector<ProjectileObject*> projectiles;
std::vector<PhysicsObject*> objects;
// Contains connections between signals and slots
@@ -62,6 +62,8 @@
* @param object Pointer to the PhysicsObject to add.
*/
void addObject(PhysicsObject *object);
+
+ void addProjectile(PhysicsObject *projectile);
/**
* Advance one time step in physics simulation.
@@ -75,6 +77,9 @@
*/
uint32_t getTick();
+
+ // TODO This should probably be protected or in GameStat or in GameStatee
+ std::list<PhysicsObject*> projectiles;
};
/**