-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
69 lines (60 loc) · 1.91 KB
/
Game.cpp
File metadata and controls
69 lines (60 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "Game.h"
//--------------------------------------------------------------------------------------------------------------------
// Private function
//--------------------------------------------------------------------------------------------------------------------
void Game::initVariables()
{
this->endGame = false;
}
void Game::initWindow()
{
this->videoMode = sf::VideoMode(800, 600);
this->window = new sf::RenderWindow(this->videoMode, "Game 02", sf::Style::Close | sf::Style::Titlebar);
this->window->setFramerateLimit(60);
}
//--------------------------------------------------------------------------------------------------------------------
// Constructors and Destructors
//--------------------------------------------------------------------------------------------------------------------
Game::Game()
{
this->initVariables();
this->initWindow();
}
Game::~Game()
{
delete this->window;
}
//--------------------------------------------------------------------------------------------------------------------
// Public functions
//--------------------------------------------------------------------------------------------------------------------
const bool Game::running() const
{
return this->window->isOpen();
}
void Game::pollEvents()
{
while (this->window->pollEvent(this->sfmlEvent)) // While there are pending events...
{
switch (this->sfmlEvent.type) // Check the type of the event...
{
case sf::Event::Closed:
this->window->close();
break;
case sf::Event::KeyPressed:
if (this->sfmlEvent.key.code == sf::Keyboard::Escape)
this->window->close();
}
}
}
void Game::update()
{
this->pollEvents();
this->player.update(this->window);
}
void Game::render()
{
this->window->clear(); // Clear window
//Render stuff
this->player.render(this->window); // Render player to window
this->window->display(); // Render window
}