--- a/src/Player.cc Thu Dec 04 19:54:51 2008 +0000
+++ b/src/Player.cc Thu Dec 04 21:10:41 2008 +0000
@@ -1,7 +1,8 @@
+#include "Engine.hh"
#include "Player.hh"
Player::Player(GameState &state, Vector position, bool visible) :
- PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) {
+ PhysicsObject(state.world, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) {
std::vector<Vector> shape(4);
shape[0] = Vector(0,-9);
@@ -14,3 +15,76 @@
world.addPlayerObject(this);
}
+/**
+ * shoots the selected weapon.
+ * TODO: selection and weapon information
+ */
+void Player::shoot (void) {
+ // 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;
+ world.addProjectile(new Shot(this->state, this->position, shotVelocity, true));
+}
+
+void Player::handleMove (PlayerInput_Move input) {
+ float fx = 0; // Force in x-direction
+ float da = 0; // Crosshair angle
+
+ // handle left/right
+ if ((input & INPUT_MOVE_LEFT) && (velocity.x > -PLAYER_MAX_SPEED))
+ fx -= PLAYER_MOVE_FORCE;
+
+ if ((input & INPUT_MOVE_RIGHT) && (velocity.x < PLAYER_MAX_SPEED))
+ fx += PLAYER_MOVE_FORCE;
+
+ if (input & INPUT_MOVE_UP)
+ da += CROSSHAIR_ANGLE_SPEED;
+
+ if (input & INPUT_MOVE_DOWN)
+ da -= CROSSHAIR_ANGLE_SPEED;
+
+ if (input & INPUT_MOVE_JUMP) {
+ if ((input & INPUT_MOVE_LEFT))
+ jump(-1);
+ else if ((input & INPUT_MOVE_RIGHT))
+ jump(1);
+ else
+ jump(0);
+ }
+
+ if (input & INPUT_MOVE_DIG) {
+ // Should create Shot which destroys ground, but also should be destroyed then,
+ // but it doesn't.
+ // But this now just segfaults
+// world.addObject(new Shot(state, position, true));
+
+ world.removeGround(position, 15);
+ }
+
+ if (input & INPUT_SHOOT) {
+ this->shoot();
+ }
+
+
+
+ // Player facing
+ if (fx < 0) setFacing(false);
+ else if (fx > 0) setFacing(true);
+
+
+ this->changeAim(da); // Move crosshair
+
+ // Apply force
+ applyForce(Vector(fx, 0));
+
+}
+
+void Player::debugInfo (void) {
+ Engine::log(DEBUG, "Player.debugInfo") << "In air: " << this->inAir;
+}