src/GameState.hh
author nireco
Sat, 31 Jan 2009 12:33:08 +0200
changeset 443 5d1119729f58
parent 417 c503e0c6a740
permissions -rw-r--r--
worm02 two pics to comment
#ifndef GAMESTATE_HH
#define GAMESTATE_HH

class GameState;

#include "PhysicsWorld.hh"
#include "Terrain.hh"
#include "Player.hh"
#include "Projectile.hh"
#include "Config.hh"

#include "Graphics/Drawable.hh"

#include <list>
#include <stdexcept>
#include <cmath>

class GameStateEventHandler {
    friend class GameState;

    protected:
        virtual void on_player_joined (Player *p) = 0;
        virtual void on_player_left (Player *p) = 0;
};

class GameState {
public:
    /**
     * All active players
     */
    std::list<Player*> player_list;

    /**
     * All active projectiles
     */
    std::list<Projectile*> projectiles;

    /**
     * Our world simulation
     */
    PhysicsWorld world;
    
    /**
     * Our terrain
     */
    Terrain &terrain;

    /**
     * The one LocalPlayer that *we* control
     */
    LocalPlayer *local_player;
    
protected:
    /**
     * Notify someone about events?
     */
    GameStateEventHandler *event_handler;

public:    
    /**
     * Create the game world, using the given terrain
     *
     * @param terrain the world's terrain
     */
    GameState (Terrain &terrain);

    /**
     * Set event handler, only one can be set
     */
    void setEventHandler (GameStateEventHandler *handler);
    
    /**
     * Adds projectile to our list of projectiles to draw
     */
    void addProjectile(Projectile *projectile);

    /**
     * Get our current LocalPlayer if we have one, else return NULL (client hasn't connected yet)
     */
    LocalPlayer *getLocalPlayer (void);
    
    /**
     * Check that local_player is NULL, and sets it to the given player
     */
    void setLocalPlayer (LocalPlayer *player);        

    /**
     * Add the given player to our player_list
     */
    void addPlayer (Player *player);
    
    /**
     * Removes the given player from player_list. If the given player was the local_player, set that to NULL
     */
    void removePlayer (Player *player);

#if GRAPHICS_ENABLED    
    /**
     * Draws the terrain, players and projectiles
     */
    virtual void draw (graphics::Display &display, PixelCoordinate camera, bool displayWeapon);
#endif
};

#endif