-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrocket.cpp
More file actions
44 lines (37 loc) · 1.23 KB
/
rocket.cpp
File metadata and controls
44 lines (37 loc) · 1.23 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
#include "Rocket.h"
#include "precomp.h"
namespace Tmpl8
{
Rocket::Rocket(vec2 position, vec2 direction, float collision_radius, allignments allignment, Sprite* rocket_sprite)
: position(position), speed(direction), collision_radius(collision_radius), allignment(allignment), current_frame(0), rocket_sprite(rocket_sprite), active(true)
{
}
Rocket::~Rocket()
{
}
void Rocket::Tick()
{
position += speed;
if (++current_frame > 8) current_frame = 0;
}
//Draw the sprite with the facing based on this rockets movement direction
void Rocket::Draw(Surface* screen)
{
rocket_sprite->SetFrame(((abs(speed.x) > abs(speed.y)) ? ((speed.x < 0) ? 3 : 0) : ((speed.y < 0) ? 9 : 6)) + (current_frame / 3));
rocket_sprite->Draw(screen, (int)position.x - 12, (int)position.y - 12);
}
//Does the given circle collide with this rockets collision circle?
bool Rocket::Intersects(vec2 position_other, float radius_other) const
{
//Uses squared lengths to remove expensive square roots
float distance_sqr = (position_other - position).sqrLength();
if (distance_sqr <= ((collision_radius * collision_radius) + (radius_other * radius_other)))
{
return true;
}
else
{
return false;
}
}
} // namespace Tmpl8