Dodane regulacja prędkości i płynejsze poruszanie się
This commit is contained in:
@@ -18,19 +18,11 @@ sf::Sprite &Actor::getSprite() {
|
||||
return actorSprite;
|
||||
}
|
||||
|
||||
void Actor::move(float deltaX, float deltaY) {
|
||||
actorSprite.move(deltaX, deltaY);
|
||||
}
|
||||
void Actor::move(float deltaX, float deltaY) {}
|
||||
|
||||
void Actor::moveLeft() {
|
||||
move(-10.0f, 0.0f);
|
||||
position.x -= 10;
|
||||
}
|
||||
void Actor::moveLeft() {}
|
||||
|
||||
void Actor::moveRight() {
|
||||
move(10.0f, 0.0f);
|
||||
position.x += 10;
|
||||
}
|
||||
void Actor::moveRight() {}
|
||||
|
||||
Position Actor::getPosition() {
|
||||
return {position.x, position.y};
|
||||
@@ -43,3 +35,11 @@ void Actor::shoot() {
|
||||
std::vector<Bullet> &Actor::getBullets() {
|
||||
return bullets;
|
||||
}
|
||||
|
||||
void Actor::updateBullets() {
|
||||
for (auto& bullet : bullets) {
|
||||
if(bullet.getStatus()) {
|
||||
bullets.erase(bullets.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
Bullet::Bullet(float x, float y, sf::Texture &bulletTexture) {
|
||||
outOfBounds = false;
|
||||
// bulletTexture.loadFromFile("../assets/img/bullet.png");
|
||||
bulletSprite.setTexture(bulletTexture);
|
||||
bulletSprite.setPosition(x, y);
|
||||
bulletSpeed = -10.0f;
|
||||
@@ -21,9 +20,12 @@ sf::Sprite &Bullet::getSprite() {
|
||||
|
||||
void Bullet::update() {
|
||||
bulletSprite.move(0.0f, bulletSpeed);
|
||||
bulletPosition.y += bulletSpeed;
|
||||
bulletPosition.y += int(bulletSpeed);
|
||||
if(bulletPosition.y < -100) {
|
||||
outOfBounds = true;
|
||||
// std::cout << "Bullet out of bounds\n";
|
||||
}
|
||||
}
|
||||
|
||||
bool Bullet::getStatus() const {
|
||||
return outOfBounds;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,39 @@
|
||||
#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, bulletTexture);
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user