created Game class; main.cpp calls the Game class to render the game
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -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
|
||||
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
|
||||
71
Chinczyk188/Game.cpp
Normal file
71
Chinczyk188/Game.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "Game.hpp"
|
||||
#include <iostream>
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
22
Chinczyk188/Game.hpp
Normal file
22
Chinczyk188/Game.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
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();
|
||||
};
|
||||
@@ -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)
|
||||
|
||||
@@ -1,24 +1,16 @@
|
||||
#include <SFML/Graphics.hpp>
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user