103 lines
3.0 KiB
C++
103 lines
3.0 KiB
C++
#include <iostream>
|
|
#include <chrono>
|
|
|
|
#include "SFML/Graphics.hpp"
|
|
#include "headers/Player.h"
|
|
#include "headers/Bullet.h"
|
|
#include "headers/Background.h"
|
|
#include "headers/AudioManager.h"
|
|
|
|
int main()
|
|
{
|
|
std::clog << "Game started\n";
|
|
sf::RenderWindow window(sf::VideoMode(600, 800), "My window");
|
|
window.setVerticalSyncEnabled(true);
|
|
window.setFramerateLimit(60);
|
|
|
|
Background background("../assets/img/space.png ", 2.0f); //tutaj predkosc tla, mozna zwiekszyc jak za wolno
|
|
|
|
|
|
AudioManager audioManager;
|
|
if (!audioManager.loadBackgroundMusic("../assets/music/background.ogg")) {
|
|
return -1;
|
|
}
|
|
audioManager.playBackgroundMusic();
|
|
|
|
audioManager.loadSoundEffect("shoot", "../assets/sounds/shoot.ogg");
|
|
audioManager.loadSoundEffect("shoot_alt", "../assets/sounds/shoot_alt.ogg");
|
|
|
|
|
|
Player ship(240,650, "../assets/ship/Dreadnought-Base.png"); // tworzenie statku
|
|
ship.setMovingSpeed(8);
|
|
ship.setFirerate(200);
|
|
|
|
while (window.isOpen()) {
|
|
window.clear();
|
|
|
|
// Tu są handlowane eventy
|
|
sf::Event event{};
|
|
while (window.pollEvent(event)) {
|
|
if(event.type == sf::Event::Closed)
|
|
window.close();
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
|
window.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
|
|
}
|
|
}
|
|
|
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
|
|
if(ship.getPosition().x > -10) {
|
|
ship.moveLeft();
|
|
}
|
|
}
|
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
|
|
if(ship.getPosition().x < 480) {
|
|
ship.moveRight();
|
|
}
|
|
}
|
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
|
|
if(ship.getPosition().y > 0) {
|
|
ship.moveUp();
|
|
}
|
|
}
|
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
|
|
if(ship.getPosition().y < 700) {
|
|
ship.moveDown();
|
|
}
|
|
}
|
|
|
|
for (auto& bullet : ship.getBullets()) {
|
|
bullet.update();
|
|
window.draw(bullet.getSprite());
|
|
}
|
|
|
|
// tło
|
|
background.update();
|
|
background.draw(window);
|
|
|
|
for (auto& bullet : ship.getBullets()) {
|
|
bullet.update();
|
|
window.draw(bullet.getSprite());
|
|
}
|
|
|
|
ship.updateBullets();
|
|
window.draw(ship.getSprite());
|
|
window.display();
|
|
}
|
|
|
|
return 0;
|
|
} |