-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathentitymayfly.cpp
More file actions
174 lines (132 loc) · 4.3 KB
/
entitymayfly.cpp
File metadata and controls
174 lines (132 loc) · 4.3 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
167
168
169
170
171
172
173
174
#include "entitymayfly.hpp"
#include "game.hpp"
#include "players.hpp"
#include "scene.hpp"
#include <SDL3/SDL_opengl.h>
entityMayfly::entityMayfly()
: entity()
{
mScale = 0.8;
mRadius = 2.5;
mScoreValue = 50;
mType = ENTITY_TYPE_MAYFLY;
setState(ENTITY_STATE_INACTIVE);
mFlipTimer = mathutils::frandFrom0To1() * 15;
mFlipDirection = 1;
mPen = vector::pen(.5, .5, 1, 1, 12);
int i = 0;
mModel.mVertexList.resize(6);
mModel.mVertexList[i++] = Point3d(-.25, 1.25);
mModel.mVertexList[i++] = Point3d(.25, 1.25);
mModel.mVertexList[i++] = Point3d(1.2, -.5);
mModel.mVertexList[i++] = Point3d(1, -.9);
mModel.mVertexList[i++] = Point3d(-1, -.9);
mModel.mVertexList[i++] = Point3d(-1.2, -.5);
i = 0;
mModel.mEdgeList.resize(3);
mModel.mEdgeList[i].from = 0;
mModel.mEdgeList[i++].to = 3;
mModel.mEdgeList[i].from = 1;
mModel.mEdgeList[i++].to = 4;
mModel.mEdgeList[i].from = 2;
mModel.mEdgeList[i++].to = 5;
}
void entityMayfly::draw()
{
if (this->getState() == entity::ENTITY_STATE_INDICATING) {
if (((int)(mStateTimer / 10)) & 1) {
vector::pen pen = mPen;
mModel.draw(pen);
}
} else if (this->getEnabled() && (this->getState() != entity::ENTITY_STATE_SPAWN_TRANSITION)) {
vector::pen pen = mPen;
if (scene::mPass == scene::RENDERPASS_BLUR) {
pen.r = .1;
pen.g = .1;
pen.b = 1;
pen.a = 1;
pen.lineRadius = 18 * 2;
}
if (getState() == ENTITY_STATE_SPAWNING) {
Point3d scale = mScale;
Point3d trans = mPos;
float inc = 1.0f / mSpawnTime;
float progress = mStateTimer * inc;
// *********************************************
glLineWidth(pen.lineRadius * .3);
glBegin(GL_LINES);
progress = 1 - progress;
float a = progress;
if (a < 0)
a = 0;
if (a > 1)
a = 1;
pen.a = a;
mModel.Identity();
mModel.Scale(scale * progress * 1);
mModel.Rotate(mAngle);
mModel.Translate(trans);
mModel.emit(pen);
// *********************************************
progress = progress + .25;
a = 1 - progress;
if (a < 0)
a = 0;
if (a > 1)
a = 1;
pen.a = a;
mModel.Identity();
mModel.Scale(scale * progress * 4);
mModel.Rotate(mAngle);
mModel.Translate(trans);
mModel.emit(pen);
// *********************************************
progress = progress + .25;
a = 1 - progress;
if (a < 0)
a = 0;
if (a > 1)
a = 1;
pen.a = a;
mModel.Identity();
mModel.Scale(scale * progress * 7);
mModel.Rotate(mAngle);
mModel.Translate(trans);
mModel.emit(pen);
// *********************************************
// Restore stuff
mModel.Identity();
mModel.Rotate(mAngle);
mModel.Scale(scale);
mModel.Translate(trans);
glEnd();
}
mModel.draw(pen);
}
}
void entityMayfly::run()
{
if (this->getEnabled()) {
// Seek the player
// Run animation
if (--mFlipTimer <= 0) {
mFlipTimer = 15;
mFlipDirection = -mFlipDirection;
// Update the target
mTarget = theGame->mPlayers->getPlayerClosestToPosition(mPos)->getPos();
mTarget.x += (mathutils::frandFrom0To1() * 30) - 15;
mTarget.y += (mathutils::frandFrom0To1() * 30) - 15;
}
float desiredAngle = 1.2 * mFlipDirection;
float diff = desiredAngle - mAngle;
mRotationRate += diff * .03;
mRotationRate *= .9;
float angle = mathutils::calculate2dAngle(mPos, mTarget);
Point3d moveVector(1, 0, 0);
moveVector = mathutils::rotate2dPoint(moveVector, angle);
mSpeed += moveVector * .5;
mSpeed = mathutils::clamp2dVector(mSpeed, .45 * mAggression);
mSpeed *= .9;
}
entity::run();
}