Roguelike
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
gamecontroller.h
Go to the documentation of this file.
1 #ifndef ROGUELIKE_BASE_GAMECONTROLLER_H_
2 #define ROGUELIKE_BASE_GAMECONTROLLER_H_
3 
4 // Inheritance
5 #include <ugdk/action/scene.h>
6 
7 // External Dependencies
8 #include <list> // template class, also needed for push_back(-)
9 #include <set> // template class, needed for ObjectsAt(-)
10 #include <vector> // template class, also needed for size(-)
11 #include <ugdk/math/integer2D.h> // needed for Tile
12 #include <ugdk/math/vector2D.h> // needed for map_size_
13 
14 // Internal Dependencies
16 
17 // Forward Declarations
18 #include "game/base.h"
19 
20 namespace game {
21 namespace base {
22 
23 class GameController : public ugdk::action::Scene {
24  typedef ugdk::action::Scene super;
25  static GameController* reference_;
26 
27  public:
28  static const ugdk::math::Integer2D TILE_SIZE;
29 
30  static GameController* reference();
32 
33  void AddGameObject(GameObject* game_object);
34 
35  const ugdk::math::Integer2D& map_size() const { return map_size_; }
36 
37  bool TileOutOfBounds(int x, int y) const {
38  return y < 0 || y >= (int)(tiles_.size()) || x < 0 || x >= (int)(tiles_[y].size());
39  }
40  bool TileOutOfBounds(const ugdk::math::Integer2D& coords) const {
41  return TileOutOfBounds(coords.x, coords.y);
42  }
43 
44  GameTile* Tile(int x, int y) const {
45  if( !TileOutOfBounds(x,y) )
46  return tiles_[y][x];
47  return nullptr;
48  }
49  GameTile* Tile(const ugdk::math::Integer2D& coords) const {
50  return Tile(coords.x, coords.y);
51  }
52 
53  const std::set<GameObject*>& ObjectsAt(const ugdk::math::Integer2D& coords);
54  const std::set<GameObject*>& ObjectsAt(int x, int y) { return ObjectsAt(ugdk::math::Integer2D(x,y)); }
55 
56  void AdjustCamera();
57  void Spawn();
58  void SpawnMonster();
59  void ClearActorsList() { actors_.clear(); }
60  void DeleteAllActors();
61  void RequireBlackout() { needs_blackout_ = true; }
62  bool TilesNeededBlackout(GameObject* owner);
63  void BlackoutTiles();
64  void ShowTileAsVisible(const ugdk::math::Integer2D& tile);
65  void LightHeroVisibleTiles();
66  //void PassTime(double dt) { time_since_beggining_ += dt; }
67  void RemoveActor(GameObject* actor);
68  void PropagateSound(const ugdk::math::Integer2D& origin, int noise_level);
69 
70  int current_tick() { return current_tick_; }
71 
72  void set_current_tick(int current_tick) { current_tick_ = current_tick; }
73  void set_hero(GameObject* hero) { hero_ = hero; }
74  void set_tiles(std::vector< std::vector<GameTile*> > tiles) { tiles_ = tiles; }
75  void set_map_size(ugdk::math::Integer2D map_size) { map_size_ = map_size; }
76 
77  std::vector<base::GameObject*> actors() { return actors_; }
78  base::GameObject* hero() { return hero_; }
79 
80  private:
82 
83  int current_tick_;
84  int monster_spawn_counter_;
85 
86  void clearDeadGameObjects();
87  void addPendingGameObjects();
88 
89  ugdk::math::Integer2D map_size_;
90  std::vector< std::vector<GameTile*> > tiles_;
91 
92  GameObject* hero_;
93  std::vector<base::GameObject*> actors_;
94 
95  double time_since_beggining_;
96  bool needs_blackout_;
97 };
98 
99 } // namespace base
100 } // namespace game
101 
102 #endif // ROGUELIKE_BASE_GAMECONTROLLER_H_
Definition: gameobject.h:53
bool TilesNeededBlackout(GameObject *owner)
Definition: gamecontroller.cc:99
const std::set< GameObject * > & ObjectsAt(int x, int y)
Definition: gamecontroller.h:54
void BlackoutTiles()
Definition: gamecontroller.cc:106
void RemoveActor(GameObject *actor)
Definition: gamecontroller.cc:136
bool TileOutOfBounds(int x, int y) const
Definition: gamecontroller.h:37
bool TileOutOfBounds(const ugdk::math::Integer2D &coords) const
Definition: gamecontroller.h:40
static const ugdk::math::Integer2D TILE_SIZE
Definition: gamecontroller.h:28
GameTile * Tile(const ugdk::math::Integer2D &coords) const
Definition: gamecontroller.h:49
void set_tiles(std::vector< std::vector< GameTile * > > tiles)
Definition: gamecontroller.h:74
void Spawn()
Definition: gamecontroller.cc:72
void ClearActorsList()
Definition: gamecontroller.h:59
void AddGameObject(GameObject *game_object)
Definition: gamecontroller.cc:93
Definition: aim.cc:15
~GameController()
Definition: gamecontroller.cc:67
const ugdk::math::Integer2D & map_size() const
Definition: gamecontroller.h:35
const std::set< GameObject * > & ObjectsAt(const ugdk::math::Integer2D &coords)
base::GameObject * hero()
Definition: gamecontroller.h:78
Definition: gametile.h:21
void LightHeroVisibleTiles()
Definition: gamecontroller.cc:130
static GameController * reference()
Definition: gamecontroller.cc:52
GameTile * Tile(int x, int y) const
Definition: gamecontroller.h:44
int current_tick()
Definition: gamecontroller.h:70
void set_hero(GameObject *hero)
Definition: gamecontroller.h:73
void set_current_tick(int current_tick)
Definition: gamecontroller.h:72
void ShowTileAsVisible(const ugdk::math::Integer2D &tile)
Definition: gamecontroller.cc:119
Definition: gamecontroller.h:23
void AdjustCamera()
Definition: gamecontroller.cc:185
void PropagateSound(const ugdk::math::Integer2D &origin, int noise_level)
Definition: gamecontroller.cc:140
void set_map_size(ugdk::math::Integer2D map_size)
Definition: gamecontroller.h:75
void SpawnMonster()
Definition: gamecontroller.cc:89
std::vector< base::GameObject * > actors()
Definition: gamecontroller.h:77
void RequireBlackout()
Definition: gamecontroller.h:61