-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity.cpp
248 lines (197 loc) · 3.94 KB
/
entity.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include <graphics.h>
#include "entity.h"
Entity::Entity()
{
}
bool Entity::sound(EntityUnit selff) {
return false;
}
IMAGE *Entity::render(EntityUnit selff) {
return &*selff.getIterator();
}
bool Entity::attack(Pool<EntityUnit> *a, Table b, EntityUnit selff)
{
return false;
}
bool Entity::skill(Pool<EntityUnit> *a, Table b, EntityUnit selff)
{
return false;
}
bool Entity::motion(Pool<EntityUnit> *a, Table b, EntityUnit selff)
{
return false;
}
void Entity::initEntityUnit(EntityUnit& a)
{
a.setAnimeType(1);
a.setAnimeIterator(res.getPicSequence(1));
a.setLastAck(GameRunTime::getTick());
a.setLastSkl(GameRunTime::getTick());
}
Entities Entity::getType() const
{
return Entities();
}
short Entity::getHealth() const
{
return maxHealth;
}
long Entity::getAttackInterval() const
{
return attackInterval;
}
long Entity::getSkillInterval() const
{
return 0;
}
//EntityUnit::EntityUnit(Entity* refe)
//{
// refer = refe;
// refresh();
//}
//void EntityUnit::refresh()
//{
// currentHealth = (*refer).getHealth();
// val[0] = 0;
// val[1] = 0;
// val[2] = 0;
// lastAttack = GameRunTime::getTick();
// lastSkill = lastAttack;
// animeFrame = 0;
// animeType = -1;
//}
void EntityUnit::setRefer(Entity* refe)
{
refer = refe;
refer->initEntityUnit(*this);
}
unsigned short EntityUnit::getCurrentHealth() const
{
return currentHealth;
}
short EntityUnit::getVal(byte index) const
{
return val[index];
}
byte EntityUnit::getAnimeType() const
{
return animeType;
}
DWORD EntityUnit::getLastatk() const
{
return lastAttack;
}
DWORD EntityUnit::getLastSkl() const
{
return lastSkill;
}
void EntityUnit::getPoi(byte* qposition, byte* qpoiInRow, byte* qrow)
{
if (qposition != NULL) *qposition = position;
if (qpoiInRow != NULL) *qpoiInRow = poiInRow;
if (qrow != NULL)*qrow = row;
}
CycleLinkedList<IMAGE>::iterator EntityUnit::getIterator()
{
return currentAnimeIr++;
}
void EntityUnit::changeCurHealth(short va)
{
currentHealth += va;
}
void EntityUnit::setVal(byte index, int va)
{
val[index] = va;
}
void EntityUnit::setLastAck(DWORD ti)
{
lastAttack = ti;
}
void EntityUnit::setLastSkl(DWORD ti)
{
lastAttack = ti;
}
void EntityUnit::setAnimeType(byte val)
{
animeType = val;
}
Entity* EntityUnit::getEntityRefer()
{
return nullptr;
}
void EntityUnit::setAnimeIterator(CycleLinkedList<IMAGE>::iterator a)
{
currentAnimeIr = a;
}
void EntityUnit::setPoi(byte* qposition, byte* qpoiInRow, byte* qrow)
{
if (qposition != NULL) position = *qposition;
if (qpoiInRow!= NULL)poiInRow = *qpoiInRow;
if (qrow != NULL) row = *qrow;
}
//to-do,加个边界检测,出界就返回false
bool EntityUnit::changePoi(byte* qposition, byte* qpoiInRow, byte* qrow)
{
int a=0, b=0, c = 0;
if (qposition != NULL) a = *qposition;
if (qpoiInRow != NULL)b = *qpoiInRow;
if (qrow != NULL) c = *qrow;
position += a;
row+=c;
if (poiInRow + c < 0)row--;
else if (poiInRow + c > 10)row++;
poiInRow = (poiInRow + 10 + c) % 10;
return false;
}
Pee::Pee()
{
type = Entities::Pee;
res.init("Pee");
}
bool Pee::attack(Pool<EntityUnit> *a, Table b)
{
return false;
}
SunPower::SunPower() {
type = Entities::SunPower;
res.init("SunPower");
}
bool SunPower::skill(short *a)
{
*a += 25;
return false;
}
bool SunPower::motion(Pool<EntityUnit> *a, Table b, EntityUnit selff)
{
int z = GameRunTime::getTick() - selff.getLastSkl();
byte aa, bb;
if (z < 12&&z%2==0) {
aa = 1;
bb = -2;
selff.changePoi(&aa, &bb, NULL);
}
else if (z >= 12 && z < 18 && z % 2 == 0) {
aa = 1;
bb = 1;
selff.changePoi(&aa, &bb, NULL);
}
return true;
}
void SunPower::initEntityUnit(EntityUnit& a)
{
Entity::initEntityUnit(a);
a.setVal(0, GameRunTime::getTick() % 2 == 0 ? 1 : -1);
}
Sunflower::Sunflower()
{
maxHealth = 10;
type = Entities::Sunflower;
skillInterval = 30;
res.init("Sunflower");
}
bool Sunflower::skill(Pool<EntityUnit> *a, Table b, EntityUnit selff)
{
if (GameRunTime::getTick() - selff.getLastSkl() > skillInterval) {
auto z = GameRunTime::requestEntityUnit(a);
}
}