--- a/src/GameState.cc Thu Dec 04 19:54:51 2008 +0000
+++ b/src/GameState.cc Thu Dec 04 21:10:41 2008 +0000
@@ -3,116 +3,29 @@
#include "Engine.hh"
#include "Config.hh"
-/**
- * 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;
- this->state.addProjectile(new Shot(this->state, this->position, shotVelocity, true));
+GameState::GameState (void) : local_player(NULL), world(Vector(0, MAP_GRAVITY), Vector(MAP_WIDTH, MAP_HEIGHT)) { }
+
+LocalPlayer *GameState::getLocalPlayer (void) {
+ return local_player;
}
-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;
+void GameState::newLocalPlayer (LocalPlayer *player) {
+ if (local_player)
+ throw std::logic_error("newLocalPlayer called even though we already have a local player");
+
+ player_list.push_back(player);
+
+ local_player = player;
+}
- if (input & INPUT_MOVE_JUMP) {
- if ((input & INPUT_MOVE_LEFT))
- jump(-1);
- else if ((input & INPUT_MOVE_RIGHT))
- jump(1);
- else
- jump(0);
- }
+void GameState::newRemotePlayer (RemotePlayer *player) {
+ player_list.push_back(player);
+}
- 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();
- }
+void GameState::removePlayer (Player *player) {
+ player_list.remove(player);
+}
- // 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;
-}
-
-void Shot::onCollision() {
- world.removeGround(position, 20);
- this->destroyed = true;
-}
-
-bool Shot::isDestroyed (void) {
- return this->destroyed;
-}
-
-void Shot::draw(CL_GraphicContext *gc) {
-
- CL_Quad player(
- (int)((position).x+1), (int)((position).y+1),
- (int)((position).x-1), (int)((position).y+1),
- (int)((position).x+1), (int)((position).y-1),
- (int)((position).x-1), (int)((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);
- }
- }
-}
-