New Projectiles class

Refactor of Bullet class
Different method of shooting.
This commit is contained in:
2024-12-01 17:44:25 +01:00
parent 2f6c98f4be
commit 2341c2fa6d
11 changed files with 127 additions and 62 deletions

View File

@@ -3,22 +3,22 @@
// TODO: Podzielić na klasy Bullet i Rocket.
Player::Player(int x, int y, std::string path) : Actor(x, y, path) {
Bullet::bulletTexture.loadFromFile("../assets/img/bullet_left.png");
bulletTexture.loadFromFile("../assets/img/bullet_left.png");
rocketTexture.loadFromFile("../assets/img/Rocket_111.png");
};
void Player::shoot() {
auto now = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {
bullets.emplace_back(position.x, position.y);
bullets.emplace_back(position.x, position.y, bulletTexture);
lastShotTime = now;
}
}
// TODO: Czy strzał prawym musi mieć osobną tablicę z pociskami?
void Player::alternate_shoot() {
auto now = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {
rightBullets.emplace_back(position.x, position.y).getSprite().scale(1.5f, 1.5f);
rockets.emplace_back(position.x, position.y, rocketTexture).getSprite().scale(1.5f, 1.5f);
lastShotTime = now;
}
}
@@ -49,4 +49,8 @@ void Player::moveUp() {
void Player::moveDown() {
move(0.0f, moving_speed);
position.y += static_cast<int>(moving_speed);
}
}
std::vector<Rocket> &Player::getRockets() {
return rockets;
}