diff --git a/assets/img/background.jpg b/assets/img/background.jpg deleted file mode 100644 index 25b278f..0000000 Binary files a/assets/img/background.jpg and /dev/null differ diff --git a/assets/img/space.jpg b/assets/img/space.jpg new file mode 100644 index 0000000..e89568d Binary files /dev/null and b/assets/img/space.jpg differ diff --git a/headers/Actor.h b/headers/Actor.h index 0bbdb2b..7ba2175 100644 --- a/headers/Actor.h +++ b/headers/Actor.h @@ -41,6 +41,7 @@ public: protected: sf::Sprite actorSprite; sf::Texture actorTexture; + sf::Texture bulletTexture; Position position; unsigned int hp; unsigned int damage; diff --git a/headers/Bullet.h b/headers/Bullet.h index 5f6a901..40dc448 100644 --- a/headers/Bullet.h +++ b/headers/Bullet.h @@ -11,7 +11,7 @@ class Bullet { }; public: - Bullet(float x, float y); + Bullet(float x, float y, sf::Texture &bulletTexture); void update(); sf::Sprite& getSprite(); void setSpeed(float speed); diff --git a/main.cpp b/main.cpp index c6e648e..a4bb5cc 100644 --- a/main.cpp +++ b/main.cpp @@ -13,7 +13,7 @@ int main() window.setFramerateLimit(60); sf::Texture backgroundTexture; - backgroundTexture.loadFromFile("../assets/img/background.jpg"); // wczytywanie tła + backgroundTexture.loadFromFile("../assets/img/space.jpg"); // wczytywanie tła sf::Sprite backgroundSprite(backgroundTexture); // tworzenie tła Player ship(240,650, "../assets/ship/Dreadnought-Base.png"); // tworzenie statku @@ -41,6 +41,10 @@ int main() ship.shoot(); } + if(event.type == sf::Event::MouseButtonPressed) { + ship.shoot(); + } + if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { window.close(); } diff --git a/sources/Actor.cpp b/sources/Actor.cpp index d1a57dd..6e10cd2 100644 --- a/sources/Actor.cpp +++ b/sources/Actor.cpp @@ -10,6 +10,8 @@ Actor::Actor(int x, int y, std::string path) { void Actor::loadTexture(std::string path) { actorTexture.loadFromFile(path); actorSprite.setTexture(actorTexture); + + bulletTexture.loadFromFile("../assets/img/bullet.png"); } sf::Sprite &Actor::getSprite() { @@ -35,10 +37,9 @@ Position Actor::getPosition() { } void Actor::shoot() { - bullets.emplace_back(position.x + actorSprite.getGlobalBounds().width / 2-62, position.y); + bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2-62, position.y, bulletTexture); } std::vector &Actor::getBullets() { return bullets; } - diff --git a/sources/Bullet.cpp b/sources/Bullet.cpp index fa2906f..c655bac 100644 --- a/sources/Bullet.cpp +++ b/sources/Bullet.cpp @@ -1,9 +1,9 @@ #include #include "../headers/Bullet.h" -Bullet::Bullet(float x, float y) { +Bullet::Bullet(float x, float y, sf::Texture &bulletTexture) { outOfBounds = false; - bulletTexture.loadFromFile("../assets/img/bullet.png"); +// bulletTexture.loadFromFile("../assets/img/bullet.png"); bulletSprite.setTexture(bulletTexture); bulletSprite.setPosition(x, y); bulletSpeed = -10.0f; @@ -24,6 +24,6 @@ void Bullet::update() { bulletPosition.y += bulletSpeed; if(bulletPosition.y < -100) { outOfBounds = true; - std::cout << "Bullet out of bounds\n"; +// std::cout << "Bullet out of bounds\n"; } }