-
Notifications
You must be signed in to change notification settings - Fork 1
/
Android.cpp
168 lines (151 loc) · 4.24 KB
/
Android.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "Android.h"
Android::Android(GameDataRef p_data, const sf::Vector2f& p_startPosition, std::vector<std::string>& p_path,
std::unique_ptr<std::vector<std::string>>& p_level, const sf::Vector2f* p_humanPostion, float p_dtOffset)
: Sprite(p_data, p_startPosition, p_path, p_level, p_humanPostion, p_dtOffset),
m_target(*p_humanPostion)
{
m_dtMax = 0.12f + p_dtOffset;
}
Android::~Android()
{
}
void Android::NextMotion()
{
// DOWN
if (m_target.y > m_presentPosition.y)
{
// DOWN LEFT
if (m_target.x > m_presentPosition.x)
{
if (m_path[((size_t)m_presentPosition.y + 8) / 8][(size_t)m_presentPosition.x / 16] != 'w')
{
m_nextPosition.x = m_presentPosition.x + 16.0f;
}
if (m_path[((size_t)m_presentPosition.y + 8) / 8][(size_t)m_presentPosition.x / 16] == 'w')
{
m_nextPosition.y = m_presentPosition.y + 8.0f;
}
}
// DOWN RIGHT
if (m_target.x < m_presentPosition.x)
{
if (m_path[((size_t)m_presentPosition.y + 8) / 8][(size_t)m_presentPosition.x / 16] != 'w')
{
m_nextPosition.x = m_presentPosition.x - 16.0f;
}
if (m_path[((size_t)m_presentPosition.y + 8) / 8][(size_t)m_presentPosition.x / 16] == 'w')
{
m_nextPosition.y = m_presentPosition.y + 8.0f;
}
}
}
// UP
if (m_target.y < m_presentPosition.y)
{
// UP RIGHT
if (m_target.x > m_presentPosition.x)
{
if (m_path[((size_t)m_presentPosition.y - 8) / 8][(size_t)m_presentPosition.x / 16] != 'w')
{
m_nextPosition.x = m_presentPosition.x + 16.0f;
}
if (m_path[((size_t)m_presentPosition.y - 8) / 8][(size_t)m_presentPosition.x / 16] == 'w')
{
m_nextPosition.y = m_presentPosition.y - 8.0f;
}
}
// UP LEFT
if (m_target.x < m_presentPosition.x)
{
if (m_path[((size_t)m_presentPosition.y - 8) / 8][(size_t)m_presentPosition.x / 16] != 'w')
{
m_nextPosition.x = m_presentPosition.x - 16.0f;
}
if (m_path[((size_t)m_presentPosition.y - 8) / 8][(size_t)m_presentPosition.x / 16] == 'w')
{
m_nextPosition.y = m_presentPosition.y - 8.0f;
}
}
}
// LEFT
if (m_target.x <= m_presentPosition.x && m_target.y == m_presentPosition.y)
{
m_nextPosition.x = m_presentPosition.x - 16.0f;
}
// RIGHT
if (m_target.x >= m_presentPosition.x && m_target.y == m_presentPosition.y)
{
m_nextPosition.x = m_presentPosition.x + 16.0f;
}
// up
if (m_target.x == m_presentPosition.x && m_target.y <= m_presentPosition.y)
{
m_nextPosition.y = m_presentPosition.y - 8.0f;
}
// down
if (m_target.x == m_presentPosition.x && m_target.y >= m_presentPosition.y)
{
m_nextPosition.y = m_presentPosition.y + 8.0f;
}
}
void Android::UpdateCatch()
{
if (m_target.x == m_nextPosition.x && m_target.y == m_nextPosition.y)
{
m_catch = true;
}
}
bool& Android::isCatching()
{
return m_catch;
}
void Android::Update(float p_deltaTime)
{
m_totalTime += p_deltaTime;
m_presentPosition = m_spriteShape.getPosition();
// In hole
if (m_level[((size_t)m_presentPosition.y) / 16][((size_t)m_presentPosition.x) / 16] == 'x')
{
if (m_level[((size_t)m_presentPosition.y) / 16][((size_t)m_presentPosition.x + 16) / 16] == '@' && m_level[((size_t)m_presentPosition.y) / 16][((size_t)m_presentPosition.x - 16) / 16] == '@')
{
if (m_presentPosition.y < 328)
{
if (m_level[((size_t)m_presentPosition.y + 16) / 16][((size_t)m_presentPosition.x) / 16] != ' ')
{
m_level[((size_t)m_presentPosition.y) / 16][((size_t)m_presentPosition.x) / 16] = 'T';
}
}
else
{
m_level[((size_t)m_presentPosition.y) / 16][((size_t)m_presentPosition.x) / 16] = 'T';
}
}
}
UpdateCatch();
if (m_totalTime > m_dtMax)
{
if (!m_isFalling)
{
if (!m_isInWall)
NextMotion();
if (!IsInBounds())
m_nextPosition = m_presentPosition;
if (!IsOnPath())
m_nextPosition = m_presentPosition;
if (m_isInWall && m_presentPosition.y > 8.0f)
m_nextPosition.y = m_presentPosition.y - 8.0f;
}
else
{
m_nextPosition.y = m_presentPosition.y + 8.0f;
}
if (m_catch)
{
m_nextPosition.x = m_target.x;
m_nextPosition.y = m_target.y;
}
UpdateStatus();
m_totalTime = 0;
m_spriteShape.setPosition(m_nextPosition);
}
}