some stuff to Weapon and shoot
authornireco
Fri, 05 Dec 2008 13:13:27 +0000
changeset 213 5bd5afab4673
parent 212 4389c1e6b9b8
child 214 6af842e348a4
some stuff to Weapon and shoot
src/Player.cc
src/Player.hh
--- a/src/Player.cc	Fri Dec 05 12:21:06 2008 +0000
+++ b/src/Player.cc	Fri Dec 05 13:13:27 2008 +0000
@@ -4,11 +4,11 @@
 #include <cstdlib>
 
 Player::Player(GameState &state, Vector position, bool visible) : 
-    PhysicsObject(state.world, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible), arsenal(), selectedWeapon(0) {
+    PhysicsObject(state.world, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible), arsenal(), selectedWeapon(0), changing(false) {
     // 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"));
+        arsenal.push_back(Weapon(10000, (5-i)*40+30, i*6+5, i*100+50, "asdf"));
     }
 
     std::vector<Vector> shape(4);
@@ -46,11 +46,11 @@
     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;
+    float shotspeed = getWeapon().velocity*PHYSICS_TICK_MS/2;
     Vector shotRelativeVelocity = unitVectorAim * shotspeed;
     Vector shotVelocity = this->velocity + shotRelativeVelocity;
     Vector shotPosition = this->position + unitVectorAim*10;
-    new Projectile(this->state, shotPosition, shotVelocity, true, 20);
+    new Projectile(this->state, shotPosition, shotVelocity, true, getWeapon().explosionRadius);
 }
 
 void LocalPlayer::handleMove (PlayerInput_Move input) {
@@ -89,7 +89,15 @@
     }
 
     if (input & INPUT_CHANGE) {
-        selectedWeapon++;
+        if(changing) {
+
+        } else {
+            changing = true;
+            selectedWeapon = (selectedWeapon+1)%arsenal.size();
+            Engine::log(DEBUG, "Player.cc:input ") << "changed weapon " << selectedWeapon;
+        }
+    } else {
+        changing = false;
     }
 
     if (input & INPUT_SHOOT) {
--- a/src/Player.hh	Fri Dec 05 12:21:06 2008 +0000
+++ b/src/Player.hh	Fri Dec 05 13:13:27 2008 +0000
@@ -16,8 +16,8 @@
         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
+        bool changing;
 
         // default constructor for use with virtual inheritance... it's not defined
         Player (void);