57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
#include "../headers/Player.h"
|
|
#include "../headers/Bullet.h"
|
|
|
|
// TODO: Podzielić na klasy Bullet i Rocket.
|
|
Player::Player(int x, int y, std::string path) : Actor(x, y, path) {
|
|
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, bulletTexture);
|
|
lastShotTime = now;
|
|
}
|
|
}
|
|
|
|
void Player::alternate_shoot() {
|
|
auto now = std::chrono::steady_clock::now();
|
|
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastShotTime).count() >= firerate) {
|
|
rockets.emplace_back(position.x, position.y, rocketTexture).getSprite().scale(1.5f, 1.5f);
|
|
lastShotTime = now;
|
|
}
|
|
}
|
|
|
|
void Player::setFirerate(unsigned int firerate) {
|
|
this->firerate = firerate;
|
|
}
|
|
|
|
void Player::move(float deltaX, float deltaY) {
|
|
actorSprite.move(deltaX, deltaY);
|
|
}
|
|
|
|
void Player::moveLeft() {
|
|
move(-moving_speed, 0.0f);
|
|
position.x -= static_cast<int>(moving_speed);
|
|
}
|
|
|
|
void Player::moveRight() {
|
|
move(moving_speed, 0.0f);
|
|
position.x += static_cast<int>(moving_speed);
|
|
}
|
|
|
|
void Player::moveUp() {
|
|
move(0.0f, -moving_speed);
|
|
position.y -= static_cast<int>(moving_speed);
|
|
}
|
|
|
|
void Player::moveDown() {
|
|
move(0.0f, moving_speed);
|
|
position.y += static_cast<int>(moving_speed);
|
|
}
|
|
|
|
std::vector<Rocket> &Player::getRockets() {
|
|
return rockets;
|
|
}
|