Merge zrobiony
This commit is contained in:
48
main.cpp
48
main.cpp
@@ -28,16 +28,18 @@ int main()
|
||||
audioManager.loadSoundEffect("shoot", "../assets/sounds/shoot.ogg");
|
||||
audioManager.loadSoundEffect("shoot_alt", "../assets/sounds/shoot_alt.ogg");
|
||||
|
||||
|
||||
// TODO: Przenieść tworzenie statku wewnątrz klasy Plansza
|
||||
Player ship(mainWindow.getSize().x / 2, mainWindow.getSize().y - 100, "../assets/ship/Dreadnought-Base.png"); // tworzenie statku
|
||||
ship.setMovingSpeed(8);
|
||||
ship.setFirerate(200);
|
||||
|
||||
while (mainWindow.isOpen()) {
|
||||
// std::cout << "Liczba: " << RandomNumberGenerator::getRandomNumber(0,499) << std::endl;
|
||||
mainWindow.clear();
|
||||
|
||||
// tło
|
||||
background.update();
|
||||
background.draw(mainWindow);
|
||||
|
||||
// Tu są handlowane eventy
|
||||
sf::Event event{};
|
||||
while (mainWindow.pollEvent(event)) {
|
||||
@@ -46,23 +48,9 @@ int main()
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
||||
mainWindow.close();
|
||||
}
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
|
||||
ship.shoot();
|
||||
audioManager.playSoundEffect("shoot");
|
||||
}
|
||||
}
|
||||
|
||||
if(event.type == sf::Event::MouseButtonPressed) {
|
||||
if(event.mouseButton.button == sf::Mouse::Left) {
|
||||
ship.shoot();
|
||||
audioManager.playSoundEffect("shoot", 70.f); // Odtworzenie dźwięku wystrzału
|
||||
} else {
|
||||
ship.alternate_shoot();
|
||||
audioManager.playSoundEffect("shoot_alt", 70.f); // Odtworzenie dźwięku dla alternatywnego strzału
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// poruszanie się statkiem
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
|
||||
if(ship.getPosition().x > 50) {
|
||||
ship.moveLeft();
|
||||
@@ -83,19 +71,22 @@ int main()
|
||||
ship.moveRight();
|
||||
}
|
||||
}
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
|
||||
|
||||
// strzelanie ze statku
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
|
||||
ship.shoot();
|
||||
audioManager.playSoundEffect("shoot", 70.f); // Odtworzenie dźwięku wystrzału
|
||||
}
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
|
||||
ship.alternate_shoot();
|
||||
audioManager.playSoundEffect("shoot_alt", 70.f); // Odtworzenie dźwięku dla alternatywnego strzału
|
||||
}
|
||||
|
||||
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) ship.shoot();
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Right)) ship.alternate_shoot();
|
||||
|
||||
// Generate a new meteor at a random position at the top of the screen
|
||||
// generowanie nowego meteoru
|
||||
plansza.spawn_meteor();
|
||||
|
||||
|
||||
// Update and draw meteors
|
||||
// utrzymanie meteorów i pocisków w ruchu
|
||||
for (auto& meteor : plansza.getMeteors()) {
|
||||
meteor.update();
|
||||
mainWindow.draw(meteor.getSprite());
|
||||
@@ -106,13 +97,10 @@ int main()
|
||||
mainWindow.draw(bullet.getSprite());
|
||||
}
|
||||
|
||||
// tło
|
||||
background.update();
|
||||
background.draw(mainWindow);
|
||||
|
||||
|
||||
// Sprawdzenie czy meteory i pociski są poza granicami ekranu
|
||||
plansza.update_meteors();
|
||||
ship.updateBullets();
|
||||
|
||||
mainWindow.draw(ship.getSprite());
|
||||
|
||||
// trochę dziwny sposób ale jednak działa
|
||||
@@ -152,7 +140,7 @@ int main()
|
||||
bulletIt = ship.getBullets().erase(bulletIt);
|
||||
meteorIt = plansza.getMeteors().erase(meteorIt);
|
||||
meteorHit = true;
|
||||
break; // Exit the inner loop to avoid invalidating the iterator
|
||||
break;
|
||||
} else {
|
||||
++bulletIt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user