forked from 2goodAP/QuizmaHeros102
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cpp
93 lines (75 loc) · 2.14 KB
/
player.cpp
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
88
89
90
91
92
93
#include <sstream>
#include "DEFINITIONS.hpp"
#include "player.hpp"
#include "Games.hpp"
#include "GameState.hpp"
#include <SFML/Window.hpp>
#include "Categories.hpp"
#include <iostream>
#include<string>
namespace Quizma
{
player::player(GameDataRef data) : _data(data)
{
}
void player::Init()
{
this->_data->assets.LoadTexture("Player Background", PLAYER_BACKGROUND_FILEPATH);
_background.setTexture(this->_data->assets.GetTexture("Player Background"));
std::cout << "The state has been loaded.\n";
_name_font.loadFromFile(PLAYER_FONT_FILEPATH);
_name_text.setFont(_name_font);
_name_text.setCharacterSize(50);
_name_text.setFillColor(sf::Color::Black);
_name_text.setPosition(1005, 665);
_name_text.setOrigin(_name_text.getLocalBounds().width / 2, _name_text.getLocalBounds().height / 2);
_name_text.scale(1.0f , 1.0f);
}
void player::HandleInput()
{
sf::Event event;
while (/*_name_file.is_open() && */this->_data->window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
this->_data->window.close();
}
else if (sf::Event::KeyPressed)
{
if (event.key.code == sf::Keyboard::Return)
{
this->_data->name = _name;
this->_data->sound.setBuffer(this->_data->buffer);
this->_data->sound.play();
std::cout << "Load new state" << std::endl;
this->_data->machine.AddState(StateRef(new Categories(_data)), true);
}
else if (event.type == sf::Event::TextEntered)
{
if (event.text.unicode >= 33 && event.text.unicode <= 126)
{
_name += (char)event.text.unicode;
}
else if (event.text.unicode == 8)
{
_name = _name.substr(0, _name.length() - 1);
}
_name_text.setString(_name);
_name_text.setOrigin(_name_text.getLocalBounds().width / 2, _name_text.getLocalBounds().height / 2);
}
}
}
}
void player::Update(float dt)
{
}
void player::Draw(float dt)
{
this->_data->window.clear();
this->_data->window.clear(sf::Color::Black);
this->_data->window.draw(this->_background);
this->_data->window.draw(this->_border);
this->_data->window.draw(_name_text);
this->_data->window.display();
}
}