forked from jasonmaharjan/QuizmaHeros9000
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameOverState.cpp
124 lines (101 loc) · 4.09 KB
/
GameOverState.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#pragma once
#include <sstream>
#include "DEFINITIONS.hpp"
#include "GameOverState.hpp"
#include "MainMenuState.hpp"
#include "GameState.hpp"
#include "Games.hpp"
#include "Categories.hpp"
#include <iostream>
namespace Quizma
{
GameOverState::GameOverState(GameDataRef data) : _data(data)
{
}
void GameOverState::Init()
{
_name_file.open(PLAYER_RECORD_FILEPATH, std::ios::app);
this->_data->assets.LoadTexture("Game Over Background", GAME_OVER_BACKGROUND_FILEPATH);
this->_data->assets.LoadTexture("Game Over", GAME_OVER_IMAGE);
this->_data->assets.LoadTexture("Quit Image", QUIT_FILEPATH);
this->_data->assets.LoadTexture("Cursor", CURSOR_FILEPATH);
this->_data->assets.LoadTexture("Play Again", PLAY_AGAIN_BUTTON_FILEPATH);
this->_data->assets.LoadTexture("Return To Title", RETURN_TO_TITLE_FILEPATH);
_background.setTexture(this->_data->assets.GetTexture("Game Over Background"));
_playAgain.setTexture(this->_data->assets.GetTexture("Play Again"));
_gameOver.setTexture(this->_data->assets.GetTexture("Game Over"));
_quit.setTexture(this->_data->assets.GetTexture("Quit Image"));
_returnToTitle.setTexture(this->_data->assets.GetTexture("Return To Title"));
_cursor.setTexture(this->_data->assets.GetTexture("Cursor"));
_cursor.setScale(0.35, 0.35);
_gameOver.setPosition((SCREEN_WIDTH / 2) - (_gameOver.getGlobalBounds().width / 2), (SCREEN_HEIGHT / 2) - (_gameOver.getGlobalBounds().height / 2));
_cursor.setPosition((SCREEN_WIDTH / 2) - (_cursor.getGlobalBounds().width / 2), (SCREEN_HEIGHT / 2) - (_cursor.getGlobalBounds().height / 2));
_playAgain.setPosition(800, 950);
_returnToTitle.setPosition(1200, 950);
_quit.setPosition(1700, 950);
}
void GameOverState::HandleInput()
{
sf::Event event;
while (this->_data->window.pollEvent(event))
{
if (sf::Event::Closed == event.type)
{
this->_data->window.close();
}
// For moving to the categories selection(for the same player)
if (this->_data->input.IsSpriteClicked(this->_playAgain, sf::Mouse::Left, this->_data->window))
{
// Go to the next page/question
this->_data->sound.setBuffer(this->_data->buffer);
this->_data->sound.play();
this->_data->machine.AddState(StateRef(new Categories(_data)), true);
}
if ((this->_data->input.IsSpriteClicked(this->_returnToTitle, sf::Mouse::Left, this->_data->window)) || (this->_data->input.IsSpriteClicked(this->_quit, sf::Mouse::Left, this->_data->window)) )
{
if (this->_data->score < 10)
_name_file << this->_data->score << " ";
else if (this->_data->score < 100)
_name_file << this->_data->score << " ";
else if (this->_data->score < 1000)
_name_file << this->_data->score << " ";
if (this->_data->category == 0)
_name_file << "Category - 1" << " ";
else if (this->_data->category == 1)
_name_file << "Category - 2" << " ";
else if (this->_data->category == 3)
_name_file << "Category - 3" << " ";
_name_file << this->_data->name << " " << std::endl;
//for returning to the main screen title
if (this->_data->input.IsSpriteClicked(this->_returnToTitle, sf::Mouse::Left, this->_data->window))
{
this->_data->sound.setBuffer(this->_data->buffer);
this->_data->sound.play();
this->_data->machine.AddState(StateRef(new MainMenuState(_data)), true);
}
//for exiting
if (this->_data->input.IsSpriteClicked(this->_quit, sf::Mouse::Left, this->_data->window))
{
this->_data->sound.setBuffer(this->_data->buffer);
this->_data->sound.play();
_data->window.close();
}
}
_cursor.setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(this->_data->window)));
}
}
void GameOverState::Update(float dt)
{
}
void GameOverState::Draw(float dt)
{
this->_data->window.clear(sf::Color::Black);
this->_data->window.draw(this->_background);
this->_data->window.draw(this->_gameOver);
this->_data->window.draw(this->_playAgain);
this->_data->window.draw(this->_quit);
this->_data->window.draw(this->_returnToTitle);
this->_data->window.draw(this->_cursor);
this->_data->window.display();
}
}