Arch Game Engine  0.2
entity.cpp
1 #include "entity.h"
2 
3 Entity::Entity() {}
4 
5 Entity::~Entity() {}
6 
7 void Entity::damage(double d) {
8  health -= d;
9  if(health >= 0) {
10  health = 0;
11  kill();
12  }
13 }
14 void Entity::heal(double h) {
15  health += h;
16  if(h > maxHealth) {
17  health = maxHealth;
18  }
19 }
20 void Entity::kill() {
21  setHealth(0);
22  deactivate();
23 }
24 
26  active = 0;
27 }
29  active = 1;
30 }
31 
33  Object obj;
34  obj.setDest(getDetect());
35  if(col.isTouching(obj, screen)) {
36  setDisplayable(true);
37  } else {
38  setDisplayable(false);
39  }
40 }
41 
43  setDetectRange(r, r);
44 }
45 void Entity::setDetectRange(int w, int h) {
46  detect.x = getPosX()-w;
47  detect.y = getPosY()-h;
48  detect.w = getPosW()+w+w;
49  detect.h = getPosH()+h+h;
50 }
This class stores information for an Object in the game.
Definition: object.h:12
void deactivate()
Sets active to false.
Definition: entity.cpp:25
void checkDisplayable(Object screen)
Checks if an the Entity is in the current screen by passing the screen to it.
Definition: entity.cpp:32
void setDisplayable(bool d)
This sets if you want the Object to visible on the screen by passing in a boolean.
Definition: object.h:32
SDL_Rect getDetect() const
Returns the detection radius.
Definition: entity.h:53
void setDest(SDL_Rect i)
Set the destination with a given SDL_Rect.
Definition: object.h:74
void setHealth(double h)
Set the Entity's health. If the health is higher then the max health it will set it to the max health...
Definition: entity.h:25
void activate()
Sets active to true.
Definition: entity.cpp:28
void setDetectRange(int r)
Sets the detection radius with a single given distance.
Definition: entity.cpp:42
void heal(double h)
Give health to the Entity.
Definition: entity.cpp:14
void damage(double d)
Deal damage. Subtracted from health. If health is less then zero it kills the entity.
Definition: entity.cpp:7
void kill()
Sets health to zero and deactives the Entity.
Definition: entity.cpp:20
bool isTouching(Object a, Object b)
Check if two objects are touching.
Definition: collision.cpp:7