39 lines
979 B
C++
39 lines
979 B
C++
#include "../headers/Player.h"
|
|
|
|
Player::Player(int x, int y, std::string path) : Actor(x, y, path) {};
|
|
|
|
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(float(position.x) + actorSprite.getGlobalBounds().width / 2-62, position.y, bulletTextureLeft);
|
|
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 -= moving_speed;
|
|
}
|
|
|
|
void Player::moveRight() {
|
|
move(moving_speed, 0.0f);
|
|
position.x += moving_speed;
|
|
}
|
|
|
|
void Player::moveUp() {
|
|
move(0.0f, -moving_speed);
|
|
position.y -= moving_speed;
|
|
}
|
|
|
|
void Player::moveDown() {
|
|
move(0.0f, moving_speed);
|
|
position.y += moving_speed;
|
|
} |