From 5611736e88052014f65645a1e20ce8dd3bbfb978 Mon Sep 17 00:00:00 2001 From: CaNaRdEoS Date: Sat, 12 Jul 2025 17:28:49 +0200 Subject: [PATCH] add graphic menu --- game/Makefile | 9 ++- game/define.h | 33 ++++++++++ game/{ => interface}/interfaces.cpp | 6 +- game/{ => interface}/interfaces.h | 0 game/interface/ui_elements.cpp | 94 ++++++++++++++++++++++++++++ game/interface/ui_elements.h | 21 +++++++ game/{ => logic}/combat.cpp | 10 +-- game/{ => logic}/combat.h | 3 +- game/{ => logic}/ennemy.cpp | 0 game/{ => logic}/ennemy.h | 0 game/{ => logic}/player.cpp | 9 +-- game/{ => logic}/player.h | 0 game/{ => logic}/spells.cpp | 17 +---- game/{ => logic}/spells.h | 0 game/{ => logic}/structs.h | 0 game/{ => logic}/utilities.cpp | 0 game/{ => logic}/utilities.h | 0 game/main.cpp | 75 +++++++++++++++------- game/release | Bin 155152 -> 190128 bytes 19 files changed, 215 insertions(+), 62 deletions(-) create mode 100644 game/define.h rename game/{ => interface}/interfaces.cpp (90%) rename game/{ => interface}/interfaces.h (100%) create mode 100644 game/interface/ui_elements.cpp create mode 100644 game/interface/ui_elements.h rename game/{ => logic}/combat.cpp (91%) rename game/{ => logic}/combat.h (84%) rename game/{ => logic}/ennemy.cpp (100%) rename game/{ => logic}/ennemy.h (100%) rename game/{ => logic}/player.cpp (94%) rename game/{ => logic}/player.h (100%) rename game/{ => logic}/spells.cpp (96%) rename game/{ => logic}/spells.h (100%) rename game/{ => logic}/structs.h (100%) rename game/{ => logic}/utilities.cpp (100%) rename game/{ => logic}/utilities.h (100%) diff --git a/game/Makefile b/game/Makefile index 5aeb1cc..2ac9e0c 100644 --- a/game/Makefile +++ b/game/Makefile @@ -1,13 +1,16 @@ -all: build run clean clear +all: logs clear + +logs: build run clean newrelease: release runrelease clear + play: runrelease clear build: - g++ main.cpp utilities.cpp player.cpp ennemy.cpp spells.cpp interfaces.cpp combat.cpp -o main + g++ main.cpp logic/utilities.cpp logic/player.cpp logic/ennemy.cpp logic/spells.cpp interface/interfaces.cpp logic/combat.cpp interface/ui_elements.cpp -lraylib -o main release: - g++ main.cpp utilities.cpp player.cpp ennemy.cpp spells.cpp interfaces.cpp combat.cpp -o release + g++ main.cpp utilities.cpp player.cpp ennemy.cpp spells.cpp interfaces.cpp combat.cpp ui_elements.cpp -lraylib -o release runrelease: ./release diff --git a/game/define.h b/game/define.h new file mode 100644 index 0000000..2f1d115 --- /dev/null +++ b/game/define.h @@ -0,0 +1,33 @@ + +//Jobs +constexpr const int MAGE = 0; +constexpr const int ALCHIMIST = 1; +constexpr const int WARRIOR = 2; +constexpr const int ENGINEER = 3; +constexpr const int ARCHER = 4; +constexpr const int TAMER = 5; + +//Elements +constexpr const int FIRE = 0; +constexpr const int AIR = 1; +constexpr const int WATER = 2; +constexpr const int EARTH = 3; +constexpr const int EATHER = 4; + +// Combinaisons +constexpr const int UP = 0; +constexpr const int RIGHT = 1; +constexpr const int DOWN = 2; +constexpr const int LEFT = 3; +constexpr const int END_SPELL = 9; + +//Buttons style +constexpr int BUTTON_BASIC = 0; +constexpr int BUTTON_INACTIVE = 1; +constexpr int BUTTON_DANGER = 2; + +//Buttons size +constexpr const int BUTTON_SMALL = 0; +constexpr const int BUTTON_MEDIUM = 1; +constexpr const int BUTTON_BIG = 2; + diff --git a/game/interfaces.cpp b/game/interface/interfaces.cpp similarity index 90% rename from game/interfaces.cpp rename to game/interface/interfaces.cpp index 9470556..a188130 100644 --- a/game/interfaces.cpp +++ b/game/interface/interfaces.cpp @@ -1,8 +1,8 @@ #include #include -#include "structs.h" -#include "player.h" -#include "ennemy.h" +#include "../logic/structs.h" +#include "../logic/player.h" +#include "../logic/ennemy.h" #include "interfaces.h" void display_menu() { diff --git a/game/interfaces.h b/game/interface/interfaces.h similarity index 100% rename from game/interfaces.h rename to game/interface/interfaces.h diff --git a/game/interface/ui_elements.cpp b/game/interface/ui_elements.cpp new file mode 100644 index 0000000..eaa5335 --- /dev/null +++ b/game/interface/ui_elements.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +#include "../logic/structs.h" +#include "../define.h" +#include "ui_elements.h" + +Button create_button(int type_arg, int size_arg, const std::vector& position_arg, const char *text_arg, const std::vector& screen_arg) { + std::vector size = button_size(size_arg, screen_arg); + float position_x = screen_arg[0] * position_arg[0] - size[0] / 2; + float position_y = screen_arg[1] * position_arg[1] - size[1] / 2; + + Font font = GetFontDefault(); + float font_size = text_size(size_arg); + float text_x = screen_arg[0] * position_arg[0] - MeasureText(text_arg, font_size) / 2; + float text_y = screen_arg[1] * position_arg[1] - font_size / 2; + Text text; + + switch(type_arg) { + case BUTTON_BASIC: + text = {font, text_arg,Vector2{text_x, text_y}, font_size, 2.0f, BLACK}; + + return Button{ + Rectangle{position_x, position_y, size[0], size[1]}, + Color{BLUE}, + text + }; + break; + case BUTTON_INACTIVE: + text = {font, text_arg,Vector2{text_x, text_y}, font_size, 2.0f, BLACK}; + + return Button{ + Rectangle{position_x, position_y, size[0], size[1]}, + Color{GRAY}, + text + }; + break; + case BUTTON_DANGER: + default: + text = {font, text_arg,Vector2{text_x, text_y}, font_size, 2.0f, WHITE}; + + return Button{ + Rectangle{position_x, position_y, size[0], size[1]}, + Color{RED}, + text + }; + break; + } +} + +void draw_buttons(const std::vector