-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreature.cpp
More file actions
166 lines (142 loc) · 3.26 KB
/
Copy pathCreature.cpp
File metadata and controls
166 lines (142 loc) · 3.26 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "commons.h"
#include "Creature.h"
using namespace game_utils;
using namespace std;
using namespace loaders;
using namespace cml;
namespace game_objects
{
CCreature::CCreature(): CEntity()
{
owner = CV_PLAYER_UNDEFINED;
currentAction = AA_WALK;
model = NULL;
name = "";
moveSpeed = 1.0f;
moveVector = vector3f(0.0f,0.0f,0.0f);
level = 1;
gold = 0;
count = 0.0f;
change = 100.0f;
}
CCreature::~CCreature()
{
if (model)
{
CV_GAME_MANAGER->getResourceManager()->returnModel(name,model);
}
}
GLvoid CCreature::setName(string name)
{
this->name = name;
}
GLvoid CCreature::setOwner(GLubyte owner)
{
this->owner=owner;
}
GLvoid CCreature::setLevel(GLint level)
{
if (this->getLevel() < 10) // cant level if already level 10
{
this->level = level;
CV_GAME_MANAGER->getConsole()->writeLine(this->getName()+" has leveled up to "+CConversions::intToStr(this->getLevel()));
}
}
GLvoid CCreature::setGold(GLint gold)
{
this->gold=gold;
}
GLvoid CCreature::addCurrentXP(GLint CurrentXP)
{
// add the experiance
this->CurrentXP = (this->getCurrentXP() + CurrentXP);
// if the creature has enough experiance to level
if (this->getCurrentXP() >= this->getLevel()*100) //some forumla
{
this->CurrentXP = this->getCurrentXP() - (this->getLevel()*100); // reset xp and add remaining xp from level
this->setLevel(this->getLevel() + 1);// level up
}
}
GLvoid CCreature::setModel(loaders::CBR5Model *model)
{
this->model = model;
this->model->setInterpolate(true);
this->model->setConnected(true);
}
GLvoid CCreature::setAction(GLint action, GLint startFrame, GLint endFrame)
{
actions[action] = model->registerAction(startFrame,endFrame);
}
GLvoid CCreature::useAction(GLint action)
{
this->currentAction = action;
if (model)
{
model->doAction(actions[action]);
}
}
GLvoid CCreature::Idle(GLfloat deltaTime)
{
if (count>=change)
{
GLfloat tX = (GLfloat)(rand()%100-50);
GLfloat tZ = (GLfloat)(rand()%100-50);
moveVector[0] = tX-position[0];
moveVector[2] = tZ-position[2];
moveVector.normalize();
rotation[1] = 90.0f-(float)(atan2(moveVector[2],moveVector[0])*180.0f/M_PI);
change=(GLfloat)((rand()%100))+300.0f;
count = 0.0f;
}
GLint X = (GLint)(position[0]/CV_BLOCK_WIDTH);
GLint Y = (GLint)(position[2]/CV_BLOCK_DEPTH);
if(CV_GAME_MANAGER->getLevelManager()->getBlock(X,Y)->isWalkable(false))
{
position += moveVector*moveSpeed*deltaTime;
count+=0.5f;
}
else
{
position -= moveVector*moveSpeed*deltaTime;
count=change;
}
}
GLvoid CCreature::draw(GLfloat deltaTime)
{
if (model)
{
CEntity::moveTo();
CEntity::rotateTo();
model->draw(deltaTime);
CEntity::rotateBack();
CEntity::moveBack();
}
}
CBR5Model *CCreature::getModel()
{
return model;
}
string CCreature::getName()
{
return name;
}
GLubyte CCreature::getOwner()
{
return owner;
}
GLint CCreature::getLevel()
{
return level;
}
GLint CCreature::getCurrentXP()
{
return CurrentXP;
}
GLint CCreature::getGold()
{
return gold;
}
GLvoid CCreature::update(GLfloat deltaTime)
{
}
};