-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.cpp
147 lines (100 loc) · 3.79 KB
/
Enemy.cpp
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
#include "Enemy.h"
#include "Sounds.h"
#include "GameLoop.h"
#define currentpos QPointF(getX(), getY())
double kirbyDistance(QPointF pos) {
return abs(pitagoricDistance(GameLoop::getInstance().getKirbyPos(), pos));
}
void WaddleDee::tick(double delta)
{
double dist = kirbyDistance(currentpos);
if (dist <= 2 && dist >= 1.95 && isGrounded())
jump(-5);
accel.y = 9.8;
if (this->hit && lastHitNormals.x != 0 && lastHitNormals.y == 0)
velocity.x = maxwalkspeed * (velocity.x > 0 ? 1 : -1);
Enemy::tick(delta);
}
void HotHead::tick(double delta)
{
accel.y = 9.8;
if (this->hit && lastHitNormals.x != 0 && lastHitNormals.y == 0)
accel.x = maxwalkspeed * (velocity.x > 0 ? 1 : -1);
Enemy::tick(delta);
}
void PoppyBrosJr::tick(double delta)
{
accel.y = 9.8;
accel.x = 1.2*maxwalkspeed * (GameLoop::getInstance().getKirbyPos().x() > getX() ? 1 : -1);
if (abs(GameLoop::getInstance().getKirbyPos().x() - getX()) < 4 && (GameLoop::getInstance().getKirbyPos().y() < getY()) && isGrounded())
jump(-8);
if (this->hit && lastHitNormals.x != 0 && lastHitNormals.y == 0)
accel.x = maxwalkspeed * (velocity.x > 0 ? 1 : -1);
if (!(rand() % 120)) {
QPointF kirbyPos = GameLoop::getInstance().getKirbyPos();
QPointF startPos = getCollider().center();
// Invert y
//startPos.setY(startPos.y() * -1);
kirbyPos.setY(kirbyPos.y()-2);
KA::Vec2Df anglebetweenkirbyandpoppy = getLineBetweenVerts(startPos, kirbyPos);
double ang = (anglebetweenkirbyandpoppy.x);
//while (ang > M_PI / 4.0) {
// ang -= (M_PI / 4.0);
//}
double dY = kirbyPos.y() - startPos.y(), dX = kirbyPos.x() - startPos.x();
double hit_time = 0.4;
double VxSq = pow(dX/hit_time,2);
double finalangle = 0;
double xVelFinal = 90;
double yVelFinal = 90;
double FModule = 999;
double FA = atan((dY + (9.81 * (pow(kirbyPos.x(), 2) + pow(startPos.x(), 2) - (2 * startPos.x() * kirbyPos.x())) / (2 * VxSq))) / dX);
xVelFinal = sqrt(VxSq) * (dX < 0 ? -1 : 1);
FModule = (xVelFinal / cos(FA));
yVelFinal = FModule * sin(FA);
if (abs(FModule) > 35)
return;
//std::cout << "Shooting with xVel: " << xVelFinal << " and yVel: " << yVelFinal << " and Module: " << FModule << "\n";
objects::ObjectID targets[] = { objects::KIRBY };
Projectile* p = new Projectile(getCollider().center(),
KA::Vec2Df{ 0,0 },
TextureManager::getInstance().getAnimatable(TexManager::SWORD), targets, 1,
1500, 0.35);
p->velocity = {xVelFinal, yVelFinal};
GameLoop::getInstance().addElement(dynamic_cast<GameObject*>(p));
}
Enemy::tick(delta);
}
void BrontoBurt::tick(double delta) {
time += delta;
accel.x = -1;
accel.y = Y_accel * (sin(2 * M_PI * 0.6 * time));
if (this->hit && lastHitNormals.x != 0 && lastHitNormals.y == 0) {
accel.x = maxwalkspeed * (velocity.x > 0 ? 1 : -1);
//velocity.x = 0;
//std::cout << "Hit: " << lastHitNormals.x << ":" << lastHitNormals.y << "\n";
}
Enemy::tick(delta);
}
void Sparky::tick(double delta) {
accel.y = 9.8;
//if (this->hit && lastHitNormals.x != 0 && lastHitNormals.y == 0) {
//accel.x = maxwalkspeed * (velocity.x > 0 ? 1 : -1);
//velocity.x = 0;
//std::cout << "Hit: " << lastHitNormals.x << ":" << lastHitNormals.y << "\n";
//}
if (!(rand() % 200)) {
animator->playOneShot(TextureManager::getInstance().getAnimatable(TexManager::SPARKY_JUMP));
jump(-4);
objects::ObjectID targets[] = { objects::KIRBY };
int steps = 25;
for (int i = 0; i < steps; i++) {
Projectile* p = new Projectile(getCollider().center(),
KA::Vec2Df{ 0,0 },
TextureManager::getInstance().getAnimatable(TexManager::SPARKY_JUMP), targets, 1,1500, 0.15);
p->velocity = {sin(M_PI * (i - (steps/2.0))/steps), -6 * cos(M_PI * (i - (steps / 2.0)) / steps) };
GameLoop::getInstance().addElement(dynamic_cast<GameObject*>(p));
}
}
Enemy::tick(delta);
}