add graphic menu
This commit is contained in:
parent
6b93b21afc
commit
5611736e88
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#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() {
|
|
@ -0,0 +1,94 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include <raylib.h>
|
||||
#include "../logic/structs.h"
|
||||
#include "../define.h"
|
||||
#include "ui_elements.h"
|
||||
|
||||
Button create_button(int type_arg, int size_arg, const std::vector<float>& position_arg, const char *text_arg, const std::vector<int>& screen_arg) {
|
||||
std::vector<float> 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<Button>& buttons_arg) {
|
||||
for(Button button: buttons_arg) {
|
||||
DrawRectangleRec(button.rectangle, button.color);
|
||||
DrawTextEx(button.text.font, button.text.text, button.text.position, button.text.fontSize, button.text.spacing, button.text.tint);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<float> button_size(int size_arg, const std::vector<int>& screen_arg) {
|
||||
std::vector<float> size;
|
||||
switch(size_arg) {
|
||||
case BUTTON_BIG:
|
||||
size.push_back(screen_arg[0]/8);
|
||||
size.push_back(screen_arg[1]/8);
|
||||
break;
|
||||
|
||||
case BUTTON_MEDIUM:
|
||||
size.push_back(screen_arg[0]/16);
|
||||
size.push_back(screen_arg[1]/16);
|
||||
break;
|
||||
|
||||
case BUTTON_SMALL:
|
||||
default:
|
||||
size.push_back(screen_arg[0]/32);
|
||||
size.push_back(screen_arg[1]/32);
|
||||
break;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
float text_size(int size_arg) {
|
||||
switch(size_arg) {
|
||||
case BUTTON_BIG:
|
||||
return 25.0f;
|
||||
break;
|
||||
|
||||
case BUTTON_MEDIUM:
|
||||
return 20.0f;
|
||||
break;
|
||||
|
||||
case BUTTON_SMALL:
|
||||
default:
|
||||
return 15.0f;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
struct Text {
|
||||
Font font;
|
||||
const char *text;
|
||||
Vector2 position;
|
||||
float fontSize, spacing;
|
||||
Color tint;
|
||||
};
|
||||
|
||||
struct Button {
|
||||
Rectangle rectangle;
|
||||
Color color;
|
||||
Text text;
|
||||
};
|
||||
|
||||
Button create_button(int type_arg, int size_arg, const std::vector<float>& position_arg, const char *text_arg, const std::vector<int>& screen_arg);
|
||||
|
||||
void draw_buttons(const std::vector<Button>& buttons_arg);
|
||||
|
||||
std::vector<float> button_size(int size_arg, const std::vector<int>& screen_arg);
|
||||
float text_size(int size_arg);
|
|
@ -5,7 +5,7 @@
|
|||
#include "player.h"
|
||||
#include "ennemy.h"
|
||||
#include "spells.h"
|
||||
#include "interfaces.h"
|
||||
#include "../interface/interfaces.h"
|
||||
#include "combat.h"
|
||||
|
||||
void init_combat(Player& player_arg, std::vector<Ennemy> ennemies_arg) {
|
||||
|
@ -64,7 +64,7 @@ void select_combat_action(int arg, Player& player_arg, bool& combat_loop_arg, st
|
|||
attack(player_arg, ennemies_arg);
|
||||
break;
|
||||
case 3:
|
||||
if(player_escape(player_arg, ennemies_arg)) {
|
||||
if(escape(player_arg, ennemies_arg)) {
|
||||
std::cout << "Escape succesfully" << std::endl;
|
||||
combat_loop_arg = 0;
|
||||
} else {
|
||||
|
@ -95,7 +95,7 @@ void attack(Player& player_arg, std::vector<Ennemy>& ennemies_arg){
|
|||
}
|
||||
}
|
||||
|
||||
bool player_escape(const Player& player_arg, std::vector<Ennemy>& ennemies_arg) {
|
||||
bool escape(const Player& player_arg, std::vector<Ennemy>& ennemies_arg) {
|
||||
float min = 1;
|
||||
for(Ennemy& ennemy: ennemies_arg) {
|
||||
if(ennemy.menace < min) {
|
||||
|
@ -103,8 +103,4 @@ bool player_escape(const Player& player_arg, std::vector<Ennemy>& ennemies_arg)
|
|||
}
|
||||
}
|
||||
return random_success(player_arg.escape * min);
|
||||
}
|
||||
|
||||
bool escape(const Ennemy& ennemy_arg) {
|
||||
return random_success(ennemy_arg.escape);
|
||||
}
|
|
@ -11,5 +11,4 @@ Spell choose_spell(const Ennemy& ennemy_arg);
|
|||
void ennemy_turn(Player& player_arg, Ennemy& ennemy_arg);
|
||||
|
||||
void attack(Player& player_arg, std::vector<Ennemy>& ennemies_arg);
|
||||
bool player_escape(const Player& player_arg, std::vector<Ennemy>& ennemies_arg);
|
||||
bool escape(const Ennemy& ennemy_arg);
|
||||
bool escape(const Player& player_arg, std::vector<Ennemy>& ennemies_arg);
|
|
@ -2,18 +2,11 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include "structs.h"
|
||||
#include "../define.h"
|
||||
#include "utilities.h"
|
||||
#include "player.h"
|
||||
#include "spells.h"
|
||||
|
||||
const int MAGE = 0;
|
||||
const int ALCHIMIST = 1;
|
||||
const int WARRIOR = 2;
|
||||
const int ENGINEER = 3;
|
||||
const int ARCHER = 4;
|
||||
const int TAMER = 5;
|
||||
|
||||
|
||||
void init_default_mage(Player& player_arg) {
|
||||
player_arg.name = "Liam le dieu";
|
||||
player_arg.job = MAGE;
|
|
@ -3,26 +3,13 @@
|
|||
#include <string>
|
||||
#include "utilities.h"
|
||||
#include "structs.h"
|
||||
#include "../define.h"
|
||||
#include "player.h"
|
||||
#include "ennemy.h"
|
||||
#include "interfaces.h"
|
||||
#include "../interface/interfaces.h"
|
||||
#include "spells.h"
|
||||
|
||||
|
||||
// Elements
|
||||
const int FIRE = 0;
|
||||
const int AIR = 1;
|
||||
const int WATER = 2;
|
||||
const int EARTH = 3;
|
||||
const int EATHER = 4;
|
||||
const std::vector<std::string> elements = {"Fire", "Air", "Water", "Earth", "Eather"};
|
||||
|
||||
// Combinaisons
|
||||
const int UP = 0;
|
||||
const int RIGHT = 1;
|
||||
const int DOWN = 2;
|
||||
const int LEFT = 3;
|
||||
const int END_SPELL = 5;
|
||||
const std::vector<std::string> arrows = {"↑", "→", "↓", "←"};
|
||||
|
||||
void init_spell(Spell& spell_arg, const std::string& name_arg, int damage_arg, int cost_arg, float precision_arg, bool zone_arg, std::vector<int> elements_arg, std::vector<int> combinaison_arg) {
|
|
@ -1,40 +1,67 @@
|
|||
#include <iostream>
|
||||
#include <raylib.h>
|
||||
#include <vector>
|
||||
#include "structs.h"
|
||||
#include "player.h"
|
||||
#include "ennemy.h"
|
||||
#include "spells.h"
|
||||
#include "interfaces.h"
|
||||
#include "combat.h"
|
||||
#include "logic/structs.h"
|
||||
#include "define.h"
|
||||
#include "logic/player.h"
|
||||
#include "logic/ennemy.h"
|
||||
#include "logic/spells.h"
|
||||
#include "interface/interfaces.h"
|
||||
#include "logic/combat.h"
|
||||
#include "interface/ui_elements.h"
|
||||
|
||||
void select_menu(int arg, Player& player_arg, std::vector<Ennemy>& ennemies_arg, bool& game_loop_arg);
|
||||
|
||||
void select_menu(int arg, Player& player_arg, std::vector<Ennemy>& ennemies_arg, bool& game_loop_arg) {
|
||||
switch (arg){
|
||||
case 1:
|
||||
init_combat(player_arg, ennemies_arg);
|
||||
break;
|
||||
case 2:
|
||||
game_loop_arg = 0;
|
||||
break;
|
||||
default:
|
||||
game_loop_arg = 0;
|
||||
break;
|
||||
}
|
||||
void handle_menu(std::vector<Button>& buttons_arg, Player& player_arg, std::vector<Ennemy>& ennemies_arg, bool& game_loop_arg) {
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
if (CheckCollisionPointRec(GetMousePosition(), buttons_arg[0].rectangle)) {
|
||||
buttons_arg = {};
|
||||
init_combat(player_arg, ennemies_arg);
|
||||
} else if (CheckCollisionPointRec(GetMousePosition(), buttons_arg[2].rectangle)) {
|
||||
game_loop_arg = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
InitWindow(300, 233, "Combat Lamthaï");
|
||||
ToggleFullscreen();
|
||||
std::vector<int> screen;
|
||||
if(IsWindowFullscreen()) {
|
||||
int monitor = GetCurrentMonitor();
|
||||
screen = {GetMonitorWidth(monitor), GetMonitorHeight(monitor)};
|
||||
} else {
|
||||
screen = {GetScreenWidth(), GetScreenHeight()};
|
||||
}
|
||||
|
||||
Player mage;
|
||||
init_default_mage(mage);
|
||||
std::vector<Ennemy> ennemies;
|
||||
create_ennemies(ennemies);
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
std::vector<Button> buttons;
|
||||
buttons.push_back(create_button(BUTTON_BASIC, BUTTON_BIG, std::vector<float>{0.5, 0.5}, "Play", screen));
|
||||
buttons.push_back(create_button(BUTTON_INACTIVE, BUTTON_MEDIUM, std::vector<float>{0.5, 0.6}, "Options", screen));
|
||||
buttons.push_back(create_button(BUTTON_DANGER, BUTTON_MEDIUM, std::vector<float>{0.5, 0.7}, "Quit", screen));
|
||||
|
||||
int arg;
|
||||
bool game_loop = 1;
|
||||
while (game_loop) {
|
||||
display_menu();
|
||||
std::cin >> arg;
|
||||
select_menu(arg, mage, ennemies, game_loop);
|
||||
while (game_loop && !WindowShouldClose()) {
|
||||
// Gestion des actions
|
||||
handle_menu(buttons, mage, ennemies, game_loop);
|
||||
|
||||
//Dessin
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
draw_buttons(buttons);
|
||||
|
||||
EndDrawing();
|
||||
|
||||
}
|
||||
// Libération des ressources
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
}
|
BIN
game/release
BIN
game/release
Binary file not shown.
Loading…
Reference in New Issue