-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathentity.cpp
More file actions
143 lines (123 loc) · 2.87 KB
/
Copy pathentity.cpp
File metadata and controls
143 lines (123 loc) · 2.87 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "entity.h"
/***************************************************************/
/** \file entity.cpp
\brief The CEntity implementation */
CEntity::CEntity()
{
interpol = 3.0f;
stateStart = 0;
stateEnd = 39;
animSpeed = 7.0f;
direction = 0.0f;
entitySound = NULL;
position = CVector(0,0,0);
velocity = CVector(0,0,0);
acceleration = CVector(0,0,0);
size = 6.25f;
}
CEntity::~CEntity()
{
if (entitySound)
{
delete entitySound;
entitySound = NULL;
}
}
void CEntity::OnAnimate(float deltaTime)
{
float cosYaw = (float)cos(DEG2RAD(direction));
float sinYaw = (float)sin(DEG2RAD(direction));
float speed = velocity.z * deltaTime;
if ((direction >= 360.0f) || (direction <= -360.0f))
direction = 0.0f;
position.x += float(cosYaw)*speed;
position.z += float(sinYaw)*speed;
deltaT = deltaTime; // used for interpolation
}
void CEntity::OnCollision(CObject *collisionObject)
{
if (typeid(*collisionObject) == typeid(CEntity))
{
modelState = MODEL_IDLE;
velocity = CVector(0.0, 0.0, 0.0);
}
if (typeid(*collisionObject) == typeid(CTerrain))
{
position.y = ((CTerrain*)collisionObject)->GetHeight(position.x, position.z) + size;
}
}
void CEntity::OnDraw(CCamera *camera)
{
glTranslatef(position.x, position.y, position.z);
glRotatef(-direction, 0.0, 1.0, 0.0);
glRotatef(90.0f, -1.0f, 0.0f, 0.0f);
glScalef(0.25, 0.25, 0.25);
AnimateModel(stateStart, stateEnd, deltaT*animSpeed);
}
void CEntity::OnPrepare()
{
/*
Frame# Action
----------------
0-39 idle
40-46 running
47-60 getting shot but not falling (back bending)
61-66 getting shot in shoulder
67-73 jumping
74-95 idle
96-112 getting shot and falling down
113-122 idle
123-135 idle
136-154 crouch
155-161 crouch crawl
162-169 crouch adjust weapon (idle)
170-177 kneeling dying
178-185 falling back dying
186-190 falling forward dying
191-198 falling back slow dying
*/
srand((unsigned)time(NULL));
switch (modelState)
{
case MODEL_IDLE:
stateStart = 0;
stateEnd = 39;
break;
case MODEL_CROUCH:
break;
case MODEL_RUN:
stateStart = 40;
stateEnd = 46;
velocity = CVector(0.0, 0.0, 15.0);
break;
case MODEL_JUMP:
stateStart = 67;
stateEnd = 73;
break;
case MODEL_DIE:
stateStart = 178;
stateEnd = 184;
break;
case MODEL_FIRE:
stateStart = 0;
stateEnd = 5;
break;
}
// perform collision detection from this entity with all other objects in world
ProcessCollisions(FindRoot());
}
void CEntity::LoadAudio(CAudioSystem *audioSystem, char *filename, bool is3DSound)
{
if (entitySound != NULL)
{
delete entitySound;
entitySound = new CAudio;
}
if (audioSystem != NULL)
entitySound = audioSystem->Create(filename, is3DSound);
else
{
delete entitySound;
entitySound = NULL;
}
}