naprawa pozycji + nowe rakiety

This commit is contained in:
2024-11-21 22:42:12 +01:00
parent 2bdfbb193c
commit 343b312227
10 changed files with 14 additions and 14 deletions

BIN
assets/img/Rocket_111.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 B

BIN
assets/img/Rocket_115.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 503 B

BIN
assets/img/meteor-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 563 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 563 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@@ -88,8 +88,8 @@ int main()
for (auto& meteor : plansza.getMeteors()) {
if(ship.getSprite().getGlobalBounds().intersects(meteor.getSprite().getGlobalBounds())) {
std::cout << "You lost the game!\n";
window.close();
exit(-2); // Kod -2 oznacza uderzenie się w meteoryt
// window.close();
// exit(-2); // Kod -2 oznacza uderzenie się w meteoryt
}
}

View File

@@ -5,7 +5,7 @@ Actor::Actor(int x, int y, std::string path) {
position.x = x;
position.y = y;
actorSprite.setOrigin(actorSprite.getLocalBounds().width / 2, actorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
actorSprite.setPosition(x, y);
actorSprite.setPosition(float(x), float(y));
}
void Actor::loadTexture(std::string path) {
@@ -13,7 +13,7 @@ void Actor::loadTexture(std::string path) {
actorSprite.setTexture(actorTexture);
bulletTextureLeft.loadFromFile("../assets/img/bullet_left.png");
bulletTextureRight.loadFromFile("../assets/img/bullet_right.png");
bulletTextureRight.loadFromFile("../assets/img/Rocket_111.png");
}
sf::Sprite &Actor::getSprite() {
@@ -25,7 +25,7 @@ Position Actor::getPosition() {
}
void Actor::shoot() {
bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2-62, position.y, bulletTextureLeft);
bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2, position.y, bulletTextureLeft);
}
std::vector<Bullet> &Actor::getBullets() {

View File

@@ -2,14 +2,14 @@
#include "../headers/Bullet.h"
Bullet::Bullet(float x, float y, sf::Texture &texture) {
bulletPosition.x = x;
bulletPosition.y = y;
outOfBounds = false;
bulletTexture = texture;
bulletSprite.setTexture(texture);
bulletSprite.setOrigin(bulletSprite.getLocalBounds().width/2, bulletSprite.getLocalBounds().height/2);
bulletSprite.setPosition(x, y);
bulletSpeed = -10.0f;
bulletPosition.x = x;
bulletPosition.y = y;
}
void Bullet::setSpeed(float speed) {

View File

@@ -5,7 +5,7 @@
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth) {
size.height = windowHeight;
size.width = windowWidth;
meteorTexture.loadFromFile("../assets/img/meteor.png");
meteorTexture.loadFromFile("../assets/img/meteor-1.png");
spawnClock.restart();
}

View File

@@ -5,7 +5,7 @@ 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, position.y, bulletTextureLeft);
bullets.emplace_back(position.x, position.y, bulletTextureLeft);
lastShotTime = now;
}
}
@@ -13,7 +13,7 @@ void Player::shoot() {
void Player::alternate_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, position.y, bulletTextureRight);
bullets.emplace_back(position.x, position.y, bulletTextureRight).getSprite().scale(1.5f, 1.5f);
lastShotTime = now;
}
}
@@ -28,20 +28,20 @@ void Player::move(float deltaX, float deltaY) {
void Player::moveLeft() {
move(-moving_speed, 0.0f);
position.x -= moving_speed;
position.x -= static_cast<int>(moving_speed);
}
void Player::moveRight() {
move(moving_speed, 0.0f);
position.x += moving_speed;
position.x += static_cast<int>(moving_speed);
}
void Player::moveUp() {
move(0.0f, -moving_speed);
position.y -= moving_speed;
position.y -= static_cast<int>(moving_speed);
}
void Player::moveDown() {
move(0.0f, moving_speed);
position.y += moving_speed;
position.y += static_cast<int>(moving_speed);
}