Commit 4044f9a5 authored by Timothy LAIRD's avatar Timothy LAIRD

options menu; documentation of existing work

parent cb3f9a52
...@@ -18,7 +18,7 @@ include_directories(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src) ...@@ -18,7 +18,7 @@ include_directories(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src)
include_directories( ${PROJECT_SOURCE_DIR}/dpd/include ) include_directories( ${PROJECT_SOURCE_DIR}/dpd/include )
link_directories( ${PROJECT_SOURCE_DIR}/dpd ) link_directories( ${PROJECT_SOURCE_DIR}/dpd )
add_executable(nw-viewer src/main-viewer.c src/networld.c src/controlpanel.c src/entity.c src/player.c src/random-map.c src/graphical-aspect.c src/window-manager.c src/menu-button.c src/main-menu.c) add_executable(nw-viewer src/main-viewer.c src/networld.c src/controlpanel.c src/entity.c src/player.c src/random-map.c src/graphical-aspect.c src/window-manager.c src/menu-button.c src/main-menu.c src/int-input.c src/options-menu.c)
target_link_libraries(nw-viewer raylib pthread dl rt X11 m) target_link_libraries(nw-viewer raylib pthread dl rt X11 m)
......
...@@ -48,22 +48,40 @@ void Panel_print(Panel * self) ...@@ -48,22 +48,40 @@ void Panel_print(Panel * self)
self->scale); self->scale);
} }
// Rendering
void Panel_drawMainMenu(Panel * self, Main_Menu * menu){ void Panel_drawMainMenu(Panel * self, Main_Menu * menu){
Font font = GetFontDefault(); Font font = GetFontDefault();
BeginDrawing(); BeginDrawing();
DrawText("RISK", (self->screenWidth*35)/100 , (self->screenHeight*10)/100 , (self->screenWidth*10)/100,BLACK);
//Draw each button
for(int index = 0; index < menu->buttonCount; index++){
Menu_Button_draw(menu->buttons[index], &font, self->screenWidth, self->screenHeight);
}
ClearBackground(RAYWHITE);
UnloadFont(font);
EndDrawing();
}
DrawText("RISK", (self->screenWidth*35)/100 , (self->screenHeight*15)/100 , (self->screenWidth*10)/100,BLACK); void Panel_drawOptionsMenu(Panel * self, Options_Menu * menu){
Font font = GetFontDefault();
BeginDrawing();
Button_draw(menu->buttons[game_ui], &font, self->screenWidth, self->screenHeight); DrawText("OPTIONS", (self->screenWidth*35)/100 , (self->screenHeight*15)/100 , (self->screenWidth*5)/100,BLACK);
Button_draw(menu->buttons[options], &font, self->screenWidth, self->screenHeight); //Draw each input field
for(int index = 0; index < menu->inputCount; index++){
Int_Input_draw(menu->inputs[index], &font, self->screenWidth, self->screenHeight);
}
DrawRectangleRec(menu->saveReturnBtn, GREEN);
DrawRectangleRec(menu->smallerSaveReturnBtn, WHITE);
DrawTextRec(font, "\tSave and Exit", menu->saveReturnBtn,(self->screenHeight*5)/100, (self->screenWidth/400), true, BLACK);
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
UnloadFont(font);
EndDrawing(); EndDrawing();
} }
// Rendering
void Panel_drawGame(Panel * self) void Panel_drawGame(Panel * self)
{ {
BeginDrawing(); BeginDrawing();
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "networld.h" #include "networld.h"
#include "main-menu.h" #include "main-menu.h"
#include "options-menu.h"
// Tools // Tools
void printVector2( Vector2 v ); void printVector2( Vector2 v );
...@@ -42,6 +42,9 @@ Vector2 Panel_positionFromPixel(Panel * self, Vector2 * p); ...@@ -42,6 +42,9 @@ Vector2 Panel_positionFromPixel(Panel * self, Vector2 * p);
//Rendering the main menu //Rendering the main menu
void Panel_drawMainMenu(Panel * self, Main_Menu * menu); void Panel_drawMainMenu(Panel * self, Main_Menu * menu);
//Rendering the options menu
void Panel_drawOptionsMenu(Panel * self, Options_Menu * menu);
// Control // Control
void Panel_control(Panel * self); void Panel_control(Panel * self);
void Panel_controlCamera(Panel * self); void Panel_controlCamera(Panel * self);
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
//Graphical view //Graphical view
void Graphic_ShowPlayerInfo(Player * player, int screenWidth, int screenHeight, Font font); void Graphic_ShowPlayerInfo(Player * player, const int screenWidth, const int screenHeight, Font font);
void Graphic_RecrutementPhase(Player * player, int screenWidth, int screenHeight, Font font); void Graphic_RecrutementPhase(Player * player, const int screenWidth, const int screenHeight, Font font);
void Graphic_AttackPhase(Player * player, int screenWidth, int screenHeight, Font font); void Graphic_AttackPhase(Player * player, const int screenWidth, const int screenHeight, Font font);
void Graphic_WhoseTurnIsIt(Player * player, int screenWidth, int screenHeight, Font font); void Graphic_WhoseTurnIsIt(Player * player, const int screenWidth, const int screenHeight, Font font);
Rectangle Graphic_ConfirmButton(Font font); Rectangle Graphic_ConfirmButton(Font font);
void Graphic_MouseHoverNodeRecrutement(Player * self, Vector2 mousePosition, Panel * panel); void Graphic_MouseHoverNodeRecrutement(Player * self, Vector2 mousePosition, Panel * panel);
void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition, Panel * panel); void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition, Panel * panel);
......
#include "int-input.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Int_Input * Int_Input_init(char* name, int * targetInt, Rectangle inputBox){
Int_Input * self = malloc(sizeof(Int_Input));
self->name = name;
self->targetInt = targetInt;
self->value = malloc(sizeof(char) * 32);
sprintf(self->value, "%d", *targetInt);
self->valueLength = strlen(self->value);
self->inputBox = inputBox;
self->inputActive = false;
return self;
}
void Int_Input_delete(Int_Input * self){
free(self);
}
void Int_Input_add_char(Int_Input * self, int * key){
self->value[self->valueLength] = (char) *key;
self->valueLength++;
}
void Int_Input_remove_char(Int_Input * self){
self->valueLength--;
if (self->valueLength < 0) self->valueLength = 0;
self->value[self->valueLength] = '\0';
}
void Int_Input_save_value(Int_Input * self){
if(self->valueLength > 0){
*(self->targetInt) = atoi(self->value);
}
}
void Int_Input_draw(Int_Input * self, Font * font, const int screenWidth, const int screenHeight){
DrawRectangleRec(self->inputBox, LIGHTGRAY);
DrawText(self->name, self->inputBox.x/2, self->inputBox.y, (screenHeight*4)/100, BLACK);
DrawTextRec(*font, self->value, self->inputBox, (screenHeight*4)/100, (screenWidth/75), true, BLACK);
}
\ No newline at end of file
#ifndef INTINPUT_H
#define INTINPUT_H
#include "raylib.h"
struct Str_Int_Input{
//! Text to display
char* name;
//! Pointer to the value to change
int * targetInt;
//! Current stored value
char* value;
//! char count of value
int valueLength;
//! Panel input box
Rectangle inputBox;
bool inputActive;
};
typedef struct Str_Int_Input Int_Input;
/**
* @brief Initialise an input field.
* @param name the text to display
* @param targetInt pointer to the value to change
* @param inputBox panel input box
* @return The pointer to the new Int_Input.
*/
Int_Input * Int_Input_init(char* name, int * targetInt, Rectangle inputBox);
/**
* @brief Free an Int_Input
* @param self the element to void
*/
void Int_Input_delete(Int_Input * self);
/**
* @brief Add a char to the current value
* @param self the Int_Input to add to
* @param key the character to add
*/
void Int_Input_add_char(Int_Input * self, int * key);
/**
* @brief Remove a char from the current value
* @param self the Int_Input to remove from
*/
void Int_Input_remove_char(Int_Input * self);
/**
* @brief Save the stored input value in the actual game parameter
* @param self the Int_Input to save in
*/
void Int_Input_save_value(Int_Input * self);
/**
* @brief Draw the Int_Input on the panel
* @param self the Int_Input to draw
* @param font the text font to use
* @param screenWidth the width of the screen
* @param screenHeight the height of the screen
*/
void Int_Input_draw(Int_Input * self, Font * font, const int screenWidth, const int screenHeight);
#endif
\ No newline at end of file
...@@ -6,15 +6,18 @@ Main_Menu * Main_Menu_init(const int screenWidth, const int screenHeight){ ...@@ -6,15 +6,18 @@ Main_Menu * Main_Menu_init(const int screenWidth, const int screenHeight){
Main_Menu * self = malloc(sizeof(Main_Menu)); Main_Menu * self = malloc(sizeof(Main_Menu));
//Init of the play game btn
Rectangle playGameBtn = {(screenWidth*32)/100, (screenHeight*35)/100, (screenWidth*30)/100, (screenHeight*5)/100}; Rectangle playGameBtn = {(screenWidth*32)/100, (screenHeight*35)/100, (screenWidth*30)/100, (screenHeight*5)/100};
Rectangle smallPlayGameBtn = {3 + (screenWidth*32/100), 3 + (screenHeight*35/100), (screenWidth*30/100) - 6, (screenHeight*5/100) - 6}; Rectangle smallPlayGameBtn = {3 + (screenWidth*32/100), 3 + (screenHeight*35/100), (screenWidth*30/100) - 6, (screenHeight*5/100) - 6};
Rectangle playGameTextBox = {smallPlayGameBtn.x + smallPlayGameBtn.width/3, smallPlayGameBtn.y, smallPlayGameBtn.width, smallPlayGameBtn.height};
Menu_Button * playGame = Menu_Button_init(playGameBtn, smallPlayGameBtn,playGameTextBox, "PLAY", game_ui);
Menu_Button * playGame = Button_init(playGameBtn, smallPlayGameBtn, "\t\t\t PLAY", game_ui); //Init of the options btn
Rectangle optionsBtn = {(screenWidth*32)/100, (screenHeight*45)/100, (screenWidth*30)/100, (screenHeight*5)/100}; Rectangle optionsBtn = {(screenWidth*32)/100, (screenHeight*45)/100, (screenWidth*30)/100, (screenHeight*5)/100};
Rectangle smallOptionsBtn = {3 + (screenWidth*32/100), 3 + (screenHeight*45/100), (screenWidth*30/100) - 6, (screenHeight*5/100) - 6}; Rectangle smallOptionsBtn = {3 + (screenWidth*32/100), 3 + (screenHeight*45/100), (screenWidth*30/100) - 6, (screenHeight*5/100) - 6};
Rectangle optionsTextBox = {smallOptionsBtn.x + smallOptionsBtn.width/4, smallOptionsBtn.y, smallOptionsBtn.width, smallOptionsBtn.height};
Menu_Button * optionsMenu = Button_init(optionsBtn, smallOptionsBtn, "\t\tOPTIONS", options); Menu_Button * optionsMenu = Menu_Button_init(optionsBtn, smallOptionsBtn,optionsTextBox, "OPTIONS", options);
self->buttonCount = 2; self->buttonCount = 2;
self->buttons = malloc(sizeof(Menu_Button) * self->buttonCount); self->buttons = malloc(sizeof(Menu_Button) * self->buttonCount);
...@@ -28,10 +31,16 @@ Display Main_Menu_detect_click(Main_Menu * self, Vector2 * mousePos){ ...@@ -28,10 +31,16 @@ Display Main_Menu_detect_click(Main_Menu * self, Vector2 * mousePos){
for(int index = 0; index < self->buttonCount; index++){ for(int index = 0; index < self->buttonCount; index++){
Menu_Button * currentBtn = self->buttons[index]; Menu_Button * currentBtn = self->buttons[index];
if(CheckCollisionPointRec(*mousePos, currentBtn->button)){ if(CheckCollisionPointRec(*mousePos, currentBtn->button)){
printf("returned %d\n", currentBtn->displayOnClick);
return currentBtn->displayOnClick; return currentBtn->displayOnClick;
} }
} }
return main_menu; return main_menu;
} }
void Main_Menu_delete(Main_Menu * self){
for(int index = 0; index < self->buttonCount; index++){
Menu_Button_delete(self->buttons[index]);
}
free(self);
}
...@@ -4,15 +4,35 @@ ...@@ -4,15 +4,35 @@
#include "menu-button.h" #include "menu-button.h"
struct Str_Main_Menu{ struct Str_Main_Menu{
//! Button pointer list
Menu_Button ** buttons; Menu_Button ** buttons;
//! Nb of buttons
int buttonCount; int buttonCount;
char ** buttonDisplayNames;
}; };
typedef struct Str_Main_Menu Main_Menu; typedef struct Str_Main_Menu Main_Menu;
/**
* @brief Initialise a new Main_Menu object
* @param screenWidth the width of the screen
* @param screenHeight the height of the screen
* @return A pointer to the new Main_Menu
*/
Main_Menu * Main_Menu_init(const int screenWidth, const int screenHeight); Main_Menu * Main_Menu_init(const int screenWidth, const int screenHeight);
/**
* @brief Detect if any buttons have been clicked
* @param self the Main_Menu context
* @param mousePos the position of the mouse on click
* @return An enum element indicating which screen to display in the next frame
*/
Display Main_Menu_detect_click(Main_Menu * self, Vector2 * mousePos); Display Main_Menu_detect_click(Main_Menu * self, Vector2 * mousePos);
/**
* @brief Delete a Main_Menu
* @param self the menu to void
*/
void Main_Menu_delete(Main_Menu * self);
#endif #endif
\ No newline at end of file
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "graphical-aspect.h" #include "graphical-aspect.h"
#include "window-manager.h" #include "window-manager.h"
#include "main-menu.h" #include "main-menu.h"
#include "options-menu.h"
// Program attributes // Program attributes
//------------------- //-------------------
...@@ -35,42 +36,31 @@ int main(int nbArg, char ** arg) ...@@ -35,42 +36,31 @@ int main(int nbArg, char ** arg)
{ {
int nodeCount = 10; int nodeCount = 10;
int playerCount = 3; int playerCount = 3;
NetWorld * world= NetWorld_new(nodeCount, playerCount); NetWorld * world = malloc(sizeof(NetWorld));
Random_map(world); Player * players = malloc(sizeof(Player));
// Game Initialization // Game Initialization
//-------------------- //--------------------
game_end= false;
Panel * panel= Panel_new(); Panel * panel= Panel_new();
Panel_initialize(panel, world, screenWidth, screenHeight); Panel_initialize(panel, world, screenWidth, screenHeight);
Color colors[] = {BLACK, RED, BLUE};
Player * players = Player_newArray(playerCount, colors);
for(int index = 0; index < world->size; index++){
Player_add_Node(&(players[index % playerCount]), &(world->nodes[index]));
}
// Raylib Initialization // Raylib Initialization
//---------------------- //----------------------
InitWindow(screenWidth, screenHeight, "NetWorld basic viewer"); InitWindow(screenWidth, screenHeight, "NetWorld basic viewer");
SetTargetFPS(targetFPS); SetTargetFPS(targetFPS);
Font font = LoadFont("GAMERIA.ttf"); Font gameFont = LoadFont("GAMERIA.ttf");
// Main game loop // Main game loop
//UI elements
Main_Menu * menu = Main_Menu_init(screenWidth, screenHeight); Main_Menu * menu = Main_Menu_init(screenWidth, screenHeight);
Window_Manager * manager = Window_Manager_new(panel, menu); Options_Menu * optionsMenu = Options_Menu_init(&playerCount, &nodeCount, screenWidth, screenHeight);
world->currentPlayer = playerCount - 1; Window_Manager * manager = Window_Manager_new(panel, menu, optionsMenu);
while (!game_end && !WindowShouldClose()) // Detect window close button or ESC key while (!game_end && !WindowShouldClose()) // Detect window close button or ESC key
{ {
DrawFPS(10, 10); DrawFPS(10, 10);
for(int index = 0; index < world->size; index++){
Vector2 screenPosition= Panel_pixelFromPosition(panel, &(world->nodes[index]).position);
world->nodes[index].collisionHitbox.x = screenPosition.x - 24;
world->nodes[index].collisionHitbox.y = screenPosition.y - 24;
}
Panel_control(panel);
Window_Manager_display(manager); Window_Manager_display(manager);
switch (manager->display) switch (manager->display)
...@@ -79,10 +69,59 @@ int main(int nbArg, char ** arg) ...@@ -79,10 +69,59 @@ int main(int nbArg, char ** arg)
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){ if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Vector2 mousePos = GetMousePosition(); Vector2 mousePos = GetMousePosition();
manager->display = Main_Menu_detect_click(menu, &mousePos); manager->display = Main_Menu_detect_click(menu, &mousePos);
if(manager->display == game_ui){
//Initialising a new game with inputted parameters
*world = *NetWorld_new(nodeCount, playerCount);
Random_map(world);
Color colors[] = {BLACK, RED, BLUE, GREEN, PURPLE, PINK, YELLOW};
players = Player_newArray(playerCount, colors);
//Distribute nodes to players evenly
for(int index = 0; index < world->size; index++){
Player_add_Node(&(players[index % playerCount]), &(world->nodes[index]));
}
world->currentPlayer = playerCount - 1;
game_end = false;
}
} }
break; break;
case game_ui: case game_ui:
game_update(world, players, font, panel); Panel_control(panel);
//Draw the hitboxes for each node
for(int index = 0; index < world->size; index++){
Vector2 screenPosition= Panel_pixelFromPosition(panel, &(world->nodes[index]).position);
world->nodes[index].collisionHitbox.x = screenPosition.x - 24;
world->nodes[index].collisionHitbox.y = screenPosition.y - 24;
}
game_update(world, players, gameFont, panel);
break;
case options:
//Activate/Deactivate inputs on click and detect click on the save btn
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Vector2 mousePos = GetMousePosition();
if(Options_Menu_check_save_click(optionsMenu, &mousePos)){
manager->display = main_menu;
for(int index = 0; index < optionsMenu->inputCount; index++){
Int_Input_save_value(optionsMenu->inputs[index]);
}
}
Options_Menu_check_input_click(optionsMenu, &mousePos);
}
//Check key inputs for active input fields (only accepts numerical characters)
for(int index = 0; index < optionsMenu->inputCount; index++){
if(optionsMenu->inputs[index]->inputActive){
int key = GetKeyPressed();
while (key > 0){
if ((key >= 48) && (key <= 57) && (optionsMenu->inputCount < 3)){
Int_Input_add_char(optionsMenu->inputs[index], &key);
}
key = GetCharPressed();
}
if (IsKeyPressed(KEY_BACKSPACE)){
Int_Input_remove_char(optionsMenu->inputs[index]);
}
}
}
break;
default: default:
break; break;
} }
...@@ -93,7 +132,10 @@ int main(int nbArg, char ** arg) ...@@ -93,7 +132,10 @@ int main(int nbArg, char ** arg)
NetWorld_delete(world); NetWorld_delete(world);
Player_delete(players); Player_delete(players);
UnloadFont(font); Main_Menu_delete(menu);
Options_Menu_delete(optionsMenu);
Window_Manager_delete(manager);
UnloadFont(gameFont);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
return 0; return 0;
...@@ -101,13 +143,12 @@ int main(int nbArg, char ** arg) ...@@ -101,13 +143,12 @@ int main(int nbArg, char ** arg)
void game_update(NetWorld * world, Player * players, Font font, Panel * panel) void game_update(NetWorld * world, Player * players, Font font, Panel * panel)
{ {
Vector2 mousePosition = { 0.0f, 0.0f }; //Game frame init
mousePosition = GetMousePosition(); Vector2 mousePosition = GetMousePosition();
Player * currentPlayer = &(players[world->currentPlayer]); Player * currentPlayer = &(players[world->currentPlayer]);
Graphic_ShowPlayerInfo(currentPlayer, screenWidth, screenHeight, font); Graphic_ShowPlayerInfo(currentPlayer, screenWidth, screenHeight, font);
Graphic_WhoseTurnIsIt(currentPlayer, screenWidth, screenHeight, font); Graphic_WhoseTurnIsIt(currentPlayer, screenWidth, screenHeight, font);
int playerCount = world->playerCount; int playerCount = world->playerCount;
Player * newPlayers = malloc(sizeof(Player));
switch(currentPlayer->turnPhase){ switch(currentPlayer->turnPhase){
case recruitment: case recruitment:
...@@ -118,18 +159,16 @@ void game_update(NetWorld * world, Player * players, Font font, Panel * panel) ...@@ -118,18 +159,16 @@ void game_update(NetWorld * world, Player * players, Font font, Panel * panel)
Player_add_soldier(currentPlayer, mousePosition); Player_add_soldier(currentPlayer, mousePosition);
} }
}else{ }else{
//Finish the recruitment phase
Rectangle nextPhaseButton = Graphic_ConfirmButton(font); Rectangle nextPhaseButton = Graphic_ConfirmButton(font);
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
if(CheckCollisionPointRec(mousePosition, nextPhaseButton)){ if(CheckCollisionPointRec(mousePosition, nextPhaseButton)){
Player_confirm_recrutement(currentPlayer); Player_confirm_recrutement(currentPlayer);
printf("Recrutement confirmed\n");
currentPlayer->turnPhase = attack; currentPlayer->turnPhase = attack;
printf("Attack phase\n");
} }
} }
} }
if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)){ if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)){
Player_remove_soldier(currentPlayer, mousePosition); Player_remove_soldier(currentPlayer, mousePosition);
} }
break; break;
...@@ -143,22 +182,20 @@ void game_update(NetWorld * world, Player * players, Font font, Panel * panel) ...@@ -143,22 +182,20 @@ void game_update(NetWorld * world, Player * players, Font font, Panel * panel)
} }
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Node * originNode = currentPlayer->selectedNode; Node * originNode = currentPlayer->selectedNode;
//Detect if the player declared an attack
for(int nodeIndex = 0; nodeIndex < world->size; nodeIndex++){ for(int nodeIndex = 0; nodeIndex < world->size; nodeIndex++){
Node* currentNode = &(world->nodes[nodeIndex]); Node* currentNode = &(world->nodes[nodeIndex]);
if(CheckCollisionPointRec(mousePosition, currentNode->collisionHitbox)){ if(CheckCollisionPointRec(mousePosition, currentNode->collisionHitbox)){
int nodePlayerID = currentNode->playerID; int nodePlayerID = currentNode->playerID;
if(nodePlayerID == currentPlayer->ID){ if(nodePlayerID == currentPlayer->ID){
printf("Selected target Node\n");
currentPlayer->selectedNode = currentNode; currentPlayer->selectedNode = currentNode;
} }
else if(Node_are_connected(originNode, currentNode) && (originNode->soldiers > 1) && originNode->canAttack){ else if(Node_are_connected(originNode, currentNode) && (originNode->soldiers > 1) && originNode->canAttack){
printf("Engagine attack on target Node\n"); printf("Engaging attack on target Node\n");
Player_attack_Node(currentPlayer, &(players[nodePlayerID]), originNode, currentNode); Player_attack_Node(currentPlayer, &(players[nodePlayerID]), originNode, currentNode);
diceRolling(); //diceRolling();
}else{ }else{
printf("Failed to attack target : Origin has already attacked, nodes aren't connected or origin node has too few soldiers\n");
} }
} }
} }
...@@ -168,24 +205,21 @@ void game_update(NetWorld * world, Player * players, Font font, Panel * panel) ...@@ -168,24 +205,21 @@ void game_update(NetWorld * world, Player * players, Font font, Panel * panel)
Player_select_Node(currentPlayer, mousePosition); Player_select_Node(currentPlayer, mousePosition);
} }
} }
//End turn btn
Rectangle nextPhase = {200, 200, 270, 55}; Rectangle nextPhase = {200, 200, 270, 55};
DrawRectangleRec(nextPhase, GREEN); DrawRectangleRec(nextPhase, GREEN);
DrawTextEx(font, "Next Turn",(Vector2){220 , 210} , 40.0, 3.0, BLACK); DrawTextEx(font, "Next Turn",(Vector2){220 , 210} , 40.0, 3.0, BLACK);
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
if(CheckCollisionPointRec(mousePosition, nextPhase)){ if(CheckCollisionPointRec(mousePosition, nextPhase)){
printf("Attack phase ended\n");
currentPlayer->turnPhase = init; currentPlayer->turnPhase = init;
} }
} }
break; break;
case init : case init :
//Switch turns
Player_end_turn(currentPlayer); Player_end_turn(currentPlayer);
printf("Turn ended\n");
world->currentPlayer = (world->currentPlayer + 1) % playerCount; world->currentPlayer = (world->currentPlayer + 1) % playerCount;
printf("Player changed\n");
Player_start_turn(&(players[world->currentPlayer])); Player_start_turn(&(players[world->currentPlayer]));
printf("Turn started\n");
printf("Recrutement phase\n");
break; break;
default:; default:;
} }
......
#include "menu-button.h" #include "menu-button.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
Menu_Button * Button_init(Rectangle button, Rectangle smallerButton, char* displayText, Display display){ Menu_Button * Menu_Button_init(Rectangle button, Rectangle smallerButton, Rectangle textBox, char* displayText, Display display){
Menu_Button * self = malloc(sizeof(Menu_Button)); Menu_Button * self = malloc(sizeof(Menu_Button));
self->button = button; self->button = button;
self->smallerButton = smallerButton; self->smallerButton = smallerButton;
self->textBox = textBox;
self->displayText = displayText; self->displayText = displayText;
self->displayOnClick = display; self->displayOnClick = display;
return self; return self;
} }
void Button_draw(Menu_Button * self, Font * font, const int screenWidth, const int screenHeight){ void Menu_Button_draw(Menu_Button * self, Font * font, const int screenWidth, const int screenHeight){
DrawRectangleRec(self->button, RED); DrawRectangleRec(self->button, RED);
DrawRectangleRec(self->smallerButton, WHITE); DrawRectangleRec(self->smallerButton, WHITE);
DrawTextRec(*font, self->displayText, self->textBox, (screenHeight*4)/100, (screenWidth/75), true, BLACK);
DrawTextRec(*font, self->displayText, self->smallerButton, (screenHeight*4)/100, (screenWidth/75), true, BLACK);
} }
void Menu_Button_delete(Menu_Button * self){
free(self);
}
...@@ -7,16 +7,43 @@ enum displays {game_ui, options, load_save, main_menu}; ...@@ -7,16 +7,43 @@ enum displays {game_ui, options, load_save, main_menu};
typedef enum displays Display; typedef enum displays Display;
struct Str_Menu_Button{ struct Str_Menu_Button{
//! Panel elements
Rectangle button; Rectangle button;
Rectangle smallerButton; Rectangle smallerButton;
Rectangle textBox;
//! Text to display in the button
char* displayText; char* displayText;
//! Menu to display if the button is clicked
Display displayOnClick; Display displayOnClick;
}; };
typedef struct Str_Menu_Button Menu_Button; typedef struct Str_Menu_Button Menu_Button;
Menu_Button * Button_init(Rectangle button, Rectangle smallerButton, char* displayText, Display display);
void Button_draw(Menu_Button * self, Font * font, const int screenWidth, const int screenHeight); /**
* @brief Init a Menu_Button
* @param button Button hitbox
* @param smallerButton White layer
* @param textBox Container for displayText
* @param displayText Text to display
* @param Display Enum element referencing to a screen display
* @return A pointer to the new button
*/
Menu_Button * Menu_Button_init(Rectangle button, Rectangle smallerButton, Rectangle textBox, char* displayText, Display display);
/**
* @brief Draw the Menu_Button
* @param self The button to draw
* @param font The font to use
* @param screenWidth Width of the screen
* @param screenHeight Height of the screen
*/
void Menu_Button_draw(Menu_Button * self, Font * font, const int screenWidth, const int screenHeight);
/**
* @brief Void a Menu_button
* @param self The button to void
*/
void Menu_Button_delete(Menu_Button * self);
#endif #endif
\ No newline at end of file
...@@ -22,6 +22,7 @@ struct Str_Node { ...@@ -22,6 +22,7 @@ struct Str_Node {
char* name; char* name;
//! Number of soldiers at the node //! Number of soldiers at the node
int soldiers; int soldiers;
//! Buffer variable to stop players from removing soldiers from their nodes
int soldiersToAdd; int soldiersToAdd;
//! Continent the node belongs to //! Continent the node belongs to
char* continent; char* continent;
...@@ -29,6 +30,7 @@ struct Str_Node { ...@@ -29,6 +30,7 @@ struct Str_Node {
int playerID; int playerID;
//! Click hitbox for the node //! Click hitbox for the node
Rectangle collisionHitbox; Rectangle collisionHitbox;
//! Boolean indicating if a node has attacked this turn
bool canAttack; bool canAttack;
}; };
...@@ -137,8 +139,18 @@ int Node_biconnect( ...@@ -137,8 +139,18 @@ int Node_biconnect(
Node * node2 Node * node2
); );
/**
* @brief Confirm the allocation of new soldiers
* @param self The node to confirm placement in
*/
void Node_confirm_placement(Node * self); void Node_confirm_placement(Node * self);
/**
* @brief Text if 2 nodes are connected
* @param self The origin node
* @param target The target node
* @return A boolean
*/
bool Node_are_connected(Node * self, Node * target); bool Node_are_connected(Node * self, Node * target);
......
#include "options-menu.h"
#include <stdlib.h>
#include <stdio.h>
Options_Menu * Options_Menu_init(int * playerCount, int * nodeCount, const int screenWidth, const int screenHeight){
Options_Menu * self = malloc(sizeof(Options_Menu));
//Input for the player count
Rectangle playerCountInputBox = {(screenWidth*32)/100, (screenHeight*35)/100, (screenWidth*30)/100, (screenHeight*5)/100};
Int_Input * playerCountInput = Int_Input_init("Nb. of Players : ", playerCount, playerCountInputBox);
//Input for the node count
Rectangle nodeCountInputBox = {(screenWidth*32)/100, (screenHeight*45)/100, (screenWidth*30)/100, (screenHeight*5)/100};
Int_Input * nodeCountInput = Int_Input_init("Nb. of Nodes : ", nodeCount, nodeCountInputBox);
self->inputCount = 2;
self->inputs = malloc(sizeof(Int_Input) * self->inputCount);
self->inputs[0] = playerCountInput;
self->inputs[1] = nodeCountInput;
//Save and exit btn
Rectangle saveBtn = {0, (screenHeight*95)/100, (screenWidth*20)/100, (screenHeight*10)/100};
Rectangle smallerSaveBtn = {3, 3 +(screenHeight*95)/100, -6 + (screenWidth*20)/100, -6 + (screenHeight*10)/100};
self->saveReturnBtn = saveBtn;
self->smallerSaveReturnBtn = smallerSaveBtn;
return self;
}
bool Options_Menu_check_save_click(Options_Menu * self, Vector2 * mousePos){
return CheckCollisionPointRec(*mousePos, self->saveReturnBtn);
}
void Options_Menu_check_input_click(Options_Menu * self, Vector2 * mousePos){
for(int index = 0; index < self->inputCount; index++){
self->inputs[index]->inputActive = CheckCollisionPointRec(*mousePos, self->inputs[index]->inputBox);
}
}
void Options_Menu_delete(Options_Menu * self){
for(int index = 0; index < self->inputCount; index++){
Int_Input_delete(self->inputs[index]);
}
free(self);
}
\ No newline at end of file
#ifndef OPTIONSBUTTON_H
#define OPTIONSBUTTON_H
#include "raylib.h"
#include "int-input.h"
struct Str_Options_Menu{
//! List of input fields
Int_Input ** inputs;
//! Nb of input fields
int inputCount;
//Return btn
Rectangle saveReturnBtn;
Rectangle smallerSaveReturnBtn;
};
typedef struct Str_Options_Menu Options_Menu;
/**
* @brief Initialise a new Options_Menu
* @param playerCount Reference to the playerCount game variable
* @param nodeCount Reference to the nodeCount game variable
* @param screenWidth Width of the screen
* @param screenHeight Height of the screen
* @return A pointer to the Options_Menu element
*/
Options_Menu * Options_Menu_init(int * playerCount, int * nodeCount, const int screenWidth, const int screenHeight);
/**
* @brief Check if the save btn has been clicked
* @param self The options menu context
* @param mousePos The position of the mouse on click
* @return A boolean
*/
bool Options_Menu_check_save_click(Options_Menu * self, Vector2 * mousePos);
/**
* @brief Activate/Deactivate inputs on click
* @param self The options menu context
* @param mousePos The position of the mouse on click
*/
void Options_Menu_check_input_click(Options_Menu * self, Vector2 * mousePos);
/**
* @brief Delete an Options_Menu
* @param self The object to void
*/
void Options_Menu_delete(Options_Menu * self);
#endif
\ No newline at end of file
...@@ -85,8 +85,6 @@ void Player_start_turn(Player * self){ ...@@ -85,8 +85,6 @@ void Player_start_turn(Player * self){
} }
self->soldiers = fmax(1, totalSoldierCount/3); self->soldiers = fmax(1, totalSoldierCount/3);
self->turnPhase = recruitment; self->turnPhase = recruitment;
printf("Current player : %i\n", self->ID);
printf("Current player soldiers : %i\n", self->soldiers);
} }
} }
...@@ -126,7 +124,6 @@ void Player_select_Node(Player * self, Vector2 mousePos){ ...@@ -126,7 +124,6 @@ void Player_select_Node(Player * self, Vector2 mousePos){
if(currentNode->soldiers > 1){ if(currentNode->soldiers > 1){
self->hasSelectedNode = true; self->hasSelectedNode = true;
self->selectedNode = currentNode; self->selectedNode = currentNode;
printf("Selected target Node\n");
} }
break; break;
} }
...@@ -138,8 +135,6 @@ void Player_unselect_Node(Player * self, Vector2 mousePos){ ...@@ -138,8 +135,6 @@ void Player_unselect_Node(Player * self, Vector2 mousePos){
Node* currentNode = self->nodes[nodeIndex]; Node* currentNode = self->nodes[nodeIndex];
if(CheckCollisionPointRec(mousePos, currentNode->collisionHitbox)){ if(CheckCollisionPointRec(mousePos, currentNode->collisionHitbox)){
self->hasSelectedNode = false; self->hasSelectedNode = false;
printf("Unselected target node\n");
} }
} }
} }
......
...@@ -7,12 +7,19 @@ enum turnPhases {init, recruitment, attack}; ...@@ -7,12 +7,19 @@ enum turnPhases {init, recruitment, attack};
typedef enum turnPhases TurnPhases; typedef enum turnPhases TurnPhases;
struct Str_Player{ struct Str_Player{
//! Player ID
int ID; int ID;
//! List of node pointers belonging to the player
Node ** nodes; Node ** nodes;
//! Nb of owned nodes
int nodeCount; int nodeCount;
//! Player Color
Color color; Color color;
//! Player's turn phase
TurnPhases turnPhase; TurnPhases turnPhase;
//! Player soldier count for the recruitement phase
int soldiers; int soldiers;
//! Player's selected node for the attack phase
Node * selectedNode; Node * selectedNode;
bool hasSelectedNode; bool hasSelectedNode;
}; };
...@@ -59,7 +66,7 @@ void Player_add_Node( ...@@ -59,7 +66,7 @@ void Player_add_Node(
); );
/** /**
* @brief Remove a node to the player's territory. * @brief Remove a node from the player's territory.
*/ */
void Player_remove_Node( void Player_remove_Node(
//! The player; //! The player;
...@@ -79,16 +86,47 @@ void Player_start_turn(Player * self); ...@@ -79,16 +86,47 @@ void Player_start_turn(Player * self);
*/ */
void Player_end_turn(Player * self); void Player_end_turn(Player * self);
/**
* @brief Add a soldier to a player's node
* @param self The player context
* @param mousePos the position of the mouse to detect which node has been clicked
*/
void Player_add_soldier(Player * self, Vector2 mousePos); void Player_add_soldier(Player * self, Vector2 mousePos);
/**
* @brief Remove a soldier from a player's node
* @param self The player context
* @param mousePos the position of the mouse to detect which node has been clicked
*/
void Player_remove_soldier(Player * self, Vector2 mousePos); void Player_remove_soldier(Player * self, Vector2 mousePos);
/**
* @brief A player selects a node
* @param self The player context
* @param mousePos the position of the mouse to detect which node has been clicked
*/
void Player_select_Node(Player * self, Vector2 mousePos); void Player_select_Node(Player * self, Vector2 mousePos);
/**
* @brief A player unselects a node
* @param self The player context
* @param mousePos the position of the mouse to detect which node has been clicked
*/
void Player_unselect_Node(Player * self, Vector2 mousePos); void Player_unselect_Node(Player * self, Vector2 mousePos);
/**
* @brief Attack declaration
* @param self The attacking player
* @param defender The defending player
* @param originNode The attacker's node
* @param targetNode The defender's node
*/
void Player_attack_Node(Player * self, Player * defender, Node * originNode, Node * targetNode); void Player_attack_Node(Player * self, Player * defender, Node * originNode, Node * targetNode);
/**
* @brief Confirm placement of soldiers
* @param self The player context
*/
void Player_confirm_recrutement(Player * self); void Player_confirm_recrutement(Player * self);
#endif #endif
\ No newline at end of file
...@@ -47,7 +47,7 @@ void Random_map(NetWorld *world) ...@@ -47,7 +47,7 @@ void Random_map(NetWorld *world)
for (int j = 0; j < i; j++) for (int j = 0; j < i; j++)
{ {
printf("positionComparee %d %f\n", j, dist(world->nodes[j].position, newPosition)); //printf("positionComparee %d %f\n", j, dist(world->nodes[j].position, newPosition));
if (dist(world->nodes[j].position, newPosition) < 8.0) if (dist(world->nodes[j].position, newPosition) < 8.0)
{ {
continueLoop = true; continueLoop = true;
...@@ -86,7 +86,7 @@ void Random_map(NetWorld *world) ...@@ -86,7 +86,7 @@ void Random_map(NetWorld *world)
//printf("xm : %f\n", xm); //printf("xm : %f\n", xm);
//printf("ym : %f\n", ym); //printf("ym : %f\n", ym);
//printf("distNodeCenterOfij : %f\n", distNodeCenterOfij); //printf("distNodeCenterOfij : %f\n", distNodeCenterOfij);
printf("distNode %d%d : %f\n", i, j, distNode((world->nodes[i]), world->nodes[j])); //printf("distNode %d%d : %f\n", i, j, distNode((world->nodes[i]), world->nodes[j]));
for (int k = 0; k < nbNode; k++) for (int k = 0; k < nbNode; k++)
{ {
//printf(" distNode center - Node k %f\n", dist(world->nodes[k].position, M)); //printf(" distNode center - Node k %f\n", dist(world->nodes[k].position, M));
......
...@@ -3,11 +3,12 @@ ...@@ -3,11 +3,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
Window_Manager * Window_Manager_new(Panel * panel, Main_Menu * menu){ Window_Manager * Window_Manager_new(Panel * panel, Main_Menu * menu, Options_Menu * optionsMenu){
Window_Manager * self = malloc(sizeof(Window_Manager)); Window_Manager * self = malloc(sizeof(Window_Manager));
self->panel = panel; self->panel = panel;
self->display = (Display) main_menu; self->display = (Display) main_menu;
self->menu = menu; self->menu = menu;
self->options = optionsMenu;
return self; return self;
} }
...@@ -21,6 +22,7 @@ void Window_Manager_display(Window_Manager * self){ ...@@ -21,6 +22,7 @@ void Window_Manager_display(Window_Manager * self){
Panel_drawMainMenu(self->panel, self->menu); Panel_drawMainMenu(self->panel, self->menu);
break; break;
case options: case options:
Panel_drawOptionsMenu(self->panel, self->options);
break; break;
case game_ui: case game_ui:
Panel_drawGame(self->panel); Panel_drawGame(self->panel);
......
...@@ -5,17 +5,37 @@ ...@@ -5,17 +5,37 @@
#include "controlpanel.h" #include "controlpanel.h"
struct Str_Window_Manager{ struct Str_Window_Manager{
//! frame to display
Display display; Display display;
//! Reference to the panel context
Panel * panel; Panel * panel;
//! Reference to the main menu context
Main_Menu * menu; Main_Menu * menu;
//! Reference to the options context
Options_Menu * options;
}; };
typedef struct Str_Window_Manager Window_Manager; typedef struct Str_Window_Manager Window_Manager;
Window_Manager * Window_Manager_new(Panel * panel, Main_Menu * menu); /**
* @brief Initialise a Window_Manager
* @param panel Reference to the panel context
* @param menu Reference to the main menu context
* @param optionsMenu Reference to the options menu context
*/
Window_Manager * Window_Manager_new(Panel * panel, Main_Menu * menu, Options_Menu * optionsMenu);
/**
* @brief Void a Window Manager
* @param self The element to void
*/
void Window_Manager_delete(Window_Manager * manager); void Window_Manager_delete(Window_Manager * manager);
/**
* @brief Displays the appropriate frame
* @param self The manager context
*/
void Window_Manager_display(Window_Manager * self); void Window_Manager_display(Window_Manager * self);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment