diff --git a/assets/bousolle.png b/assets/bousolle.png index fb342c39..8e08369f 100644 Binary files a/assets/bousolle.png and b/assets/bousolle.png differ diff --git a/assets/error.png b/assets/error.png new file mode 100644 index 00000000..9f97c76a Binary files /dev/null and b/assets/error.png differ diff --git a/assets/flags/lookButton.png b/assets/flags/lookButton.png new file mode 100644 index 00000000..c246a147 Binary files /dev/null and b/assets/flags/lookButton.png differ diff --git a/src/gui/src/Main.cpp b/src/gui/src/Main.cpp index 822fe275..ed65aaeb 100644 --- a/src/gui/src/Main.cpp +++ b/src/gui/src/Main.cpp @@ -13,6 +13,8 @@ #include "utils/CommandLineParser.hpp" #include "utils/GuiException.hpp" +#include "error/ErrorWindow.hpp" + int main(int argc, char **argv) { int port = 0; std::string ip = ""; @@ -49,8 +51,19 @@ int main(int argc, char **argv) { try { debug_print << "Starting GUI" << std::endl; - Core core(port, ip); - core.run(); + try { + Core core(port, ip); + try { + core.run(); + } catch (const std::exception &e) { + ErrorWindow errorWindow(1); + errorWindow.run(); + } + } catch (const std::exception &e) { + ErrorWindow errorWindow(0); + errorWindow.run(); + } + } catch (const guiException& e) { std::cerr << e.what() << std::endl; return 84; diff --git a/src/gui/src/error/ErrorWindow.hpp b/src/gui/src/error/ErrorWindow.hpp new file mode 100644 index 00000000..b426b3af --- /dev/null +++ b/src/gui/src/error/ErrorWindow.hpp @@ -0,0 +1,75 @@ +/* +** EPITECH PROJECT, 2024 +** zappy +** File description: +** ErrorWindow +*/ + +#ifndef ERRORWINDOW_HPP_ +#define ERRORWINDOW_HPP_ + +#include +#include +#include + + +static const std::vector errorTitles = { + "Error: Initialization failed", + "Error: Runtime error", +}; + +static const std::vector errorMessages = { + "uh oh, something went wrong during \nthe initialization of the game, \nplease check the logs\n or reinstall the game", + "uh oh, something went wrong during \nthe runtime of the game, \nplease check the logs\n or reinstall the game", +}; + +class ErrorWindow { + + public: + ErrorWindow(int errorType) { + if (errorType < 0 || errorType > 1) + errorType = 0; + _errorType = errorType; + _window.create(sf::VideoMode(400, 225), errorTitles[_errorType], sf::Style::Close); + if (_font.loadFromFile("assets/BadComic-Regular.ttf") == false) + throw std::runtime_error("Error: Font not found"); + _text.setFont(_font); + _text.setString(errorMessages[_errorType]); + _text.setCharacterSize(15); + _text.setPosition(0, 0); + + if (_texture.loadFromFile("assets/error.png") == false) + throw std::runtime_error("Error: Texture not found"); + _sprite.setTexture(_texture); + _sprite.setPosition( + 400 / 2 - 140 / 2 + , 225 - 140 + ); + + }; + ~ErrorWindow() {}; + + void run() { + while (_window.isOpen()) { + sf::Event event; + while (_window.pollEvent(event)) { + if (event.type == sf::Event::Closed) + _window.close(); + } + _window.clear(); + _window.draw(_text); + _window.draw(_sprite); + _window.display(); + } + } + protected: + private: + int _errorType = 0; + sf::Font _font; + sf::Text _text; + sf::Texture _texture; + sf::Sprite _sprite; + sf::RenderWindow _window; +}; + +#endif /* !ERRORWINDOW_HPP_ */ diff --git a/src/gui/src/render/scenes/world/World.cpp b/src/gui/src/render/scenes/world/World.cpp index 5853de9c..1d6d6553 100644 --- a/src/gui/src/render/scenes/world/World.cpp +++ b/src/gui/src/render/scenes/world/World.cpp @@ -21,6 +21,7 @@ World::World(Core *core) _sprites["hoverEgg"] = std::make_shared("./assets/hoverEgg.png"); _sprites["trantorian_run"] = std::make_shared("./assets/trantorian_run.png", 6, 0.1f); _sprites["trantorian_spawn"] = std::make_shared("./assets/trantorian_spawn.png", 12, 0.1f); + _sprites["trantorian_death"] = std::make_shared("./assets/trantorian_death.png", 13, 0.1f); _sprites["grass"] = std::make_shared("./assets/grass_detail(1).png"); _sprites["grass2"] = std::make_shared("./assets/stone(1).png"); _sprites["tree2"] = std::make_shared("./assets/trees/tree(2).png"); @@ -33,6 +34,7 @@ World::World(Core *core) _sprites["starling"] = std::make_shared("assets/trantorian.png"); _sprites["starling"]->setScale(2); _sprites["buildings"] = std::make_shared("./assets/houses.png", 8, 0.1f); + _sprites["lvlup"] = std::make_shared("./assets/lvlup.png", 8, 0.1f); _view.setSize(sf::Vector2f(1920 , 1080)); _chat = std::make_shared(_core->getFont(), 7); _bubbleText = sf::Text("", _core->getFont(), 15); @@ -131,4 +133,17 @@ void World::initSounds() _sounds["wololo"].setVolume(100); _sounds["interact"].openFromFile("./assets/audio/interact.ogg"); _sounds["interact"].setVolume(50); -} \ No newline at end of file +} + +void World::lookTrantorian(int index) +{ + Trantorian trantorian = _trantorians[index]; + + sf::Vector2f pos = trantorian.getPos(); + sf::Vector2f viewPos = _pos + _tmpOffset + _offset; + sf::Vector2f offset = sf::Vector2f( + pos.x - viewPos.x, + pos.y - viewPos.y + ); + _offset += offset; +} diff --git a/src/gui/src/render/scenes/world/World.hpp b/src/gui/src/render/scenes/world/World.hpp index e5dc8a4a..11af8130 100644 --- a/src/gui/src/render/scenes/world/World.hpp +++ b/src/gui/src/render/scenes/world/World.hpp @@ -68,6 +68,7 @@ class World : public IScene { sf::Vector2f _selectedTile = sf::Vector2f(-1, -1); std::vector> _chuncks; std::vector _rankings; + void lookTrantorian(int index); private: void reset(); void getServerInit(); diff --git a/src/gui/src/render/scenes/world/ui/WorldUi.cpp b/src/gui/src/render/scenes/world/ui/WorldUi.cpp index 007d17e5..31d62f77 100644 --- a/src/gui/src/render/scenes/world/ui/WorldUi.cpp +++ b/src/gui/src/render/scenes/world/ui/WorldUi.cpp @@ -49,6 +49,10 @@ bool WorldUi::update(sf::Event event, sf::RenderWindow &window) return false; _idPlayer = (_idPlayer + 1) % _world->getNbTrantorian(); } + if (_world->getNbTrantorian() != 0) + if (_layer2["lookButton"]->update(event, window)) { + _world->lookTrantorian(_idPlayer); + } } if (_panelState == FLAG) { if (_layer2["prevButton"]->update(event, window)) { @@ -162,6 +166,7 @@ void WorldUi::drawTrantorian(sf::RenderWindow &window) _sprites["bousolle"]->draw(window); if (_world->getNbTrantorian() == 0) return; + _layer2["lookButton"]->draw(window); auto trantorian = _world->getTrantorian(_idPlayer); _inventoryText.setPosition(sf::Vector2f( _sprites["trantorianPanel"]->getPosition().x + + 96, @@ -184,7 +189,12 @@ void WorldUi::drawTrantorian(sf::RenderWindow &window) _sprites["trantorianPanel"]->getPosition().x + + 96, _sprites["trantorianPanel"]->getPosition().y + 32 + 50 )); - _inventoryText.setString("Facing " + orientation[trantorian._facing - 1]); + int facing = trantorian._facing - 1; + if (facing < 0) + facing = 3; + if (facing > 3) + facing = 0; + _inventoryText.setString("Facing " + orientation[facing]); window.draw(_inventoryText); } diff --git a/src/gui/src/render/scenes/world/ui/WorldUi.hpp b/src/gui/src/render/scenes/world/ui/WorldUi.hpp index 734aed0c..72b267c1 100644 --- a/src/gui/src/render/scenes/world/ui/WorldUi.hpp +++ b/src/gui/src/render/scenes/world/ui/WorldUi.hpp @@ -31,8 +31,9 @@ class WorldUi : public IScene { _layer1.push_back(std::make_shared("./assets/flags/flagButton.png", sf::Vector2f(0, 16*4 * 1), sf::Vector2f(16, 16), 4)); _layer1.push_back(std::make_shared("./assets/flags/trantorianButton.png", sf::Vector2f(0, 16*4 * 2), sf::Vector2f(16, 16), 4)); _layer2["closeButton"] = std::make_shared("./assets/flags/closeButton.png", sf::Vector2f(16 * 4 *7, 0), sf::Vector2f(16, 16), 4); - _layer2["prevButton"] = std::make_shared("./assets/flags/prevButton.png", sf::Vector2f(16 * 4 + 8, 64), sf::Vector2f(16, 16), 4); - _layer2["nextButton"] = std::make_shared("./assets/flags/nextButton.png", sf::Vector2f(16 * 4 * 6 - 8, 64), sf::Vector2f(16, 16), 4); + _layer2["prevButton"] = std::make_shared("./assets/flags/prevButton.png", sf::Vector2f(16 * 4 + 8, 32), sf::Vector2f(16, 16), 4); + _layer2["nextButton"] = std::make_shared("./assets/flags/nextButton.png", sf::Vector2f(16 * 4 * 6 - 8, 32), sf::Vector2f(16, 16), 4); + _layer2["lookButton"] = std::make_shared("./assets/flags/lookButton.png", sf::Vector2f(16 * 4 * 6 - 8, 96), sf::Vector2f(16, 16), 4); _sprites["inventory"] = std::make_shared("./assets/inventory.png"); _sprites["food"] = std::make_shared("./assets/ressources/food.png"); _sprites["trantorian"] = std::make_shared("./assets/trantorian.png");