-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathentityproton.cpp
More file actions
65 lines (49 loc) · 1.58 KB
/
entityproton.cpp
File metadata and controls
65 lines (49 loc) · 1.58 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
#include "defines.hpp"
#include "entityproton.hpp"
#include "game.hpp"
#include "players.hpp"
entityProton::entityProton(void)
{
mScale = 1;
mRadius = 1.2;
mEdgeBounce = true;
mSpawnTime = 0;
mScoreValue = 50; // ??
mDestroyTime = 0;
mPen = vector::pen(.5, .6, 1, .7, 12);
mType = ENTITY_TYPE_PROTON;
setState(ENTITY_STATE_INACTIVE);
mModel.mVertexList.resize(16);
float delta_theta = (2 * PI) / mModel.mVertexList.size();
float r = mScale.x * mRadius;
std::size_t i = 0;
for (float angle = 0; i < mModel.mVertexList.size(); angle += delta_theta, i++) {
mModel.mVertexList[i] = Point3d(r * cos(angle), r * sin(angle));
}
mModel.mEdgeList.resize(mModel.mVertexList.size());
for (i = 0; i < mModel.mEdgeList.size() - 1; ++i) {
mModel.mEdgeList[i].from = i;
mModel.mEdgeList[i].to = i + 1;
}
mModel.mEdgeList[i].from = i;
mModel.mEdgeList[i].to = 0;
}
void entityProton::run()
{
if (this->getEnabled()) {
// Seek the player
float angle = mathutils::calculate2dAngle(mPos, theGame->mPlayers->getPlayerClosestToPosition(mPos)->getPos());
Point3d moveVector(1, 0, 0);
moveVector = mathutils::rotate2dPoint(moveVector, angle);
mSpeed += moveVector * .1;
mSpeed = mathutils::clamp2dVector(mSpeed, .6 * mAggression);
// mSpeed *= .98;
}
entity::run();
}
void entityProton::spawnTransition()
{
entity::spawnTransition();
mDrift.x = (mathutils::frandFrom0To1() * 4) - 2;
mDrift.y = (mathutils::frandFrom0To1() * 4) - 2;
}