YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
CharacterMoveController.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Game/World/Map/Physics/CharacterMoveController.hpp
"
2
3
namespace
yap
4
{
5
const
Direction
CharacterMoveController::DEFAULT_LAST_DIRECTION
=
6
Direction::South
;
7
8
CharacterMoveController::CharacterMoveController
()
9
:
WorldObjectMoveController
()
10
, directions_ ()
11
, lastDirection_ (DEFAULT_LAST_DIRECTION)
12
{
13
directions_
.
Add
(Direction::North,
false
);
14
directions_
.
Add
(
Direction::East
,
false
);
15
directions_
.
Add
(
Direction::South
,
false
);
16
directions_
.
Add
(
Direction::West
,
false
);
17
}
18
19
CharacterMoveController::~CharacterMoveController
()
20
{
21
}
22
23
void
CharacterMoveController::EnableDirection
(
Direction
direction)
24
{
25
directions_
[direction] =
true
;
26
27
lastDirection_
= direction;
28
29
Update
();
30
}
31
32
void
CharacterMoveController::DisableDirection
(
Direction
direction)
33
{
34
directions_
[direction] =
false
;
35
36
Update
();
37
}
38
39
void
CharacterMoveController::Update
()
40
{
41
int
enabledDirectionCount = 0;
42
Direction
currentDirection =
lastDirection_
;
43
44
for
(
auto
& it :
directions_
)
45
{
46
if
(!it.second)
47
continue
;
48
49
++enabledDirectionCount;
50
51
currentDirection = it.first;
52
}
53
54
if
(enabledDirectionCount == 0)
55
{
56
force_
=
Vector2
();
57
return
;
58
}
59
60
if
(enabledDirectionCount > 1)
61
currentDirection =
lastDirection_
;
62
63
switch
(currentDirection)
64
{
65
case
Direction::North:
force_
=
Vector2
(0.0f, -
value_
.y);
break
;
66
case
Direction::East
:
force_
=
Vector2
(
value_
.x, 0.0f);
break
;
67
case
Direction::South
:
force_
=
Vector2
(0.0f,
value_
.y);
break
;
68
case
Direction::West
:
force_
=
Vector2
(-
value_
.x, 0.0f);
break
;
69
default
:
break
;
70
}
71
}
72
}
// namespace yap
YAPOG
src
YAPOG
Game
World
Map
Physics
CharacterMoveController.cpp
Generated on Mon Sep 17 2012 22:24:25 for YAPOG by
1.8.1.1