-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlivingentity.cpp
77 lines (66 loc) · 1.72 KB
/
livingentity.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
#include "livingentity.h"
#include "header.h"
#include <QDebug>
double LivingEntity::getHealth() const
{
return health;
}
void LivingEntity::setHealth(double value)
{
health = value;
}
int LivingEntity::getIntangible() const
{
return intangible;
}
void LivingEntity::setIntangible(int value)
{
intangible = value;
}
void LivingEntity::deathTimer()
{
if(health < 0){
health--;
}
if(health == -constants::FPS_CALCULATION/2){
isDead = true;
}
}
LivingEntity::LivingEntity():Entity()
{
vectorX = 0;
vectorY = 0;
}
bool LivingEntity::detectCollisionMap(Level * const level)
{
int firstTileY = posTmp.left()/ constants::TILE_WIDTH;
int lastTileY = (posTmp.right()-1)/ constants::TILE_WIDTH;
int firstTileX = posTmp.top()/ constants::TILE_HEIGHT;
int lastTileX = (posTmp.bottom()-1)/ constants::TILE_HEIGHT;
bool collision = false;
for(int tileX = firstTileX; tileX <= lastTileX; tileX++){
for(int tileY = firstTileY; tileY <= lastTileY; tileY++){
if(level->getTile(tileX, tileY)->getWall()){
collision = true;
}
}
}
return collision;
}
QVector<LivingEntity *> LivingEntity::getCollidingEntities(double id, Level * const level)
{
QVector<LivingEntity *> colliding;
for(int i = 0; i<level->getNbEntities(); i++)
if(i != id) {
LivingEntity * entity = level->getEntity(i);
if(entity->getHitbox().intersects(getHitbox())) {
colliding.push_back(entity);
}
}
return colliding;
}
void LivingEntity::validatePos()
{
setHitbox(posTmp);
setImagePos(posTmp);
}