-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.cpp
More file actions
82 lines (69 loc) · 1.6 KB
/
Bullet.cpp
File metadata and controls
82 lines (69 loc) · 1.6 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
#include "Bullet.h"
#include "RaylibWrapper.h"
#include <math.h>
Bullet::Bullet()
{
_position = { 0,0 };
_velocity = { 0,0 };
_speed = 0;
_rotation = 0;
_size = { 0,0 };
_damage = 0;
_lifeTime = 0;
_color = BLANC;
}
void Bullet::Create(Vec2<float> position, Vec2<float> size, int damage, Couleur color)
{
_damage = damage;
_position = position;
_color = color;
_size = size;
_velocity = { 0,0 };
_speed = 0;
_rotation = 0;
_lifeTime = 0;
}
void Bullet::Init(Vec2<float> baseVelocity, float speed, float rotation)
{
_speed = speed;
_rotation = rotation;
float force_x = (float)cos(rotation * DEG2RAD) * _speed * raywrp::GetDeltaTime();
float force_y = (float)sin(rotation * DEG2RAD) * _speed * raywrp::GetDeltaTime();
_velocity.SetX(force_x);
_velocity.SetY(force_y);
if (baseVelocity.GetX() > 0 && _velocity.GetX() > 0
|| baseVelocity.GetX() < 0 && _velocity.GetX() < 0)
{
_velocity.SetX(_velocity.GetX() + baseVelocity.GetX());
}
if (baseVelocity.GetY() > 0 && _velocity.GetY() > 0
|| baseVelocity.GetY() < 0 && _velocity.GetY() < 0)
{
_velocity.SetY(_velocity.GetY() + baseVelocity.GetY());
}
_lifeTime = 10.0f;
_actif = true;
}
void Bullet::Update()
{
Sprite::Update();
if (_lifeTime > 0)
{
_lifeTime -= raywrp::GetDeltaTime();
}
else
{
_actif = false;
}
}
void Bullet::Draw()
{
Rect forme{ _position.GetX(), _position.GetY(), _size.GetX(), _size.GetY() };
Vec2<float> origin = _size / 2.0f;
raywrp::DrawRectangle(forme, origin, _rotation, _color);
// raywrp::DrawCircleV(_position, _size.GetY(), _color);
}
Vec2<float> Bullet::GetPosition()
{
return _position;
}