-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entity.h
52 lines (42 loc) · 1.13 KB
/
Entity.h
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
#ifndef ENTITY_H
#define ENTITY_H
#include "Sprite.h"
#include "ComponentManager.h"
class Entity : public Component
{
public:
Entity(const Sprite &, float2, float);
virtual ~Entity();
virtual void update();
virtual void draw();
float2 getPosition() const { return position; }
void setPosition(const float2 &p) { position = p; }
template <class EntityType> EntityType *collisionWithE(Entity* = NULL);
float2 collisionSeparate(Entity *e, float2, float2, float);
protected:
Sprite sprite;
float2 position;
float orientation;
float2 velocity;
float radius;
// int hp;
private:
};
template <class EntityType> EntityType* Entity::collisionWithE(Entity* except)
{
ComponentManager::get().find<EntityType>();
EntityType *r, *t = NULL;
float maxLen = 0.f;
while( (r=ComponentManager::get().next<EntityType>()) != NULL )
{
float len = r->radius + radius - (r->position-position).len();
if(velocity>float2(0,0))
if (len>0 && except!=r && len>maxLen)
{
maxLen = len;
t = r;
}
}
return t;
}
#endif // ENTITY_H