add combat_ui, bars
This commit is contained in:
parent
d18afd18c0
commit
b98d3731fa
|
@ -7,10 +7,10 @@ newrelease: release runrelease clear
|
||||||
play: runrelease clear
|
play: runrelease clear
|
||||||
|
|
||||||
build:
|
build:
|
||||||
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
|
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 interface/combat_interface.cpp -lraylib -o main
|
||||||
|
|
||||||
release:
|
release:
|
||||||
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 release
|
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 interface/combat_interface.cpp -lraylib -o release
|
||||||
|
|
||||||
runrelease:
|
runrelease:
|
||||||
./release
|
./release
|
||||||
|
|
|
@ -14,6 +14,15 @@ constexpr const int WATER = 2;
|
||||||
constexpr const int EARTH = 3;
|
constexpr const int EARTH = 3;
|
||||||
constexpr const int EATHER = 4;
|
constexpr const int EATHER = 4;
|
||||||
|
|
||||||
|
//Stats
|
||||||
|
constexpr const int HEALTH = 0;
|
||||||
|
constexpr const int SHIELD = 1;
|
||||||
|
constexpr const int SPEED = 2;
|
||||||
|
constexpr const int MANA = 3;
|
||||||
|
constexpr const int ENERGY = 4;
|
||||||
|
constexpr const int TAME = 5;
|
||||||
|
constexpr const int XP = 6;
|
||||||
|
|
||||||
// Combinaisons
|
// Combinaisons
|
||||||
constexpr const int UP = 0;
|
constexpr const int UP = 0;
|
||||||
constexpr const int RIGHT = 1;
|
constexpr const int RIGHT = 1;
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <raylib.h>
|
||||||
|
#include "../define.h"
|
||||||
|
#include "../logic/structs.h"
|
||||||
|
#include "../logic/player.h"
|
||||||
|
#include "ui_elements.h"
|
||||||
|
#include "combat_interface.h"
|
||||||
|
|
||||||
|
void display_combat_interface(Player& player_arg, std::vector<Ennemy>& ennemies_arg, const std::vector<int>& screen_arg) {
|
||||||
|
std::vector<float> position = {0.5f, 0.5f};
|
||||||
|
Bar player_health = create_bar(HEALTH, player_arg.max_health, player_arg.health, position, screen_arg);
|
||||||
|
inc_health(player_arg, -5);*
|
||||||
|
|
||||||
|
//Dessin
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(BLACK);
|
||||||
|
draw_bar(player_health);
|
||||||
|
EndDrawing();
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
void display_combat_interface(Player& player_arg, std::vector<Ennemy>& ennemies_arg, const std::vector<int>& screen_arg);
|
|
@ -5,12 +5,6 @@
|
||||||
#include "../logic/ennemy.h"
|
#include "../logic/ennemy.h"
|
||||||
#include "interfaces.h"
|
#include "interfaces.h"
|
||||||
|
|
||||||
void display_menu() {
|
|
||||||
std::cout << "1. Search ennemies" << std::endl;
|
|
||||||
std::cout << "2. Quit" << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void display_combat_menu(const Player& player_arg, const std::vector<Ennemy>& ennemies_arg) {
|
void display_combat_menu(const Player& player_arg, const std::vector<Ennemy>& ennemies_arg) {
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
print_player(player_arg);
|
print_player(player_arg);
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
void display_menu();
|
|
||||||
void display_combat_menu(const Player& player_arg, const std::vector<Ennemy>& ennemies_arg);
|
void display_combat_menu(const Player& player_arg, const std::vector<Ennemy>& ennemies_arg);
|
||||||
void display_ennemi_turn(const Ennemy& ennemy_arg);
|
void display_ennemi_turn(const Ennemy& ennemy_arg);
|
||||||
void display_ennemies(const std::vector<Ennemy>& ennemies_arg);
|
void display_ennemies(const std::vector<Ennemy>& ennemies_arg);
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
@ -5,14 +6,14 @@
|
||||||
#include "../define.h"
|
#include "../define.h"
|
||||||
#include "ui_elements.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) {
|
Button create_button(int type_arg, int size_arg, const std::vector<float>& position_arg, std::string text_arg, const std::vector<int>& screen_arg) {
|
||||||
std::vector<float> size = button_size(size_arg, 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_x = screen_arg[0] * position_arg[0] - size[0] / 2;
|
||||||
float position_y = screen_arg[1] * position_arg[1] - size[1] / 2;
|
float position_y = screen_arg[1] * position_arg[1] - size[1] / 2;
|
||||||
|
|
||||||
Font font = GetFontDefault();
|
Font font = GetFontDefault();
|
||||||
float font_size = text_size(size_arg);
|
float font_size = text_size(size_arg);
|
||||||
float text_x = screen_arg[0] * position_arg[0] - MeasureText(text_arg, font_size) / 2;
|
float text_x = screen_arg[0] * position_arg[0] - MeasureText(text_arg.c_str(), font_size) / 2;
|
||||||
float text_y = screen_arg[1] * position_arg[1] - font_size / 2;
|
float text_y = screen_arg[1] * position_arg[1] - font_size / 2;
|
||||||
Text text;
|
Text text;
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ Button create_button(int type_arg, int size_arg, const std::vector<float>& posit
|
||||||
void draw_buttons(const std::vector<Button>& buttons_arg) {
|
void draw_buttons(const std::vector<Button>& buttons_arg) {
|
||||||
for(Button button: buttons_arg) {
|
for(Button button: buttons_arg) {
|
||||||
DrawRectangleRec(button.rectangle, button.color);
|
DrawRectangleRec(button.rectangle, button.color);
|
||||||
DrawTextEx(button.text.font, button.text.text, button.text.position, button.text.fontSize, button.text.spacing, button.text.tint);
|
DrawTextEx(button.text.font, button.text.text.c_str(), button.text.position, button.text.fontSize, button.text.spacing, button.text.tint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,3 +93,55 @@ float text_size(int size_arg) {
|
||||||
return 15.0f;
|
return 15.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Color type_color(int type_arg) {
|
||||||
|
switch(type_arg) {
|
||||||
|
case HEALTH:
|
||||||
|
return RED;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SHIELD:
|
||||||
|
return GRAY;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SPEED:
|
||||||
|
return BLUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return YELLOW;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bar create_bar(int type_arg, int& max_arg, int& actual_arg, const std::vector<float>& position_arg, const std::vector<int>& screen_arg) {
|
||||||
|
float width = 150.0f;
|
||||||
|
float height = 15.0f;
|
||||||
|
float position_x = screen_arg[0] * position_arg[0] - width / 2;
|
||||||
|
float position_y = screen_arg[1] * position_arg[1] - height / 2;
|
||||||
|
Rectangle complete = {position_x, position_y, width, height};
|
||||||
|
|
||||||
|
float progression_width = (width - 2.0f) * (actual_arg / max_arg);
|
||||||
|
float progression_heigth = height - 2.0f;
|
||||||
|
Rectangle progression = {position_x+1, position_y+1, progression_width, progression_heigth};
|
||||||
|
|
||||||
|
Font font = GetFontDefault();
|
||||||
|
float font_size = 10.0f;
|
||||||
|
std::string value = std::to_string(actual_arg) + "/" + std::to_string(max_arg);
|
||||||
|
float text_x = screen_arg[0] * position_arg[0] - MeasureText(value.c_str(), font_size) / 2;
|
||||||
|
float text_y = screen_arg[1] * position_arg[1] - font_size / 2;
|
||||||
|
Text text = {font, value, Vector2{text_x, text_y}, font_size, 2.0f, YELLOW};
|
||||||
|
Color color = type_color(type_arg);
|
||||||
|
|
||||||
|
return Bar{complete, progression, max_arg, actual_arg, text, color};
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_bar(const Bar& bar_arg) {
|
||||||
|
DrawRectangleRec(bar_arg.complete, WHITE);
|
||||||
|
DrawRectangleRec(bar_arg.progression, bar_arg.color);
|
||||||
|
DrawTextEx(bar_arg.text.font, bar_arg.text.text.c_str(), bar_arg.text.position, bar_arg.text.fontSize, bar_arg.text.spacing, bar_arg.text.tint);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ennemy_stats create_bar(const Ennemy& ennemy_arg, const std::vector<float>& position_arg, const std::vector<int>& screen_arg) {
|
||||||
|
return Ennemy_stats{};
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
struct Text {
|
struct Text {
|
||||||
Font font;
|
Font font;
|
||||||
const char *text;
|
std:: string text;
|
||||||
Vector2 position;
|
Vector2 position;
|
||||||
float fontSize, spacing;
|
float fontSize, spacing;
|
||||||
Color tint;
|
Color tint;
|
||||||
|
@ -13,9 +13,24 @@ struct Button {
|
||||||
Text text;
|
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);
|
struct Bar {
|
||||||
|
Rectangle complete, progression;
|
||||||
|
int max, actual;
|
||||||
|
Text text;
|
||||||
|
Color color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Ennemy_stats {
|
||||||
|
Text name, level;
|
||||||
|
Bar health, shield, speed, tame;
|
||||||
|
};
|
||||||
|
|
||||||
|
Button create_button(int type_arg, int size_arg, const std::vector<float>& position_arg, std::string text_arg, const std::vector<int>& screen_arg);
|
||||||
void draw_buttons(const std::vector<Button>& buttons_arg);
|
void draw_buttons(const std::vector<Button>& buttons_arg);
|
||||||
|
|
||||||
std::vector<float> button_size(int size_arg, const std::vector<int>& screen_arg);
|
std::vector<float> button_size(int size_arg, const std::vector<int>& screen_arg);
|
||||||
float text_size(int size_arg);
|
float text_size(int size_arg);
|
||||||
|
|
||||||
|
Bar create_bar(int type_arg, int& max_arg, int& actual_arg, const std::vector<float>& position_arg, const std::vector<int>& screen_arg);
|
||||||
|
void draw_bar(const Bar& bar_arg);
|
||||||
|
|
||||||
|
Ennemy_stats create_bar(const Ennemy& ennemy_arg, const std::vector<float>& position_arg, const std::vector<int>& screen_arg);
|
|
@ -6,13 +6,15 @@
|
||||||
#include "ennemy.h"
|
#include "ennemy.h"
|
||||||
#include "spells.h"
|
#include "spells.h"
|
||||||
#include "../interface/interfaces.h"
|
#include "../interface/interfaces.h"
|
||||||
|
#include "../interface/combat_interface.h"
|
||||||
#include "combat.h"
|
#include "combat.h"
|
||||||
|
|
||||||
void init_combat(Player& player_arg, std::vector<Ennemy> ennemies_arg) {
|
void init_combat(Player& player_arg, std::vector<Ennemy> ennemies_arg, const std::vector<int>& screen_arg) {
|
||||||
std::vector<Ennemy> ennemies;
|
std::vector<Ennemy> ennemies;
|
||||||
ennemies.push_back(ennemies_arg[1]);
|
ennemies.push_back(ennemies_arg[1]);
|
||||||
ennemies.push_back(ennemies_arg[2]);
|
ennemies.push_back(ennemies_arg[2]);
|
||||||
|
|
||||||
|
display_combat_interface(player_arg, ennemies, screen_arg);
|
||||||
combat(player_arg, ennemies);
|
combat(player_arg, ennemies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
void init_combat(Player& player_arg, std::vector<Ennemy> ennemies_arg);
|
void init_combat(Player& player_arg, std::vector<Ennemy> ennemies_arg, const std::vector<int>& screen_arg);
|
||||||
void combat(Player& player_arg, std::vector<Ennemy>& ennemies_arg);
|
void combat(Player& player_arg, std::vector<Ennemy>& ennemies_arg);
|
||||||
|
|
||||||
void check_deads(Player& player_arg, std::vector<Ennemy>& ennemies_arg, bool& combat_loop);
|
void check_deads(Player& player_arg, std::vector<Ennemy>& ennemies_arg, bool& combat_loop);
|
||||||
|
|
|
@ -71,7 +71,7 @@ void print_ennemy(const Ennemy& ennemy_arg) {
|
||||||
std::cout << "Health: " << ennemy_arg.health << "/"<< ennemy_arg.max_health << std::endl;
|
std::cout << "Health: " << ennemy_arg.health << "/"<< ennemy_arg.max_health << std::endl;
|
||||||
std::cout << "Shield: " << ennemy_arg.shield << "/"<< ennemy_arg.max_shield << std::endl;
|
std::cout << "Shield: " << ennemy_arg.shield << "/"<< ennemy_arg.max_shield << std::endl;
|
||||||
std::cout << "Speed: " << ennemy_arg.speed << "/"<< ennemy_arg.max_speed << std::endl;
|
std::cout << "Speed: " << ennemy_arg.speed << "/"<< ennemy_arg.max_speed << std::endl;
|
||||||
std::cout << "Speed: " << ennemy_arg.tame << "/"<< ennemy_arg.max_tame << std::endl;
|
std::cout << "Tame: " << ennemy_arg.tame << "/"<< ennemy_arg.max_tame << std::endl;
|
||||||
std::cout << "Escape: " << ennemy_arg.escape * 100 << "%"<< std::endl;
|
std::cout << "Escape: " << ennemy_arg.escape * 100 << "%"<< std::endl;
|
||||||
std::cout << "Menace: " << ennemy_arg.menace * 100 << "%"<< std::endl;
|
std::cout << "Menace: " << ennemy_arg.menace * 100 << "%"<< std::endl;
|
||||||
std::cout << "Spells: ";
|
std::cout << "Spells: ";
|
||||||
|
|
|
@ -10,11 +10,11 @@
|
||||||
#include "logic/combat.h"
|
#include "logic/combat.h"
|
||||||
#include "interface/ui_elements.h"
|
#include "interface/ui_elements.h"
|
||||||
|
|
||||||
void handle_menu(std::vector<Button>& buttons_arg, Player& player_arg, std::vector<Ennemy>& ennemies_arg, bool& game_loop_arg) {
|
void handle_menu(std::vector<Button>& buttons_arg, Player& player_arg, std::vector<Ennemy>& ennemies_arg, bool& game_loop_arg, const std::vector<int>& screen_arg) {
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||||
if (CheckCollisionPointRec(GetMousePosition(), buttons_arg[0].rectangle)) {
|
if (CheckCollisionPointRec(GetMousePosition(), buttons_arg[0].rectangle)) {
|
||||||
buttons_arg = {};
|
buttons_arg = {};
|
||||||
init_combat(player_arg, ennemies_arg);
|
init_combat(player_arg, ennemies_arg, screen_arg);
|
||||||
} else if (CheckCollisionPointRec(GetMousePosition(), buttons_arg[2].rectangle)) {
|
} else if (CheckCollisionPointRec(GetMousePosition(), buttons_arg[2].rectangle)) {
|
||||||
game_loop_arg = 0;
|
game_loop_arg = 0;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ int main() {
|
||||||
bool game_loop = 1;
|
bool game_loop = 1;
|
||||||
while (game_loop && !WindowShouldClose()) {
|
while (game_loop && !WindowShouldClose()) {
|
||||||
// Gestion des actions
|
// Gestion des actions
|
||||||
handle_menu(buttons, mage, ennemies, game_loop);
|
handle_menu(buttons, mage, ennemies, game_loop, screen);
|
||||||
|
|
||||||
//Dessin
|
//Dessin
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
BIN
game/release
BIN
game/release
Binary file not shown.
Loading…
Reference in New Issue