-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathentitytinyspinner.cpp
More file actions
114 lines (95 loc) · 2.83 KB
/
entitytinyspinner.cpp
File metadata and controls
114 lines (95 loc) · 2.83 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
#include "entitytinyspinner.hpp"
#include "game.hpp"
#include "grid.hpp"
#include "players.hpp"
entityTinySpinner::entityTinySpinner(const game& gameRef)
: entitySpinner(gameRef), mGame(gameRef)
{
mScale = 1;
mRadius = 2.2;
mScoreValue = 50;
mAnimationIndex = 0;
mType = ENTITY_TYPE_TINYSPINNER;
}
void entityTinySpinner::draw()
{
if (this->getState() == entity::ENTITY_STATE_INDICATING) {
if (((int)(mStateTimer / 10)) & 1) {
vector::pen pen = mPen;
mModel.draw(pen);
}
} else if (this->getEnabled()) {
mModel.Identity();
mModel.Scale(mScale);
mModel.Rotate(mAngle);
mModel.Translate(mVirtualPos);
mModel.draw(mPen);
}
}
void entityTinySpinner::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 * .02;
mSpeed = mathutils::clamp2dVector(mSpeed, .2 * mAggression);
mSpeed *= .9;
// Run circling animation
mAnimationIndex += .12;
Point3d offset(5, 0, 0);
offset = mathutils::rotate2dPoint(offset, mAnimationIndex);
mVirtualPos = mPos + offset;
mAngle = mAnimationIndex * 2;
if (mVirtualPos.x < 0)
mVirtualPos.x = 0;
else if (mVirtualPos.x > theGame->mGrid->extentX() - 1)
mVirtualPos.x = theGame->mGrid->extentX() - 1;
if (mVirtualPos.y < 0)
mVirtualPos.y = 0;
else if (mVirtualPos.y > theGame->mGrid->extentY() - 1)
mVirtualPos.y = theGame->mGrid->extentY() - 1;
}
entity::run();
}
void entityTinySpinner::spawnTransition()
{
entity::spawnTransition();
mDrift = mInitialSpeed;
mInitialSpeed = Point3d(0, 0, 0);
}
void entityTinySpinner::spawn()
{
entity::spawn();
if (mStateTimer > 0) {
// Make them invincible (and brighter) for a short period of time
// so we don't just pick them off as soon as they spawn
float c = mStateTimer / mSpawnTime;
c = (1 * c) + (.5 * (1 - c));
mPen = vector::pen(1, c, 1, .5, 12);
mStateTimer -= 1;
run();
}
if (mStateTimer <= 0) {
mPen = vector::pen(1, .5, 1, .5, 12);
}
}
void entityTinySpinner::destroyTransition()
{
entity::destroyTransition();
}
void entityTinySpinner::destroy()
{
entity::destroy();
}
entity* entityTinySpinner::hitTest(const Point3d& pos, float radius)
{
Point3d ourPos = mVirtualPos;
float distance = mathutils::calculate2dDistance(pos, ourPos);
float resultRadius = radius + getRadius();
if (distance < resultRadius) {
return this;
}
return nullptr;
}