-
Notifications
You must be signed in to change notification settings - Fork 0
/
creature.cpp
161 lines (140 loc) · 2.91 KB
/
creature.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
#include "creature.h"
#include "board.h"
#include "bullet.h"
#include <ctime>
#include <cstdlib>
Creature::Creature(Board *_map, float _speed, int _maxHp, int _width, int _height)
:Mobile(_speed,_width,_height)
{
Weapon=NULL;
MaxSpeed=_speed;
MaxHp=_maxHp;
Hp=_maxHp;
setStartPosition(_map);
}
Creature::~Creature()
{
}
int Creature::getHp()
{
return Hp;
}
void Creature:: setHp(int _hp)
{
Hp=_hp;
}
int Creature::getMaxHp()
{
return MaxHp;
}
void Creature::setSpeed(float _speed)
{
Speed=_speed;
}
float Creature::getMaxSpeed()
{
return MaxSpeed;
}
void Creature::Dead()
{
if(Hp<=0)
{
ToRemove=true;
}else{
ToRemove=false;
}
}
bool Creature::collisionCreatureStart(Board *_map)
{
if(X<=0||Y<=0||Y+Height>=_map->getHeight()||X+Width>=_map->getWidth())
{
return true;
}
float X_c=X+Width/2;
float Y_c=Y+Height/2;
Object *obj;
for(int i=0; i<_map->getNumberOfMobiles();i++)
{
obj=_map->getMobile(i);
if(isOn(X_c,Y_c,obj))
{
obj=NULL;
return true;
}
}
for(int i=0;i<_map->getNumberOfObstacle();i++)
{
if(_map->getObstacle(i)->CanPass()==false)
{
obj=_map->getObstacle(i);
if(isOn(X_c,Y_c,obj))
{
obj=NULL;
return true;
}
}
}
return false;
}
void Creature::checkField(Board *_map)
{
this->Dead();
float X_c=X+Width/2;
float Y_c=Y+Height/2;
bool condition=false;
Object *obj=NULL;
//w razie jakby tamto nie działało z bulletów reducehp
Bullet *bull;
obj=this;
float xc,yc;
for(int i=0;i<_map->getNumberOfMobiles();i++)
{
bull=dynamic_cast<Bullet*>(_map->getMobile(i));
if(bull)
{
xc=bull->getX()+(bull->getWidth())/2;
yc=bull->getY()+(bull->getHeight())/2;
if(this->isOn(xc,yc,obj))
{
bull->reduceHp(this);
//_map->removeMobile(i);//to nie musi byc koniecznie
return;
}
}
}
//dotąd
for(int i=0;i<_map->getNumberOfObstacle();i++)
{
obj=NULL;
obj=_map->getObstacle(i);
if( this->isOn(X_c,Y_c,obj) )
{
condition=true;
_map->getObstacle(i)->affect(this,condition);
return;
}
else
{
condition=false;
_map->getObstacle(i)->affect(this,condition);
}
}
}
void Creature::setStartPosition(Board *_map)
{
bool success=false;
srand(time(0));
while(!success)
{
X=rand()%(_map->getWidth());
Y=rand()%(_map->getHeight());
if(!collisionCreatureStart(_map))
{
success=true;
}
}
}
TypeWeapon* Creature::getWeponPtr()
{
return Weapon;
}