-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameobject.cpp
64 lines (53 loc) · 1.81 KB
/
gameobject.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
#include "gameobject.h"
#include <glm/glm.hpp>
#include <stdexcept>
GameObject::GameObject(
GameObjectType type,
uint32_t entityID,
const vec3 &position,
const vec3 &direction
) : type(type), entityID(entityID), position(position), direction(direction)
{
if (direction == vec3(0.0f))
throw std::invalid_argument("Direction cannot be the zero vector.");
}
CircleCollider GameObject::getCollider() const { return collider; }
vec3 GameObject::getPosition() const { return position; }
void GameObject::setPosition(const vec3 &pos)
{
position = pos;
_hasChanged = true;
}
vec3 GameObject::getDirection() const { return direction; }
void GameObject::setDirection(const vec3 &dir)
{
if (dir == vec3(0.0f))
throw std::invalid_argument("Direction cannot be the zero vector.");
direction = glm::normalize(dir);
//_hasChanged = true; // No need to enable this until non-circle colliders are implemented
}
float GameObject::getSpeed() const { return speed; }
void GameObject::setSpeed(float spd)
{
if (spd <= 0)
throw std::invalid_argument("Speed must be positive.");
speed = spd;
}
GameObjectType GameObject::getType() const { return type; }
uint32_t GameObject::getEntityID() const { return entityID; }
void GameObject::selfDestruct() { _isQueuedForDestruction = true; }
bool GameObject::isQueuedForDestruction() const { return _isQueuedForDestruction; }
bool GameObject::hasChanged() const { return _hasChanged; }
void GameObject::resetChanged() { _hasChanged = false; }
void GameObject::start(){
doStart();
collider.updatePosition(position);
}
void GameObject::update(float deltaTime){
doUpdate(deltaTime);
if (hasChanged())
collider.updatePosition(position);
}
void GameObject::doStart(){}
void GameObject::doUpdate(float deltaTime){}
void GameObject::doCollision(GameObject *other){}