diff --git a/.gitignore b/.gitignore index 06ced92..699531e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,8 @@ Chinczyk188/res/SFML # EN: Executable created by g++ (mingw). # PL: Plik wykonywalny tworzony przez g++ (mingw). output.exe -Chinczyk188/output.exe \ No newline at end of file +Chinczyk188/output.exe + +# EN: Don't include include directory with Doxygen documentation. +# PL: Aby nie brać pod uwagę katalogu include z dokumentacją Doxygen. +Chiczyk188/include \ No newline at end of file diff --git a/Chinczyk188/Game.cpp b/Chinczyk188/Game.cpp new file mode 100644 index 0000000..82ed9dc --- /dev/null +++ b/Chinczyk188/Game.cpp @@ -0,0 +1,71 @@ +#include "Game.hpp" +#include + +void Game::initVariables() { + + this->window = nullptr; + +} + +void Game::initWindow() { + + this->videoMode = sf::VideoMode::getDesktopMode(); + this->videoMode.width /= 2; + this->videoMode.height /= 2; + + this->window = new sf::RenderWindow(this->videoMode, "Chinczyk188", sf::Style::Default); + +} + +Game::Game() { + + this->initVariables(); + this->initWindow(); + +} + +Game::~Game() { + + delete this->window; + +} + +const bool Game::running() const { + + return this->window->isOpen(); + +} + +void Game::pollEvents() { + + while (this->window->pollEvent(this->ev)) { + switch (this->ev.type) { + case sf::Event::Closed: + this->window->close(); + break; + case sf::Event::KeyPressed: + if (this->ev.key.code == sf::Keyboard::Escape) this->window->close(); + break; + } + } +} + +void Game::update() { + + this->pollEvents(); + +} + +void Game::render() { + + // EN: Render logic + // PL: Mechanizm renderowania + this->window->clear(sf::Color(255, 0, 0, 255)); + + + + // PL: Mechanizm wyświetlania + // W celu wyświetlenia na ekranie wyniku renderowania + this->window->display(); + +} \ No newline at end of file diff --git a/Chinczyk188/Game.hpp b/Chinczyk188/Game.hpp new file mode 100644 index 0000000..a349fc9 --- /dev/null +++ b/Chinczyk188/Game.hpp @@ -0,0 +1,22 @@ +#pragma once +#include + +class Game { + private: + sf::RenderWindow* window; + sf::VideoMode videoMode; + sf::Event ev; + + void initVariables(); + void initWindow(); + + public: + Game(); + virtual ~Game(); + + const bool running() const; + void pollEvents(); + + void update(); + void render(); +}; \ No newline at end of file diff --git a/Chinczyk188/Makefile b/Chinczyk188/Makefile index c0a30ab..84568e9 100644 --- a/Chinczyk188/Makefile +++ b/Chinczyk188/Makefile @@ -9,7 +9,7 @@ OUTPUT = output.exe CPPSTD = c++17 default: - $(CC) -g "*.cpp" $(CFLAGS) $(DEPS) $(LINK) -std=$(CPPSTD) -static -static-libgcc -fno-keep-inline-dllexport -o $(OUTPUT) + $(CC) -g "*.cpp" $(DEPS) $(LINK) -std=$(CPPSTD) -static -static-libgcc -fno-keep-inline-dllexport -o $(OUTPUT) run: default $(OUTPUT) diff --git a/Chinczyk188/main.cpp b/Chinczyk188/main.cpp index 4a5b9da..1d6dbed 100644 --- a/Chinczyk188/main.cpp +++ b/Chinczyk188/main.cpp @@ -1,24 +1,16 @@ -#include +#include "Game.hpp" -int main() -{ - sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!"); - sf::CircleShape shape(100.f); - shape.setFillColor(sf::Color::Green); +int main() { - while (window.isOpen()) - { - sf::Event event; - while (window.pollEvent(event)) - { - if (event.type == sf::Event::Closed) - window.close(); - } + Game game; - window.clear(); - window.draw(shape); - window.display(); - } + while(game.running()) { - return 0; + game.update(); + + game.render(); + + } + + return 0; } \ No newline at end of file