-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.cpp
More file actions
31 lines (25 loc) · 979 Bytes
/
Copy pathBullet.cpp
File metadata and controls
31 lines (25 loc) · 979 Bytes
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
#include "Bullet.h"
#include <raymath.h>
Bullet::Bullet(Vector2 position) : m_rectangle({position.x, position.y, 3, 12}) {}
Rectangle Bullet::getRectangle() const {
return m_rectangle;
}
void Bullet::draw(float speed) {
m_rectangle.y += speed;
DrawRectangleRec(m_rectangle, WHITE);
}
bool Bullet::operator==(const Bullet& other) const {
return Vector2Equals({m_rectangle.x, m_rectangle.y}, {other.m_rectangle.x, other.m_rectangle.y});
}
void Bullet::shoot(std::list<Bullet>* bullets, float x, float y, float shuttleSize, Sound shootSound, double* lastShotTime, bool audio) {
if (IsKeyDown(KEY_SPACE) && GetTime() - *lastShotTime >= 0.35 && bullets->size() < 3) {
(*bullets).emplace_back(Bullet({x + shuttleSize/2, y}));
*lastShotTime = GetTime();
if (audio) PlaySound(shootSound);
}
for (auto &bullet : *bullets) {
if (bullet.m_rectangle.y < 0)
(*bullets).pop_front();
bullet.draw(-8);
}
}