src/proto2/GameState.cc
changeset 182 84675387ca74
parent 180 bfe1077edab3
child 183 e31ff2152774
--- a/src/proto2/GameState.cc	Wed Dec 03 12:21:38 2008 +0000
+++ b/src/proto2/GameState.cc	Wed Dec 03 14:25:23 2008 +0000
@@ -1,9 +1,23 @@
 
 #include "GameState.hh"
 #include "Engine.hh"
+#include "Config.hh"
 
+/**
+ * shoots the selected weapon.
+ * TODO: selection and weapon information
+ */
 void Player::shoot (void) {
-    this->state.addProjectile(new Shot(this->state, this->position, true));
+    // here should be somehow considered which projectile it is
+    if(!canShoot())
+        return;
+    reloadTimer += 0;
+    Vector unitVectorAim = facingRight ? Vector(std::cos(aim), -std::sin(aim)) : 
+            Vector(-std::cos(aim), -std::sin(aim));
+    float shotspeed = 100*PHYSICS_TICK_MS;
+    Vector shotRelativeVelocity = unitVectorAim * shotspeed;
+    Vector shotVelocity = this->velocity + shotRelativeVelocity;
+    this->state.addProjectile(new Shot(this->state, this->position, shotVelocity, true));
 }
 
 void Player::handleMove (PlayerInput_Move input) {
@@ -50,6 +64,10 @@
 
         world.removeGround(position, 15);
     }
+
+    if (input & INPUT_SHOOT) {
+        this->shoot();
+    }
 }
 
 void Player::debugInfo (void) {
@@ -57,5 +75,36 @@
 }
 
 void Shot::onCollision() {
-//    world.removeGround(position, 20);
+    world.removeGround(position, 20);
 }
+
+void Shot::draw(CL_GraphicContext *gc) {
+
+
+    CL_Quad player(
+                   (position).x+1, (position).y+1,
+                   (position).x-1, (position).y+1,
+                   (position).x+1, (position).y-1,
+                   (position).x-1, (position).y-1
+                   );
+
+    gc->fill_quad(player, CL_Color::green);
+
+    const uint16_t chlen = 10;
+    uint16_t x = player.center().x;
+    uint16_t y = player.center().y;
+    if(target_visible) {
+        if (facingRight) {
+            gc->draw_line(x, y,
+                          x + std::cos(aim)*chlen,
+                          y - std::sin(aim)*chlen,
+                          CL_Color::black);
+        } else {
+            gc->draw_line(x, y,
+                          x - std::cos(aim)*chlen,
+                          y - std::sin(aim)*chlen,
+                          CL_Color::black);
+        }
+    }
+}
+