Skip to content

Commit

Permalink
feat(): add winning scene
Browse files Browse the repository at this point in the history
  • Loading branch information
DiaboloAB committed Jun 23, 2024
1 parent c16f0ab commit fc8ee5e
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 0 deletions.
Binary file added assets/win.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/gui/src/render/core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../scenes/Home.hpp"
#include "../scenes/Quit.hpp"
#include "../scenes/Menu.hpp"
#include "../scenes/WinScene.hpp"
#include <iostream>
#include "../../utils/GuiException.hpp"

Expand All @@ -22,6 +23,7 @@ Core::Core(int port, std::string ip) {
_scenes[GameState::END] = std::make_shared<Quit>(this);
_scenes[GameState::GAME] = std::make_shared<World>(this);
_scenes[GameState::MENU] = std::make_shared<Menu>(this);
_scenes[GameState::WIN] = std::make_shared<WinScene>(this);
_clock.restart();
initSounds();
_sounds["music"].play();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/src/render/core/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum GameState {
GAME,
QUIT,
END,
WIN,
DEFAULT,
};
class Core {
Expand Down Expand Up @@ -59,6 +60,7 @@ class Core {
int _tickRate = 2;

bool _funMode = false;
std::string _winner = "";
private:
sf::RenderWindow _window;
sf::Event _event;
Expand Down
45 changes: 45 additions & 0 deletions src/gui/src/render/scenes/WinScene.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
** EPITECH PROJECT, 2024
** zappy
** File description:
** WinScene
*/

#include "WinScene.hpp"
#include "../core/Core.hpp"

WinScene::WinScene(Core *core)
{
_text.setFont(core->getFont());
_text.setCharacterSize(25);
_text.setFillColor(sf::Color::White);
_core = core;
_quitButton = std::make_shared<Button>(sf::Vector2f(100, 500), sf::Vector2f(100, 100), "Quit", _core->getFont());
_homeButton = std::make_shared<Button>(sf::Vector2f(100, 450), sf::Vector2f(100, 100), "Home", _core->getFont());
_homeButton->setCallBack(std::bind(&WinScene::getBackHome, this));
_win = std::make_shared<Sprite>("./assets/win.png");
_win->setScale(1.5f);
}

void WinScene::draw(sf::RenderWindow &window)
{
sf::Vector2f winSize = window.getView().getSize();
_quitButton->setPosition(sf::Vector2f(winSize.x / 2 - 150, winSize.y / 2 + 150));
_homeButton->setPosition(sf::Vector2f(winSize.x / 2 + 50, winSize.y / 2 + 150));
_quitButton->draw(window);
_homeButton->draw(window);
_text.setPosition(sf::Vector2f(winSize.x / 2 -_text.getGlobalBounds().width / 2
, winSize.y / 2 + 100));
_text.setString(_core->_winner + " won the game !");
_win->setPosition(sf::Vector2f(winSize.x / 2, winSize.y / 2 - 100));
window.draw(_text);
_win->draw(window);
}

void WinScene::getBackHome()
{
if (_core->_server.disconectFromServer() == true)
_core->_data.resetGame();
_core->_upperState = GameState::DEFAULT;
_core->_state = GameState::HOME;
}
58 changes: 58 additions & 0 deletions src/gui/src/render/scenes/WinScene.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
** EPITECH PROJECT, 2024
** zappy
** File description:
** WinScene
*/

#ifndef WINSCENE_HPP_
#define WINSCENE_HPP_

#include <memory>

#include "IScene.hpp"
#include "../ui/Button.hpp"
#include "../ui/Input.hpp"
#include "../sprites/Sprite.hpp"

class Core;

class WinScene : public IScene {
public:
WinScene(Core *core);
~WinScene() {

}

bool update(sf::Event event, sf::RenderWindow &window) override
{
if (_quitButton->update(event, window))
window.close();
_homeButton->update(event, window);
return false;
}

void update(float /*fElapsedTime*/) override
{

}

void draw(sf::RenderWindow &window) override;

void init() override
{

}

void getBackHome();
protected:
private:
Core *_core;
std::shared_ptr<Button> _homeButton;
std::shared_ptr<Button> _quitButton;
sf::Text _text;
std::shared_ptr<Sprite> _win;

};

#endif /* !WINSCENE_HPP_ */
4 changes: 4 additions & 0 deletions src/gui/src/render/ui/Button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class Button {
return _text.getString();
}

void setPosition(sf::Vector2f pos) {
_text.setPosition(pos);
}

protected:
private:
sf::Text _text;
Expand Down

0 comments on commit fc8ee5e

Please sign in to comment.