This repository has been archived on 2025-06-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
LotoStatek/main.cpp

65 lines
1.7 KiB
C++

#include <iostream>
#include "SFML/Graphics.hpp"
#include "headers/Actor.h"
#include "headers/Player.h"
#include "headers/Bullet.h"
int main()
{
std::clog << "Game started\n";
sf::RenderWindow window(sf::VideoMode(600, 800), "My window");
window.setVerticalSyncEnabled(true);
window.setFramerateLimit(60);
sf::Texture backgroundTexture;
backgroundTexture.loadFromFile("../assets/img/background.jpg"); // wczytywanie tła
sf::Sprite backgroundSprite(backgroundTexture); // tworzenie tła
Player ship(240,650, "../assets/ship/Dreadnought-Base.png"); // tworzenie statku
while (window.isOpen()) {
window.clear();
window.draw(backgroundSprite); // narysuj tło
// Tu są handlowane eventy
sf::Event event{};
while (window.pollEvent(event)) {
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
if(ship.getPosition().x > -10) {
ship.moveLeft();
}
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
if(ship.getPosition().x < 480) {
ship.moveRight();
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
ship.shoot();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
window.close();
}
if (event.type == sf::Event::Closed)
window.close();
}
for (auto& bullet : ship.getBullets()) {
bullet.update();
window.draw(bullet.getSprite());
}
ship.updateBullets();
window.draw(ship.getSprite());
window.display();
}
return 0;
}