-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity.cpp
149 lines (130 loc) · 3.61 KB
/
entity.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
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
143
144
145
146
147
148
149
// -----------------------------------------------------------------
// Learning Team B
// Members:
// Adam LeMmon
// Faith Satterthwaite
// Tom Fletcher
// Justin Ball
// CS 4280 – 11:30 am
// Final Project
// Dr. Rague
// Due: 12/06/12
// Version: 2.4
// -----------------------------------------------------------------
// We made five major improvements to this game
// 1) New controls
// 2) Enemy attack
// 3) HUD (heads up display)
// 4) Enemy health bars
// 5) New Weapon
// -----------------------------------------------------------------
#include "entity.h"
CEntity::CEntity()
{
interpol = 3.0f;
stateStart = 0;
stateEnd = 39;
animSpeed = 7.0f;
direction = 0.0f;
// Phase 15 - Comment out the following
position = CVector(0,0,0);
velocity = CVector(0,0,0);
acceleration = CVector(0,0,0);
size = 6.25f;
}
CEntity::~CEntity()
{
}
void CEntity::OnAnimate(float deltaTime)
{
float cosYaw = (float)cos(DEG2RAD(direction));
float sinYaw = (float)sin(DEG2RAD(direction));
float speed = velocity.z * deltaTime;
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
*/
switch (modelState)
{
case MODEL_IDLE:
stateStart = 0;
stateEnd = 39;
break;
case MODEL_CROUCH:
break;
/****************Faith Satterthwaite 12/1/2012***********************/
case MODEL_WALK:
stateStart = 42;
stateEnd = 44;
velocity = CVector(-15.0, -15.0, -15.0);
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;
default:
stateStart = 0;
stateEnd = 1;
break;
}
// perform collision detection from this entity with all other objects in world
ProcessCollisions(FindRoot());
}
// Phase 15 - Comment out the following
// Phase 19 - Uncomment the following
void CEntity::LoadAudio(XACTINDEX soundindex) //function to load the entities sound based on the index given
{
index = soundindex; //set index to the index passed in
}