Repository navigation
Expand file tree
/
Copy pathConsole.cpp
More file actions
87 lines (80 loc) · 2.5 KB
/
Copy pathConsole.cpp
File metadata and controls
87 lines (80 loc) · 2.5 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
84
85
86
87
//
// Created by Aram Paparian on 5/13/26.
//
#include "Console.h"
Console::Console() : ml::Application(1200, 900, 32, "console")
{
_text.setFillColor(sf::Color::White);
_text.setCharacterSize(20);
_rect.setSize({400.f, 200.f});
_rect.setFillColor(sf::Color::Transparent);
_rect.setOutlineColor(sf::Color::White);
_rect.setOutlineThickness(2.f);
addComponent(_rect);
addComponent(_text);
onUpdate([this]()
{
if (!_active)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Num1))
{
_active = _games[0];
addComponent(*_active);
_active->run();
_active->registerEvents();
_active->initialization();
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Num2))
{
_active = _games[1];
addComponent(*_active);
_active->run();
_active->registerEvents();
_active->initialization();
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Num3))
{
_active = _games[2];
addComponent(*_active);
_active->run();
_active->registerEvents();
_active->initialization();
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Num4))
{
_active = _games[3];
addComponent(*_active);
_active->run();
_active->registerEvents();
_active->initialization();
}
}
else
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape))
{
removeComponent(*_active);
_active = nullptr;
}
}
});
}
void Console::onInit()
{
_games.push_back(&_pong);
_games.push_back(&_brick);
_games.push_back(&_calc);
_games.push_back(&_euchre);
{
sf::RenderWindow& window = ml::WindowManager::getWindow();
sf::Vector2u windowSize = window.getSize();
sf::Vector2f rectSize = _rect.getSize();
_rect.setPosition({(float)windowSize.x/2.f - rectSize.x/2.f,
(float)windowSize.y/2.f - rectSize.y/2.f});
}
_text.setString("Arcade Console:\n1. Pong\n2. Brick Breaker\n3. Calculator\n4. Euchre\nPress number key to start, Esc to quit.");
_rect.centerText(_text);
}
void Console::onReady()
{
}