Basic Movements

Basic Movement
Interface classes renamed
Fixed few bugs
This commit is contained in:
Syntriax
2020-06-09 20:12:26 +03:00
parent 3b8affae37
commit 8341d82660
9 changed files with 255 additions and 23 deletions

View File

@@ -1,5 +1,7 @@
#include "SynEngine.hpp"
Timer GameManager::timer;
class GameWindow
{
private:
@@ -8,17 +10,20 @@ class GameWindow
std::string title;
sf::Uint32 style;
sf::RenderWindow window;
Timer timer;
Timer *timer;
GameConfiguration *config;
Drawable *drawable;
void (Drawable::*draw)(sf::RenderWindow *);
IDrawable *drawable;
void (IDrawable::*draw)(sf::RenderWindow *);
IBehaviour *behaviour;
void (IBehaviour::*behaviourUpdate)();
bool isFocused;
bool fullscreen;
void CreateWindow();
void CloseWindow();
public:
GameWindow(std::string = "Window", sf::Uint32 = sf::Style::Titlebar | sf::Style::Close);
void BindDrawable(Drawable *, void (Drawable::*)(sf::RenderWindow *));
void BindDrawable(IDrawable *, void (IDrawable::*)(sf::RenderWindow *));
void BindBehaviour(IBehaviour *, void (IBehaviour::*)());
void Update();
bool IsOpen();
~GameWindow();
@@ -39,13 +44,17 @@ void GameWindow::Update()
break;
}
timer.UpdateTime();
timer -> UpdateTime();
if(!isFocused)
return;
window.clear(config -> GetBackgroundColor());
((drawable)->*(draw))(&window);
if(behaviour)
((behaviour)->*(behaviourUpdate))();
if(drawable)
((drawable)->*(draw))(&window);
window.display();
}
@@ -59,7 +68,8 @@ void GameWindow::CreateWindow()
window.create(videoMode, title, fullscreen ? sf::Style::Fullscreen : style);
window.setVerticalSyncEnabled(true);
window.setFramerateLimit(60);
timer.ResetTimer();
timer = &GameManager::timer;
timer -> ResetTimer();
}
void GameWindow::CloseWindow()
@@ -70,12 +80,18 @@ void GameWindow::CloseWindow()
window.close();
}
void GameWindow::BindDrawable(Drawable *drawable, void (Drawable::*draw)(sf::RenderWindow *))
void GameWindow::BindDrawable(IDrawable *drawable, void (IDrawable::*draw)(sf::RenderWindow *))
{
this -> drawable = drawable;
this -> draw = draw;
}
void GameWindow::BindBehaviour(IBehaviour *behaviour, void (IBehaviour::*behaviourUpdate)())
{
this -> behaviour = behaviour;
this -> behaviourUpdate = behaviourUpdate;
}
GameWindow::GameWindow(std::string title, sf::Uint32 style)
{
config = GameManager::GetConfig();