YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
BeginWildBattlePhase.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Graphics/Game/Sprite/ISprite.hpp
"
2
#include "
YAPOG/Graphics/Gui/DialogBoxWidget.hpp
"
3
#include "
YAPOG/Game/Battle/Phase/PhaseArgs.hpp
"
4
5
#include "
Battle/Phase/BeginWildBattlePhase.hpp
"
6
#include "
Battle/OpponentBattleInfoWidget.hpp
"
7
#include "
Battle/BattleInterface.hpp
"
8
#include "Battle/Battle.hpp"
9
#include "Game.hpp"
10
11
namespace
ycl
12
{
13
const
bool
BeginWildBattlePhase::DEFAULT_VISIBLE_STATE
=
true
;
14
const
sf::Color
BeginWildBattlePhase::DEFAULT_COLOR
= sf::Color ();
15
const
float
BeginWildBattlePhase::GROUND_SPEED
= 500.f;
16
const
yap::String
BeginWildBattlePhase::FISRT_STATE
=
"Init"
;
17
18
BeginWildBattlePhase::BeginWildBattlePhase
19
(
Battle
& battle,
BattleInterface
& battleInterface)
20
:
BeginBattlePhase
(battle, battleInterface)
21
, nextState_ (FISRT_STATE)
22
{
23
}
24
25
BeginWildBattlePhase::~BeginWildBattlePhase
()
26
{
27
}
28
29
void
BeginWildBattlePhase::Init
()
30
{
31
battle_
.
GetOpponent
().
OnHPChangedEvent
() +=
32
[&] (
const
yap::IBattleEntity
& sender,
33
const
yap::ChangeEventArgs<const yap::HitPoint&>
& args)
34
{
35
battleInterface_
.
GetOpponentInfoWidget
().
UpdateHPColor
(
36
battle_
.
GetOpponent
().
GetHPPercentage
());
37
38
battleInterface_
.
GetOpponentInfoWidget
().
UpdateHPSize
(
39
battle_
.
GetOpponent
().
GetHPPercentage
());
40
};
41
42
battleInterface_
.
GetBattleInfoDialogBox
().
OnTextChanged
+=
43
[&] (
const
yap::BaseWidget
& sender,
const
yap::EmptyEventArgs
& args)
44
{
45
if
(
nextState_
==
"WaitUser"
)
46
{
47
battleInterface_
.
GetBattleInfoDialogBox
().
48
AddText (
battle_
.
GetPlayerTeam
().
GetName
() +
"! GO !"
);
49
50
nextState_
=
"PlayerBack"
;
51
battleInterface_
.
GetBattleInfoDialogBox
().
SetEnable
(
false
);
52
}
53
};
54
}
55
56
void
BeginWildBattlePhase::HandleStart
(
yap::PhaseArgs
* args)
57
{
58
BeginBattlePhase::HandleStart
(args);
59
60
// Begin battle little phases booleans init.
61
nextState_
=
FISRT_STATE
;
62
63
// Player's side init
64
battle_
.
GetPlayerGround
().
SetPosition
(
65
yap::Vector2
(
66
Game::SCREEN_SIZE
.x,
battle_
.
GetPlayerGroundPosition
().y
67
));
68
69
UpdatePlayerTrainerBack
();
70
71
// Opponent's side init.
72
battle_
.
GetOpponentGround
().
SetPosition
(
73
yap::Vector2
(
74
(-1) *
battle_
.
GetOpponentGround
().
GetSize
().x,
75
battle_
.
GetOpponentGroundPosition
().y));
76
77
UpdateOpponentFront
();
78
81
const
yap::String
& opponentName =
battle_
.
GetOpponent
().
GetName
();
82
83
// Battle dialog box init.
84
battleInterface_
.
GetBattleInfoDialogBox
().
SetEnable
(
false
);
85
battleInterface_
.
GetBattleInfoDialogBox
().
Show
(
true
);
86
battleInterface_
.
GetBattleInfoDialogBox
().
SetShowText
(
false
);
87
battleInterface_
.
GetBattleInfoDialogBox
().
88
AddText (
"Un "
+ opponentName +
" sauvage apparait !"
);
89
90
// Opponent's side.
91
battleInterface_
.
GetOpponentInfoWidget
().
Show
(
true
);
92
battleInterface_
.
GetOpponentInfoWidget
().
SetName
(opponentName);
93
battleInterface_
.
GetOpponentInfoWidget
().
SetLevel
(
94
battle_
.
GetOpponent
().
GetLevel
());
95
battleInterface_
.
GetOpponentInfoWidget
().
SetGender
(
96
battle_
.
GetOpponent
().
GetGender
());
97
98
battleInterface_
.
GetOpponentInfoWidget
().
SetPosition
(
yap::Vector2
(
99
-1 *
battleInterface_
.
GetOpponentInfoWidget
().
GetSize
().x,
100
battle_
.
GetOpponentInfoPosition
().y));
102
103
battleInterface_
.
GetBattleInfoDialogBox
().
SetEnable
(
false
);
104
}
105
106
void
BeginWildBattlePhase::HandleUpdate
(
const
yap::Time
& dt)
107
{
108
BeginBattlePhase::HandleUpdate
(dt);
109
110
if
(
nextState_
==
FISRT_STATE
)
111
{
112
if
(
battle_
.
GetPlayerGround
().
GetPosition
().x >
113
battle_
.
GetPlayerGroundPosition
().x)
114
{
115
battle_
.
GetPlayerGround
().
Move
(
116
yap::Vector2
(
117
(-1) * (
GROUND_SPEED
* dt.
GetValue
()),
118
0));
119
120
UpdatePlayerTrainerBack
();
121
}
122
else
123
{
124
battle_
.
GetPlayerGround
().
SetPosition
(
125
battle_
.
GetPlayerGroundPosition
());
126
127
UpdatePlayerTrainerBack
();
128
}
129
130
if
(
battle_
.
GetOpponentGround
().
GetPosition
().x <
131
battle_
.
GetOpponentGroundPosition
().x)
132
{
133
battle_
.
GetOpponentGround
().
Move
(
134
yap::Vector2
(
135
(
GROUND_SPEED
* dt.
GetValue
()),
136
0));
137
138
UpdateOpponentFront
();
139
}
140
else
141
{
142
battle_
.
GetOpponentGround
().
SetPosition
(
143
battle_
.
GetOpponentGroundPosition
());
144
145
UpdateOpponentFront
();
146
}
147
148
if
(
battle_
.
GetOpponentGround
().
GetPosition
() ==
149
battle_
.
GetOpponentGroundPosition
() &&
150
battle_
.
GetPlayerGround
().
GetPosition
() ==
151
battle_
.
GetPlayerGroundPosition
())
152
{
153
nextState_
=
"OpponentInfo"
;
154
}
155
}
156
157
if
(
nextState_
==
"OpponentInfo"
)
158
{
159
battleInterface_
.
GetBattleInfoDialogBox
().
SetShowText
(
true
);
160
161
if
(
battleInterface_
.
GetOpponentInfoWidget
().
GetPosition
().x <
162
battle_
.
GetOpponentInfoPosition
().x)
163
{
164
battleInterface_
.
GetOpponentInfoWidget
().
Move
(
yap::Vector2
(
165
((
GROUND_SPEED
* 2) * dt.
GetValue
()),
166
0));
167
}
168
else
169
{
170
battleInterface_
.
GetOpponentInfoWidget
().
SetPosition
(
171
battle_
.
GetOpponentInfoPosition
());
172
173
battleInterface_
.
GetBattleInfoDialogBox
().
SetEnable
(
true
);
174
nextState_
=
"WaitUser"
;
175
}
176
}
177
178
if
(
nextState_
==
"PlayerBack"
)
179
{
180
if
(
battle_
.
GetPlayerTrainerBack
().
GetPosition
().x >
181
(-1) *
battle_
.
GetPlayerTrainerBack
().
GetSize
().x)
182
{
183
battle_
.
GetPlayerTrainerBack
().
Move
(
184
yap::Vector2
((-1) * ((
GROUND_SPEED
* 2) * dt.
GetValue
()), 0));
185
}
186
else
187
nextState_
=
"SwitchPhase"
;
188
}
189
190
if
(
nextState_
==
"SwitchPhase"
)
191
yap::BattlePhase::SwitchPhase
(
yap::BattlePhaseState::Switch
);
192
}
193
194
void
BeginWildBattlePhase::HandleEnd
()
195
{
196
BeginBattlePhase::HandleEnd
();
197
}
198
199
void
BeginWildBattlePhase::HandleDraw
(
yap::IDrawingContext
& context)
200
{
201
}
202
203
void
BeginWildBattlePhase::HandleShow
(
bool
isVisible)
204
{
205
}
206
207
void
BeginWildBattlePhase::HandleChangeColor
(
const
sf::Color& color)
208
{
209
}
210
211
void
BeginWildBattlePhase::UpdatePlayerTrainerBack
()
212
{
213
battle_
.
GetPlayerTrainerBack
().
SetPosition
(
214
yap::Vector2
(
215
battle_
.
GetPlayerGround
().
GetPosition
().x +
216
battle_
.
GetPlayerGround
().
GetSize
().x / 2 -
217
battle_
.
GetPlayerTrainerBack
().
GetSize
().x / 2
218
,
battle_
.
GetPlayerGroundPosition
().y +
219
battle_
.
GetPlayerGround
().
GetSize
().y / 2 -
220
battle_
.
GetPlayerTrainerBack
().
GetSize
().y
221
));
222
}
223
224
void
BeginWildBattlePhase::UpdateOpponentFront
()
225
{
226
battle_
.
GetOpponent
().
GetBattleSprite
().
SetPosition
(
227
yap::Vector2
(
228
battle_
.
GetOpponentGround
().
GetPosition
().x +
229
battle_
.
GetOpponentGround
().
GetSize
().x / 2 -
230
battle_
.
GetOpponent
().
GetBattleSprite
().
GetSize
().x / 2,
231
battle_
.
GetOpponentGround
().
GetPosition
().y -
232
battle_
.
GetOpponent
().
GetBattleSprite
().
GetSize
().y / 2));
233
}
234
}
YAPOG.Client
src
Battle
Phase
BeginWildBattlePhase.cpp
Generated on Mon Sep 17 2012 22:24:21 for YAPOG by
1.8.1.1