YAPOG  0.0.1
Yet Another Pokemon Online Game
Game.cpp
Go to the documentation of this file.
1 #include <ctime>
2 
43 
44 #include "Client/Session.hpp"
45 #include "Game.hpp"
57 #include "Pokemon/PokemonInfo.hpp"
58 #include "Pokemon/PokemonInfoReader.hpp"
59 #include "World/Map/MapReader.hpp"
60 #include "World/Map/Map.hpp"
61 #include "World/Map/Player.hpp"
62 #include "World/Map/PlayerReader.hpp"
63 #include "World/Map/MapElement.hpp"
64 #include "World/Map/MapElementReader.hpp"
65 #include "World/Map/NPC.hpp"
66 #include "World/Map/NPCReader.hpp"
67 #include "World/Map/Teleporter.hpp"
68 #include "World/Map/DestructibleObject.hpp"
69 #include "World/Map/DestructibleObjectReader.hpp"
70 #include "World/Map/OpenBattleSpawnerArea.hpp"
71 #include "World/Map/OpenBattleSpawnerAreaReader.hpp"
72 #include "Battle/PlayerTrainer.hpp"
73 #include "Pokemon/PokemonTeam.hpp"
74 
75 namespace ycl
76 {
77  const yap::Vector2 Game::SCREEN_SIZE = yap::Vector2 (800, 600);
78 
79  Game::Game (const yap::String& name)
80  : yap::Game (name)
81  , session_ (Session::Instance ())
82  , contentManager_ (yap::ContentManager::Instance ())
83  , objectFactory_ (yap::ObjectFactory::Instance ())
84  , worldObjectStateFactory_ (yap::WorldObjectStateFactory::Instance ())
85  , gameInputManager_ (yap::GameInputManager::Instance ())
86  , logger_ (yap::DebugLogger::Instance ())
87  {
88  }
89 
91  {
92  }
93 
95  {
96  InitRandom ();
97 
99 
105 
107  }
108 
109  bool Game::HandleOnEvent (const yap::GuiEvent& guiEvent)
110  {
111  switch (guiEvent.type)
112  {
113  case yap::GuiEventType::Closed:
114 
115  window_->close ();
116 
117  return true;
118 
119  default:
120  break;
121  }
122 
123  return yap::Game::HandleOnEvent (guiEvent);
124  }
125 
127  const yap::Time& dt,
128  yap::IDrawingContext& context)
129  {
130  session_.Refresh ();
131 
132  // Update player's game time
134 
135  yap::Game::HandleRun (dt, context);
136  }
137 
139  {
141 
142  session_.Disconnect ();
143  }
144 
146  {
147  yap::RandomHelper::Init (time (nullptr));
148  }
149 
150  void Game::InitContentManager (const yap::Path& contentRootPath)
151  {
152  contentManager_.Init (contentRootPath);
153 
158  }
159 
161  {
163  "AnimatedSprite",
167 
169  "DestructibleObject",
173  yap::Path ("DestructibleObject"),
174  "DestructibleObject"));
175 
177  "DirectionSpriteSet",
181 
183  "Map",
185  yap::Path ("Map"),
186  "Map"));
187 
189  "MapElement",
191  yap::Path ("MapElement"),
192  "MapElement"));
193 
195  "NPC",
197  yap::Path ("NPC"),
198  "NPC"));
199 
201  "OpenBattleSpawnerArea",
205  yap::Path ("OpenBattleSpawnerArea"),
206  "OpenBattleSpawnerArea"));
207 
209  "Player",
211  yap::Path ("Player"),
212  "Player"));
213 
215  "Teleporter",
217  yap::Path ("Teleporter"),
218  "Teleporter"));
219 
221  "RandomTileLayoutHandler",
225 
227  "SelectionTileLayoutHandler",
231 
233  "Sprite",
235 
237  "StringSpriteSet",
241 
243  "Texture",
245  yap::Path ("Texture"),
246  "Texture"));
247 
249  "Tile",
251  yap::Path ("Tile"),
252  "Tile"));
253 
255  "PokemonInfo",
257  yap::Path ("Pokemon/Pokemon"),
258  "PokemonInfo"));
259 
261  "NatureInfo",
263  yap::Path ("Pokemon/Nature"),
264  "Nature"));
265 
267  "TypeInfo",
269  yap::Path ("Pokemon/Types"),
270  "Type"));
271 
273  "SkillInfo",
275  yap::Path ("Pokemon/Skills"),
276  "Skill"));
277  }
278 
280  {
281  worldObjectStateFactory_.AddState ("Inactive", "Inactive");
282  worldObjectStateFactory_.AddState ("Moving", "Moving");
283  }
284 
286  {
288 
290  new yap::GameInput (
292  new yap::KeyboardGameInputEntry (yap::Key::A)));
294  new yap::GameInput (
296  new yap::KeyboardGameInputEntry (yap::Key::Return)));
298  new yap::GameInput (
300  new yap::KeyboardGameInputEntry (yap::Key::M)));
302  new yap::GameInput (
306  new yap::GameInput (
310  new yap::GameInput (
314  new yap::GameInput (
317  }
318 
319  void Game::InitDrawingContext (const yap::Vector2& resolution)
320  {
321  yap::DrawingContext* drawingContext = new yap::DrawingContext (
322  resolution,
323  name_);
324 
325  drawingContext_ = drawingContext;
326 
328  "World",
329  new yap::Camera (yap::Vector2 (), resolution));
330 
332  "Background World",
333  new yap::Camera (yap::Vector2 (), resolution));
334 
336  "Gui", new yap::Camera (yap::Vector2 (), resolution));
337 
339  "Battle", new yap::Camera (yap::Vector2 (), resolution));
340 
341  window_ = &drawingContext->GetWindow ();
342  }
343 
345  {
347 
356  new RegistrationScreen (
357  *drawingContext_));
360 
361  GetScreenManager ().Init ("Loading");
362  }
363 
365  {
368  }
369 } // namespace ycl