forked from carboned4/CeGue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynamicObject.h
78 lines (56 loc) · 1.46 KB
/
DynamicObject.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
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
#ifndef DYNAMICOBJECT_H
#define DYNAMICOBJECT_H
#include <stdlib.h>
#include "glut.h"
#include "GameObject.h"
#include "Vector3.h"
#include <time.h>
#include <cmath>
class DynamicObject : public GameObject {
protected:
Vector3 _speed;
Vector3 _default_speed;
double _speed_multiplier;
public:
DynamicObject(Box box): GameObject(box){
_speed_multiplier = 1.0;
_speed = Vector3(0.0, 0.0, 0.0);
}
~DynamicObject(){}
void setSpeed(const Vector3 &speed){
_speed = speed;
}
void setSpeed(double x, double y, double z){
_speed.set(x, y, z);
}
void setDefaultSpeed(double x, double y, double z){
_default_speed.set(x, y, z);
_speed = _default_speed;
}
void restartSpeed(){
_speed = _default_speed;
}
public: double getSpeedMultiplier(){
return _speed_multiplier;
}
Vector3 getSpeed(){
return _speed;
}
virtual void update(int delta_t){
double _x, _vx;
Vector3 pos = getPosition();
Vector3 distance = getSpeed();
distance = distance *(((double)delta_t / 1000)*_speed_multiplier);
setPosition(pos + distance);
pos = getPosition();
_x = pos.getX();
_vx = distance.getX();
if ( (_x < -7.5) && (_vx < 0.0) ){ //If an object is beyond the left wall
setPosition(_x + 15,pos.getY(),pos.getZ()); //and moving left, he gets respawned
}
else if ((_x > +7.5) && (_vx > 0.0)){ //If an object is beyond the right wall
setPosition(_x - 15, pos.getY(), pos.getZ()); //and moving right, he gets respawned
}
}
};
#endif