YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
Game.cpp
Go to the documentation of this file.
1
#include <ctime>
2
3
#include "
YAPOG/Content/ContentManager.hpp
"
4
#include "
YAPOG/Game/Factory/ObjectFactory.hpp
"
5
#include "
YAPOG/Game/Factory/XmlObjectIDLoader.hpp
"
6
#include "
YAPOG/Game/Factory/XmlObjectLoader.hpp
"
7
#include "
YAPOG/Game/World/Map/WorldObjectStateFactory.hpp
"
8
#include "
YAPOG/Graphics/Camera.hpp
"
9
#include "
YAPOG/Graphics/DrawingContext.hpp
"
10
#include "
YAPOG/Graphics/Game/GameScreenManager.hpp
"
11
#include "
YAPOG/Graphics/Game/Sprite/AnimatedSpriteReader.hpp
"
12
#include "
YAPOG/Graphics/Game/Sprite/SpriteSet.hpp
"
13
#include "
YAPOG/Graphics/Game/Sprite/SpriteSetReader.hpp
"
14
#include "
YAPOG/Graphics/Gui/GameInput/GameInputManager.hpp
"
15
#include "
YAPOG/Graphics/Gui/GameInput/KeyboardGameInputEntry.hpp
"
16
#include "
YAPOG/System/IO/Log/CountLoggerMode.hpp
"
17
#include "
YAPOG/System/IO/Log/DebugLogger.hpp
"
18
#include "
YAPOG/System/IO/Log/TimeLoggerMode.hpp
"
19
#include "
YAPOG/System/RandomHelper.hpp
"
20
#include "
YAPOG/Graphics/Game/World/Map/Tile.hpp
"
21
#include "
YAPOG/Graphics/Game/World/Map/TileReader.hpp
"
22
#include "
YAPOG/Graphics/Game/Sprite/Sprite.hpp
"
23
#include "
YAPOG/Graphics/Game/Sprite/SpriteReader.hpp
"
24
#include "
YAPOG/Graphics/Game/World/Map/RandomTileLayoutHandler.hpp
"
25
#include "
YAPOG/Graphics/Game/World/Map/RandomTileLayoutHandlerReader.hpp
"
26
#include "
YAPOG/Graphics/Game/World/Map/SelectionTileLayoutHandler.hpp
"
27
#include "
YAPOG/Graphics/Game/World/Map/SelectionTileLayoutHandlerReader.hpp
"
28
#include "
YAPOG/Graphics/Texture.hpp
"
29
#include "
YAPOG/Graphics/TextureReader.hpp
"
30
#include "
YAPOG/Graphics/Game/Sprite/RegularAnimatedSprite.hpp
"
31
#include "
YAPOG/Game/Pokemon/PokemonInfoReader.hpp
"
32
#include "
YAPOG/Game/Pokemon/PokemonInfo.hpp
"
33
#include "
YAPOG/Game/Pokemon/NatureInfoReader.hpp
"
34
#include "
YAPOG/Game/Pokemon/NatureInfo.hpp
"
35
#include "
YAPOG/Game/Pokemon/TypeInfoReader.hpp
"
36
#include "
YAPOG/Game/Pokemon/TypeInfo.hpp
"
37
#include "
YAPOG/Game/Pokemon/SkillInfoReader.hpp
"
38
#include "
YAPOG/Game/Pokemon/SkillInfo.hpp
"
39
#include "
YAPOG/Game/Pokemon/PokemonTeam.hpp
"
40
#include "
YAPOG/Game/Battle/PokemonFighter.hpp
"
41
#include "
YAPOG/Game/Battle/PokemonFighterTeam.hpp
"
42
#include "
YAPOG/Game/World/Map/TeleporterReader.hpp
"
43
44
#include "
Client/Session.hpp
"
45
#include "Game.hpp"
46
#include "
Configuration/GameData.hpp
"
47
#include "
GameScreen/LoadingScreen.hpp
"
48
#include "
GameScreen/UpdateScreen.hpp
"
49
#include "
GameScreen/OptionScreen.hpp
"
50
#include "
GameScreen/LoginScreen.hpp
"
51
#include "
GameScreen/GameplayScreen.hpp
"
52
#include "
GameScreen/BattleScreen.hpp
"
53
#include "
GameScreen/MainMenuScreen.hpp
"
54
#include "
GameScreen/CreditScreen.hpp
"
55
#include "
GameScreen/RegistrationScreen.hpp
"
56
#include "
GameScreen/SplashScreen.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
90
Game::~Game
()
91
{
92
}
93
94
void
Game::HandleInit
()
95
{
96
InitRandom
();
97
98
InitContentManager
(
yap::Path
(
GameData::ContentPath
()));
99
100
InitObjectFactory
();
101
InitGameInputManager
();
102
InitWorldObjectStateFactory
();
103
InitDrawingContext
(
GameData::WindowSize
());
104
InitScreenManager
();
105
106
InitLoggerManager
();
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
126
void
Game::HandleRun
(
127
const
yap::Time
& dt,
128
yap::IDrawingContext
& context)
129
{
130
session_
.
Refresh
();
131
132
// Update player's game time
133
session_
.
GetUser
().
UpdatePlayTime
(dt);
134
135
yap::Game::HandleRun
(dt, context);
136
}
137
138
void
Game::HandleDispose
()
139
{
140
yap::Game::HandleDispose
();
141
142
session_
.
Disconnect
();
143
}
144
145
void
Game::InitRandom
()
146
{
147
yap::RandomHelper::Init
(time (
nullptr
));
148
}
149
150
void
Game::InitContentManager
(
const
yap::Path
& contentRootPath)
151
{
152
contentManager_
.
Init
(contentRootPath);
153
154
contentManager_
.
SetTexturePath
(
yap::Path
(
GameData::TexturePath
()));
155
contentManager_
.
SetFontPath
(
yap::Path
(
GameData::FontPath
()));
156
contentManager_
.
SetMusicPath
(
yap::Path
(
GameData::MusicPath
()));
157
contentManager_
.
SetSoundBufferPath
(
yap::Path
(
GameData::SoundPath
()));
158
}
159
160
void
Game::InitObjectFactory
()
161
{
162
objectFactory_
.
RegisterLoader
(
163
"AnimatedSprite"
,
164
new
yap::XmlObjectLoader
<
165
yap::RegularAnimatedSprite
,
166
yap::AnimatedSpriteReader
> ());
167
168
objectFactory_
.
RegisterLoader
(
169
"DestructibleObject"
,
170
new
yap::XmlObjectIDLoader
<
171
DestructibleObject
,
172
DestructibleObjectReader
> (
173
yap::Path
(
"DestructibleObject"
),
174
"DestructibleObject"
));
175
176
objectFactory_
.
RegisterLoader
(
177
"DirectionSpriteSet"
,
178
new
yap::XmlObjectLoader
<
179
yap::SpriteSet<yap::Direction>
,
180
yap::SpriteSetReader<yap::Direction>
> ());
181
182
objectFactory_
.
RegisterLoader
(
183
"Map"
,
184
new
yap::XmlObjectIDLoader<Map, MapReader>
(
185
yap::Path
(
"Map"
),
186
"Map"
));
187
188
objectFactory_
.
RegisterLoader
(
189
"MapElement"
,
190
new
yap::XmlObjectIDLoader<MapElement, MapElementReader>
(
191
yap::Path
(
"MapElement"
),
192
"MapElement"
));
193
194
objectFactory_
.
RegisterLoader
(
195
"NPC"
,
196
new
yap::XmlObjectIDLoader<NPC, NPCReader>
(
197
yap::Path
(
"NPC"
),
198
"NPC"
));
199
200
objectFactory_
.
RegisterLoader
(
201
"OpenBattleSpawnerArea"
,
202
new
yap::XmlObjectIDLoader
<
203
OpenBattleSpawnerArea
,
204
OpenBattleSpawnerAreaReader
> (
205
yap::Path
(
"OpenBattleSpawnerArea"
),
206
"OpenBattleSpawnerArea"
));
207
208
objectFactory_
.
RegisterLoader
(
209
"Player"
,
210
new
yap::XmlObjectIDLoader<Player, PlayerReader>
(
211
yap::Path
(
"Player"
),
212
"Player"
));
213
214
objectFactory_
.
RegisterLoader
(
215
"Teleporter"
,
216
new
yap::XmlObjectIDLoader<Teleporter, yap::TeleporterReader>
(
217
yap::Path
(
"Teleporter"
),
218
"Teleporter"
));
219
220
objectFactory_
.
RegisterLoader
(
221
"RandomTileLayoutHandler"
,
222
new
yap::XmlObjectLoader
<
223
yap::RandomTileLayoutHandler
,
224
yap::RandomTileLayoutHandlerReader
> ());
225
226
objectFactory_
.
RegisterLoader
(
227
"SelectionTileLayoutHandler"
,
228
new
yap::XmlObjectLoader
<
229
yap::SelectionTileLayoutHandler
,
230
yap::SelectionTileLayoutHandlerReader
> ());
231
232
objectFactory_
.
RegisterLoader
(
233
"Sprite"
,
234
new
yap::XmlObjectLoader<yap::Sprite, yap::SpriteReader>
());
235
236
objectFactory_
.
RegisterLoader
(
237
"StringSpriteSet"
,
238
new
yap::XmlObjectLoader
<
239
yap::SpriteSet<yap::String>
,
240
yap::SpriteSetReader<yap::String>
> ());
241
242
objectFactory_
.
RegisterLoader
(
243
"Texture"
,
244
new
yap::XmlObjectIDLoader<yap::Texture, yap::TextureReader>
(
245
yap::Path
(
"Texture"
),
246
"Texture"
));
247
248
objectFactory_
.
RegisterLoader
(
249
"Tile"
,
250
new
yap::XmlObjectIDLoader<yap::Tile, yap::TileReader>
(
251
yap::Path
(
"Tile"
),
252
"Tile"
));
253
254
objectFactory_
.
RegisterLoader
(
255
"PokemonInfo"
,
256
new
yap::XmlObjectIDLoader<PokemonInfo, PokemonInfoReader>
(
257
yap::Path
(
"Pokemon/Pokemon"
),
258
"PokemonInfo"
));
259
260
objectFactory_
.
RegisterLoader
(
261
"NatureInfo"
,
262
new
yap::XmlObjectIDLoader<yap::NatureInfo, yap::NatureInfoReader>
(
263
yap::Path
(
"Pokemon/Nature"
),
264
"Nature"
));
265
266
objectFactory_
.
RegisterLoader
(
267
"TypeInfo"
,
268
new
yap::XmlObjectIDLoader<yap::TypeInfo, yap::TypeInfoReader>
(
269
yap::Path
(
"Pokemon/Types"
),
270
"Type"
));
271
272
objectFactory_
.
RegisterLoader
(
273
"SkillInfo"
,
274
new
yap::XmlObjectIDLoader<yap::SkillInfo, yap::SkillInfoReader>
(
275
yap::Path
(
"Pokemon/Skills"
),
276
"Skill"
));
277
}
278
279
void
Game::InitWorldObjectStateFactory
()
280
{
281
worldObjectStateFactory_
.
AddState
(
"Inactive"
,
"Inactive"
);
282
worldObjectStateFactory_
.
AddState
(
"Moving"
,
"Moving"
);
283
}
284
285
void
Game::InitGameInputManager
()
286
{
288
289
gameInputManager_
.
AddGameInput
(
290
new
yap::GameInput
(
291
yap::GameInputType::MapAction
,
292
new
yap::KeyboardGameInputEntry
(yap::Key::A)));
293
gameInputManager_
.
AddGameInput
(
294
new
yap::GameInput
(
295
yap::GameInputType::Action
,
296
new
yap::KeyboardGameInputEntry
(yap::Key::Return)));
297
gameInputManager_
.
AddGameInput
(
298
new
yap::GameInput
(
299
yap::GameInputType::Misc
,
300
new
yap::KeyboardGameInputEntry
(yap::Key::M)));
301
gameInputManager_
.
AddGameInput
(
302
new
yap::GameInput
(
303
yap::GameInputType::Up
,
304
new
yap::KeyboardGameInputEntry
(
yap::Key::Up
)));
305
gameInputManager_
.
AddGameInput
(
306
new
yap::GameInput
(
307
yap::GameInputType::Down
,
308
new
yap::KeyboardGameInputEntry
(
yap::Key::Down
)));
309
gameInputManager_
.
AddGameInput
(
310
new
yap::GameInput
(
311
yap::GameInputType::Left
,
312
new
yap::KeyboardGameInputEntry
(
yap::Key::Left
)));
313
gameInputManager_
.
AddGameInput
(
314
new
yap::GameInput
(
315
yap::GameInputType::Right
,
316
new
yap::KeyboardGameInputEntry
(
yap::Key::Right
)));
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
327
drawingContext_
->
AddCamera
(
328
"World"
,
329
new
yap::Camera
(
yap::Vector2
(), resolution));
330
331
drawingContext_
->
AddCamera
(
332
"Background World"
,
333
new
yap::Camera
(
yap::Vector2
(), resolution));
334
335
drawingContext_
->
AddCamera
(
336
"Gui"
,
new
yap::Camera
(
yap::Vector2
(), resolution));
337
338
drawingContext_
->
AddCamera
(
339
"Battle"
,
new
yap::Camera
(
yap::Vector2
(), resolution));
340
341
window_
= &drawingContext->
GetWindow
();
342
}
343
344
void
Game::InitScreenManager
()
345
{
346
SetScreenManager
(
new
yap::GameScreenManager
());
347
348
GetScreenManager
().
AddGameScreen
(
new
LoadingScreen
(*
drawingContext_
));
349
GetScreenManager
().
AddGameScreen
(
new
UpdateScreen
(*
drawingContext_
));
350
GetScreenManager
().
AddGameScreen
(
new
OptionScreen
(*
drawingContext_
));
351
GetScreenManager
().
AddGameScreen
(
new
LoginScreen
(*
drawingContext_
));
352
GetScreenManager
().
AddGameScreen
(
new
GameplayScreen
(*
drawingContext_
));
353
GetScreenManager
().
AddGameScreen
(
new
BattleScreen
(*
drawingContext_
));
354
GetScreenManager
().
AddGameScreen
(
new
MainMenuScreen
(*
drawingContext_
));
355
GetScreenManager
().
AddGameScreen
(
356
new
RegistrationScreen
(
357
*
drawingContext_
));
358
GetScreenManager
().
AddGameScreen
(
new
SplashScreen
(*
drawingContext_
));
359
GetScreenManager
().
AddGameScreen
(
new
CreditScreen
(*
drawingContext_
));
360
361
GetScreenManager
().
Init
(
"Loading"
);
362
}
363
364
void
Game::InitLoggerManager
()
365
{
366
logger_
.
AddMode
(
new
yap::CountLoggerMode
());
367
logger_
.
AddMode
(
new
yap::TimeLoggerMode
());
368
}
369
}
// namespace ycl
YAPOG.Client
src
Game.cpp
Generated on Mon Sep 17 2012 22:24:25 for YAPOG by
1.8.1.1