-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathentitygrunt.cpp
More file actions
67 lines (53 loc) · 1.64 KB
/
entitygrunt.cpp
File metadata and controls
67 lines (53 loc) · 1.64 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
#include "entitygrunt.hpp"
#include "game.hpp"
#include "players.hpp"
#include "sincos.hpp"
entityGrunt::entityGrunt(const game& gameRef)
: entity(), mGame(gameRef)
{
mScale = 1.5;
mRadius = 3;
mScoreValue = 50;
mType = ENTITY_TYPE_GRUNT;
setState(ENTITY_STATE_INACTIVE);
mAnimationIndex = 0;
mPen = vector::pen(.5, 1, 1, .7, 12);
int i = 0;
mModel.mVertexList.resize(4);
mModel.mVertexList[i++] = Point3d(0, 1);
mModel.mVertexList[i++] = Point3d(1, 0);
mModel.mVertexList[i++] = Point3d(0, -1);
mModel.mVertexList[i++] = Point3d(-1, 0);
i = 0;
mModel.mEdgeList.resize(4);
mModel.mEdgeList[i].from = 0;
mModel.mEdgeList[i++].to = 1;
mModel.mEdgeList[i].from = 1;
mModel.mEdgeList[i++].to = 2;
mModel.mEdgeList[i].from = 2;
mModel.mEdgeList[i++].to = 3;
mModel.mEdgeList[i].from = 3;
mModel.mEdgeList[i++].to = 0;
}
void entityGrunt::run()
{
if (this->getEnabled()) {
// Seek the player
float angle = mathutils::calculate2dAngle(mPos, mGame.mPlayers->getPlayerClosestToPosition(mPos)->getPos());
Point3d moveVector(1, 0, 0);
moveVector = mathutils::rotate2dPoint(moveVector, angle);
mSpeed += moveVector * .01;
mSpeed = mathutils::clamp2dVector(mSpeed, .3 * mAggression);
mSpeed *= .99;
// Run animation
mAnimationIndex += .07;
mScale.x = 2 + (get_sin(mAnimationIndex) * .4);
mScale.y = 2.5 + (get_sin(-mAnimationIndex) * .4);
}
entity::run();
}
void entityGrunt::spawnTransition()
{
entity::spawnTransition();
theGame->mSound->playTrack(SOUNDID_ENEMYSPAWN4);
}