Documenting more, cleaning variables. This code needs some serious
rewriting. (And we havent too many features either)
#ifndef GAMESTATE_HH
#define GAMESTATE_HH
#include "Physics.hh"
#include "Input.hh"
#include <list>
#include <stdexcept>
#include <cmath>
const float KG_PI = 3.14159265;
// in cells/kg
const uint16_t MAP_WIDTH = 800;
const uint16_t MAP_HEIGHT = 600;
const float MAP_GRAVITY = 1200.0;
const float COLLISION_ELASTICITY = 0.4;
const float PLAYER_MASS = 10.0;
const float PLAYER_MOVE_FORCE = 5000.0;
const float PLAYER_INITIAL_X = 400.0;
const float PLAYER_INITIAL_Y = 300.0;
const float PLAYER_MIN_SPEED = 10.0;
const float CROSSHAIR_ANGLE_SPEED = PI/40; // TODO: Adjust this
const float PLAYER_AIM_MIN = -KG_PI/4; // TODO: -- || --
const float PLAYER_AIM_MAX = KG_PI/2; // TODO: -- || --
// forward-declare GameState
class GameState;
class Player : public PhysicsObject {
protected:
GameState &state;
bool visible;
public:
Player(GameState &state, Vector position, bool visible) :
PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) {
std::vector<Vector> shape(4);
shape[0] = Vector(0,-18);
shape[1] = Vector(6,-9);
shape[2] = Vector(0,0);
shape[3] = Vector(-6,-9);
// Initialize the shape of the player (salmiakki shape)
setShape(shape);
}
void debugInfo ();
public:
virtual void handleMove (PlayerInput_Move input);
};
class Shot : public PhysicsObject {
protected:
GameState &state;
bool visible;
uint32_t birth_tick;
uint32_t death_tick;
public:
Shot(GameState &state, Vector position, bool visible) :
PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) {
// Looks kind of dumb, for ammunition to have shape
std::vector<Vector> shape(4);
shape[0] = Vector(-1, -1);
shape[1] = Vector(-1, 1);
shape[2] = Vector(1, 1);
shape[3] = Vector(1, -1);
setShape(shape);
}
private:
virtual void onCollision();
};
class LocalPlayer : public Player {
protected:
LocalPlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
};
class RemotePlayer : public Player {
protected:
RemotePlayer (GameState &state, Vector pos, bool visible) : Player(state, pos, visible) { }
};
class GameState : public PhysicsWorld {
public:
std::list<Player*> player_list;
// only one local player is supported
LocalPlayer *local_player;
GameState (void) : PhysicsWorld(Vector(0, MAP_GRAVITY), Vector(MAP_WIDTH, MAP_HEIGHT)), local_player(NULL) {
}
/*
* This will return NULL if we don't have a local player - yet
*/
LocalPlayer *getLocalPlayer (void) {
return local_player;
}
void 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;
}
void newRemotePlayer (RemotePlayer *player) {
player_list.push_back(player);
}
void removePlayer (Player *player) {
player_list.remove(player);
}
};
#endif