Код: Выделить всё
//Game loop
while (game.running()) {
//Update
//Render
}
Код: Выделить всё
//THIS IS THE "Game.h" FILE!!!
#pragma once
#include
#include
#include
#include
#include
#include
using namespace sf;
using namespace std;
/*
Class that acts as the game engine.
Wrapper class.
*/
class Game {
private:
//Variables
//Window
RenderWindow* window;
VideoMode videoMode;
Event ev;
//Private Functions
void initVariables();
void initWindow();
public:
//Constructors / Destructors
Game();
virtual ~Game();
//Accessors
const bool running() const;
//Functions
void update();
void render();
};
//THIS IS THE "Game.cpp" FILE!!!
#include "Game.h"
//Private functions
void Game::initVariables() {
this->window = nullptr;
}
void Game::initWindow() {
this->videoMode.width = 1280;
this->videoMode.height = 720;
this->window = new RenderWindow(this->videoMode, "Cannoneer", Style::Titlebar | Style::Close);
}
//Constructors / Destructors
Game::Game() {
this->initVariables();
this->initWindow();
}
Game::~Game() {
delete this->window;
}
//Accessors
const bool Game::running() const
{
return this->window->isOpen();
}
//Functions
void Game::update() {
}
void Game::render() {
}
//THIS IS THE "main.cpp" FILE!!!
#include "Game.h"
int main() {
//Initialize game engine
Game game();
//Game loop
while (game.running()) {
//Update
//Render
}
//End of application
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/789 ... -type-game