-
Notifications
You must be signed in to change notification settings - Fork 2
/
Enemy_RotatoryTank.cpp
161 lines (129 loc) · 4.26 KB
/
Enemy_RotatoryTank.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "Application.h"
#include "Enemy_RotatoryTank.h"
#include "ModuleCollision.h"
#include "ModuleParticles.h"
#include "ModulePlayer.h"
#include "ModuleRender.h"
Enemy_RotatoryTank::Enemy_RotatoryTank(int x, int y) : Enemy(x, y)
{
walk.SetUp(629, 635, 94, 93, 3, 3, "0,1,2");
walk.speed = 0.2f;
turret.SetUp(629, 729, 44, 46, 1, 1, "0");
turret_shooting.SetUp(673, 729, 44, 46, 1, 1, "0");
turret_shooting.speed = 0.2f;
turret_shooting.loop = false;
animation_hurt.SetUp(629, 635, 94, 93, 4, 4, "2,3,2,3,2");
path.PushBack({ 0,0 }, 50, &walk);
if (position.x > SCREEN_WIDTH / 2)
{
path.PushBack({ 0,0 }, 100, &walk);
path.PushBack({ -1,0 }, 100, &walk);
path.PushBack({ 0,-1 }, 50, &walk);
path.PushBack({ 0,0 }, 50, &walk);
path.PushBack({ 0,-1.2f }, 120, &walk);
path.PushBack({ 0,0 }, 2000, &walk);
/*path.LoopStart(250);*/
}
if (position.x < SCREEN_WIDTH / 2)
{
path.PushBack({ 0,0 }, 100, &walk);
path.PushBack({ 1,0 }, 100, &walk);
path.PushBack({ 0,-1 }, 50, &walk);
path.PushBack({ 0,0 }, 50, &walk);
path.PushBack({ 0,-1.2f }, 120, &walk);
path.PushBack({ 0,0 }, 2000, &walk);
/*path.LoopStart(250);*/
}
collider_offset.x = 7;
collider_offset.y = 17;
collider = App->collision->AddCollider({ 200, 0, 70, 55 }, COLLIDER_TYPE::COLLIDER_ENEMY_GROUND, (Module*)App->enemies);
original_position = position;
sdl_clock_start = SDL_GetTicks();
sdl_clock = sdl_clock_start + 2000 + 850;
type = GROUND;
hitpoints = 10;
}
Enemy_RotatoryTank::~Enemy_RotatoryTank()
{
walk.CleanUp();
turret.CleanUp();
turret_shooting.CleanUp();
}
void Enemy_RotatoryTank::Draw(SDL_Texture * sprites)
{
App->collision->SetPosition(collider, position.x + collider_offset.x, position.y + collider_offset.y);
iPoint turret_direction;
float factor = M_PI / 180;
turret_direction.x = (100 * cos((turret_angle - 90) * factor));
turret_direction.y = (100 * -sin((turret_angle - 90) * factor));
if (rotating) {
turret_angle -= 12;
if (turret_angle <= -360) {
rotating = false;
turret_angle = 0;
}
}
switch (state) {
case REGULAR:
if (animation != nullptr) {
App->render->Blit(type, sprites, position.x, position.y, direction, &(animation->GetCurrentFrame()));
App->render->Blit(type, sprites, position.x + 20, position.y + 20, turret_direction, &(turret.GetCurrentFrame()));
}
break;
case SHOOTING:
rotating = true;
App->render->Blit(type, sprites, position.x, position.y, direction, &(animation->GetCurrentFrame()));
App->render->Blit(type, sprites, position.x + 20, position.y + 20, turret_direction, &(turret_shooting.GetCurrentFrame()));
if (turret_shooting.Finished()) {
state = REGULAR;
animation_hurt.Reset();
}
break;
case HURT:
App->render->Blit(type, sprites, position.x, position.y, direction, &(animation_hurt.GetCurrentFrame()));
App->render->Blit(type, sprites, position.x + 20, position.y + 20, turret_direction, &(turret_shooting.GetCurrentFrame()));
if (animation_hurt.Finished()) {
state = REGULAR;
animation_hurt.Reset();
}
break;
}
}
void Enemy_RotatoryTank::Move()
{
position = original_position + path.GetCurrentPosition(&animation);
iPoint origin = position;
origin.x = origin.x + 40;
origin.y = origin.y + walk.CurrentFrame().h - 54;
float factor = (float)M_PI / 180.0f;
if (shot_angle <= 720 && SDL_GetTicks() >= sdl_clock) {
int radius = 1;
fPoint shot_vector;
shot_vector.x = (radius * cos((shot_angle - 90) * factor));
shot_vector.y = (radius * sin((shot_angle - 90) * factor));
LOG("Direction x: %f, Direction y: %f", shot_vector.x, shot_vector.y);
Shoot(origin, shot_vector);
shot_angle += 45;
}
}
void Enemy_RotatoryTank::Shoot(iPoint origin, fPoint direction)
{
state = SHOOTING;
turret_shooting.Reset();
sdl_clock = SDL_GetTicks() + 150;
App->particles->AddParticle(ENEMYSHOT, origin.x, origin.y, direction);
App->particles->AddParticle(ENEMYSHOT, origin.x, origin.y, direction * -1);
/*sdl_clock_start = sdl_clock + 3167;*/
}
void Enemy_RotatoryTank::OnCollision(Collider* collider)
{
if (state != HURT) {
if (--hitpoints == 0) {
App->particles->AddParticle(BIG_EXPLOSION, position.x - 25, position.y - 40);
App->particles->AddParticle(CRATER, position.x + 5, position.y + 5);
App->player->AddScore(200, collider->type);
}
else
state = HURT;
}
}