-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameScreen.cpp
More file actions
83 lines (74 loc) · 2.6 KB
/
GameScreen.cpp
File metadata and controls
83 lines (74 loc) · 2.6 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "GameScreen.h"
#include "MenuScreen.h"
#include "Game.h"
/* Game screen implements the screen abstract class. The idea is to create
separate environments for which the entities tcan interact. For example, the
entities utilized on a menu screen are going to interact differently than the
entities utilized during gameplay even if they are the same objects (e.g. buttons).
*/
Map * GameScreen::gameMap;
GameScreen::GameScreen(void)
// Constructor loads the map information from a text document an prepares the gameplay objects.
{
_font.loadFromFile("source/fonts/chango.ttf");
MenuMessage.setString("0");
MenuMessage.setOrigin(0, 8);
MenuMessage.setPosition(10, 10);
MenuMessage.setFont(_font);
MenuMessage.setCharacterSize(32);
MenuMessage.setColor(sf::Color::Red);
}
void GameScreen::getInput(sf::RenderWindow& window)
// GetInput takes input from the user and stores it in a list.
{
if (KEY_LEFT) {
actions.appendAction('l');
}
if (KEY_RIGHT) {
actions.appendAction('r');
}
if (KEY_SPACE) {
actions.appendAction(' ');
}
}
void GameScreen::update()
// update takes the list of user input and passes it to the player entity.
// The player entity takes the list and performs all the required actions.
// The action list is cleared for the next cycle.
// Additionally, the other objects also update their data for this cycle.
{
if (!curLevel.playerLose()) {
curLevel.update(actions);
actions.clearActions();
}
else {
if (KEY_ENTER)
Game::screen = std::make_shared<MenuScreen>();
}
}
void GameScreen::render(sf::RenderWindow& window)
// Render draws all of the game objects to the window.
{
char uiMessage[256];
sprintf_s(uiMessage, "%i", curLevel.getPoints());
MenuMessage.setString(uiMessage);
MenuMessage.setOrigin(MenuMessage.getLocalBounds().width/2,MenuMessage.getLocalBounds().height/2);
MenuMessage.setPosition((window_x)/4, 16);
window.draw(MenuMessage);
sprintf_s(uiMessage, "%iX", curLevel.getCombo());
MenuMessage.setString(uiMessage);
MenuMessage.setOrigin(MenuMessage.getLocalBounds().width/2,MenuMessage.getLocalBounds().height/2);
MenuMessage.setPosition((window_x)/4*3, 16);
window.draw(MenuMessage);
window.draw(curLevel.getSprite());
if (curLevel.playerLose()) {
MenuMessage.setString(" YOU LOSE\n\nPRESS ENTER\n TO RETURN");
MenuMessage.setOrigin(MenuMessage.getLocalBounds().width/2,MenuMessage.getLocalBounds().height/2);
MenuMessage.setPosition((window_x)/2, (window_y)/2);
window.draw(MenuMessage);
}
}
GameScreen::~GameScreen(void)
// The destructor is empty for now.
{
}