From e3fd07e606098dd9cdf0b7ed806340d8466b5572 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sun, 11 Feb 2018 22:55:22 +0100 Subject: Reimplement in C++ with SFML (mostly) --- src/main/cpp/Subconscious.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/main/cpp/Subconscious.cpp (limited to 'src/main/cpp/Subconscious.cpp') diff --git a/src/main/cpp/Subconscious.cpp b/src/main/cpp/Subconscious.cpp new file mode 100644 index 0000000..942b0b4 --- /dev/null +++ b/src/main/cpp/Subconscious.cpp @@ -0,0 +1,60 @@ +#include "Subconscious.hpp" +#include "WorldScene.hpp" + +#include + +/*** public methods ***/ + +Subconscious::Subconscious() + : _window(sf::VideoMode(800, 600), "Subconscious") +{ + _window.setVerticalSyncEnabled(true); + _window.setFramerateLimit(90); +} + +Subconscious::~Subconscious() +{} + +void Subconscious::run() +{ + _running = true; + while (_running && _window.isOpen()) { + gameUpdate(); + gameRender(); + } +} + +void Subconscious::demo() +{ + Scene *demoScene = new WorldScene(); + + _currentScene = demoScene; + _scenes.push_back(demoScene); + + run(); +} + + +/*** private methods ***/ + +void Subconscious::gameUpdate() +{ + sf::Event event; + + while (_window.pollEvent(event)) { + if (event.type == sf::Event::Closed) { + _window.close(); + } + } +} + +void Subconscious::gameRender() +{ + _window.clear(); + + if (_currentScene != nullptr) { + _currentScene->render(_window); + } + + _window.display(); +} -- cgit v1.2.1