--- a/src/Graphics.cc Fri Dec 05 11:11:38 2008 +0000
+++ b/src/Graphics.cc Fri Dec 05 12:21:06 2008 +0000
@@ -52,9 +52,11 @@
player->debugInfo();
if (keyboard.get_keycode(CL_KEY_F)) {
- Engine::log(DEBUG, "Graphics.check_input") << "Fire!";
input_move |= INPUT_SHOOT;
}
+
+ if (keyboard.get_keycode(CL_KEY_D))
+ input_move |= INPUT_CHANGE;
if (keyboard.get_keycode(CL_KEY_M))
input_move |= INPUT_MOVE_DIG;
--- a/src/Input.hh Fri Dec 05 11:11:38 2008 +0000
+++ b/src/Input.hh Fri Dec 05 12:21:06 2008 +0000
@@ -14,6 +14,7 @@
INPUT_MOVE_JUMP = 0x0010,
INPUT_MOVE_DIG = 0x0020,
INPUT_SHOOT = 0x0040,
+ INPUT_CHANGE = 0x0080,
};
typedef uint16_t PlayerInput_Move;
--- a/src/Player.cc Fri Dec 05 11:11:38 2008 +0000
+++ b/src/Player.cc Fri Dec 05 12:21:06 2008 +0000
@@ -4,7 +4,12 @@
#include <cstdlib>
Player::Player(GameState &state, Vector position, bool visible) :
- PhysicsObject(state.world, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) {
+ PhysicsObject(state.world, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible), arsenal(), selectedWeapon(0) {
+ // TODO: arsenal's size should be affected by some value
+ // and weapons should be loaded from somewhere, not generated here
+ for(int i = 0; i < 5; i++) {
+ arsenal.push_back(Weapon(10000, i*20+30, i*2+3, i*100+50, "asdf"));
+ }
std::vector<Vector> shape(4);
shape[0] = Vector(0,-9);
@@ -38,7 +43,7 @@
// here should be somehow considered which projectile it is
if(!canShoot())
return;
- reloadTimer += 50;
+ reloadTimer += getWeapon().reloadTime;
Vector unitVectorAim = facingRight ? Vector(std::cos(aim), -std::sin(aim)) :
Vector(-std::cos(aim), -std::sin(aim));
float shotspeed = 100*PHYSICS_TICK_MS/2;
@@ -83,6 +88,10 @@
handleDig(position, 15);
}
+ if (input & INPUT_CHANGE) {
+ selectedWeapon++;
+ }
+
if (input & INPUT_SHOOT) {
this->shoot();
}
@@ -101,3 +110,6 @@
}
+Weapon& Player::getWeapon() {
+ return arsenal[selectedWeapon%arsenal.size()];
+}
--- a/src/Player.hh Fri Dec 05 11:11:38 2008 +0000
+++ b/src/Player.hh Fri Dec 05 12:21:06 2008 +0000
@@ -8,18 +8,25 @@
#include "GameState.hh"
#include "PhysicsObject.hh"
#include "Input.hh"
+#include "Weapon.hh"
+#include <vector>
class Player : public PhysicsObject {
protected:
GameState &state;
bool visible;
-
+ std::vector<Weapon> arsenal;
+ //keep selectedWeapon in form of index+arsenal.size() to prevent underflow.. just a vision
+ unsigned int selectedWeapon; //unsigned for x%sW not to fail
+
// default constructor for use with virtual inheritance... it's not defined
Player (void);
Player (GameState &state, Vector position, bool visible);
virtual void handleDig (Vector position, float radius);
+ Weapon& getWeapon();
+
public:
void debugInfo ();
};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Weapon.cc Fri Dec 05 12:21:06 2008 +0000
@@ -0,0 +1,9 @@
+#include "Weapon.hh"
+
+Weapon::Weapon(TickCount age, float velocity, float explosionRadius, int reloadTime, std::string name)
+ : age(age), velocity(velocity), explosionRadius(explosionRadius), reloadTime(reloadTime), name(name) {
+}
+
+Weapon::Weapon(const Weapon& orig)
+ : age(orig.age), velocity(orig.velocity), explosionRadius(orig.explosionRadius), reloadTime(orig.reloadTime), name(orig.name) {
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Weapon.hh Fri Dec 05 12:21:06 2008 +0000
@@ -0,0 +1,35 @@
+#ifndef WEAPON_HH
+#define WEAPON_HH
+
+#include "Timer.hh"
+#include <string>
+
+class Weapon {
+public:
+/* const TickCount age;
+ const float velocity;
+ const float explosionRadius;
+ const int reloadTime; //in ms
+
+ const int clipSize;
+ const bool visible;
+
+ const std::string name;
+*/
+
+ TickCount age;
+ float velocity;
+ float explosionRadius;
+ int reloadTime; //in ms
+
+ int clipSize;
+ bool visible;
+
+ std::string name;
+
+ Weapon(TickCount age, float velocity, float explosionRadius, int reloadTime, std::string name);
+
+ Weapon(const Weapon& orig);
+};
+
+#endif