src/GameState.hh
author Tero Marttila <terom@fixme.fi>
Tue, 13 Jan 2009 23:15:47 +0200
changeset 393 5dd4d782cf3a
parent 274 c35307e8645c
child 408 e6cfc44266af
permissions -rw-r--r--
a basic implementation of game messages, plus some weird GameStateEvent stuff
#ifndef GAMESTATE_HH
#define GAMESTATE_HH

class GameState;

#include "PhysicsWorld.hh"
#include "Player.hh"
#include "Projectile.hh"
#include "Rope.hh"
#include "Input.hh"
#include "GraphicsPointer.hh"
#include "Config.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:
    std::list<Player*> player_list;
    std::list<Projectile*> projectiles;
    PhysicsWorld world;

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

public:    
    /**
     * ...
     * 
     * This should take some arguments
     */
    GameState (void);

    /**
     * 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);
    
    /**
     * Draws the terrain, players and projectiles
     */
    virtual void draw (Graphics *g, PixelCoordinate camera, bool displayWeapon);
};

#endif