Commit 2d0a1477 authored by ewen.madec's avatar ewen.madec

comments + cleaning

parent 2135e79f
...@@ -12,31 +12,29 @@ ...@@ -12,31 +12,29 @@
#include "raylib.h" #include "raylib.h"
void Graphic_ShowPlayerInfo(Player *player, int screenWidth, int screenHeight, Font font)
{
Rectangle rec = {0, screenHeight - 250, 250, 250}; //Draw current player number on the bottom left
void Graphic_ShowPlayerInfo(Player * player, int screenWidth, int screenHeight, Font font){
Rectangle rec = {0, screenHeight - 250, 250, 250};
DrawRectangleLinesEx(rec, 10, player->color); DrawRectangleLinesEx(rec, 10, player->color);
//Font font = LoadFont("Game On_PersonalUseOnly.ttf"); char *playerNumber = malloc(20 * sizeof(char));
char * playerNumber = malloc(20*sizeof(char));
sprintf(playerNumber, "Player %d", player->ID); sprintf(playerNumber, "Player %d", player->ID);
DrawTextEx(font, playerNumber, (Vector2){35, screenHeight - 240}, 30.0, 3.0, player->color); DrawTextEx(font, playerNumber, (Vector2){35, screenHeight - 240}, 30.0, 3.0, player->color);
char * soldierNumber = malloc(40*sizeof(char)); char *soldierNumber = malloc(40 * sizeof(char)); //Draw current player number of soldiers
sprintf(soldierNumber, "Soldiers left %d", player->soldiers); sprintf(soldierNumber, "Soldiers left %d", player->soldiers);
DrawTextEx(font, soldierNumber, (Vector2){15, screenHeight - 180}, 24.0, 3.0, player->color); DrawTextEx(font, soldierNumber, (Vector2){15, screenHeight - 180}, 24.0, 3.0, player->color);
int totalTroops = 0; int totalTroops = 0;
for(int i =0; i < player->nodeCount; i++){ for (int i = 0; i < player->nodeCount; i++)
{
totalTroops += player->nodes[i]->soldiers; totalTroops += player->nodes[i]->soldiers;
} }
char * str_totalTroops = malloc(40*sizeof(char)); char *str_totalTroops = malloc(40 * sizeof(char)); //Draw current player number of total troops owned
sprintf(str_totalTroops, "Total Troops %d", totalTroops); sprintf(str_totalTroops, "Total Troops %d", totalTroops);
DrawTextEx(font, str_totalTroops, (Vector2){15, screenHeight - 150}, 24.0, 3.0, player->color); DrawTextEx(font, str_totalTroops, (Vector2){15, screenHeight - 150}, 24.0, 3.0, player->color);
char * str_nodeCount = malloc(40*sizeof(char)); char *str_nodeCount = malloc(40 * sizeof(char)); //Draw current player number of nodes owned
sprintf(str_nodeCount, "Nodes owned %d", player->nodeCount); sprintf(str_nodeCount, "Nodes owned %d", player->nodeCount);
DrawTextEx(font, str_nodeCount, (Vector2){15, screenHeight - 120}, 24.0, 3.0, player->color); DrawTextEx(font, str_nodeCount, (Vector2){15, screenHeight - 120}, 24.0, 3.0, player->color);
free(playerNumber); free(playerNumber);
...@@ -45,409 +43,374 @@ void Graphic_ShowPlayerInfo(Player * player, int screenWidth, int screenHeight, ...@@ -45,409 +43,374 @@ void Graphic_ShowPlayerInfo(Player * player, int screenWidth, int screenHeight,
free(str_nodeCount); free(str_nodeCount);
} }
void Graphic_RecrutementPhase(Player * player, int screenWidth, int screenHeight, Font font){ void Graphic_RecrutementPhase(Player *player, int screenWidth, int screenHeight, Font font)
Rectangle rec = {screenWidth-300, 100 , 300, 400}; {
Rectangle rec = {screenWidth - 300, 100, 300, 400}; //Display recruitment phase rules
DrawRectangleLinesEx(rec, 10, player->color); DrawRectangleLinesEx(rec, 10, player->color);
DrawTextEx(font, "Recrutement Phase",(Vector2){screenWidth-275, 120}, 23.0, 3.0, player->color); DrawTextEx(font, "Recrutement Phase", (Vector2){screenWidth - 275, 120}, 23.0, 3.0, player->color);
DrawTextRec(font, " LEFT click on one of your node to recruit a soldier", (Rectangle){screenWidth-285, 175, 270, 100}, 20.0, 3.0, true, player->color); DrawTextRec(font, " LEFT click on one of your node to recruit a soldier", (Rectangle){screenWidth - 285, 175, 270, 100}, 20.0, 3.0, true, player->color);
DrawTextRec(font, " RIGHT click on the same node to remove the soldier", (Rectangle){screenWidth-285, 295, 270, 100}, 20.0, 3.0, true, player->color); DrawTextRec(font, " RIGHT click on the same node to remove the soldier", (Rectangle){screenWidth - 285, 295, 270, 100}, 20.0, 3.0, true, player->color);
DrawTextRec(font, " click Confirm once finished", (Rectangle){screenWidth-285, 415, 270, 100}, 20.0, 3.0, true, player->color); DrawTextRec(font, " click Confirm once finished", (Rectangle){screenWidth - 285, 415, 270, 100}, 20.0, 3.0, true, player->color);
} }
void Graphic_AttackPhase(Player * player, int screenWidth, int screenHeight, Font font){ void Graphic_AttackPhase(Player *player, int screenWidth, int screenHeight, Font font)
Rectangle rec = {screenWidth-300, 100 , 300, 450}; {
Rectangle rec = {screenWidth - 300, 100, 300, 450}; //Display attack phase rules
DrawRectangleLinesEx(rec, 10, player->color); DrawRectangleLinesEx(rec, 10, player->color);
DrawTextEx(font, "Attack Phase",(Vector2){screenWidth-265, 120}, 23.0, 3.0, player->color); DrawTextEx(font, "Attack Phase", (Vector2){screenWidth - 265, 120}, 23.0, 3.0, player->color);
DrawTextRec(font, " FIRST click on the node you want to attack from", (Rectangle){screenWidth-285, 175, 270, 100}, 20.0, 3.0, true, player->color); DrawTextRec(font, " FIRST click on the node you want to attack from", (Rectangle){screenWidth - 285, 175, 270, 100}, 20.0, 3.0, true, player->color);
DrawTextRec(font, " THEN click on one of neighbouring node you want to attack", (Rectangle){screenWidth-285, 295, 270, 100}, 20.0, 3.0, true, player->color); DrawTextRec(font, " THEN click on one of neighbouring node you want to attack", (Rectangle){screenWidth - 285, 295, 270, 100}, 20.0, 3.0, true, player->color);
DrawTextRec(font, " click Next Turn once finished all your attacks", (Rectangle){screenWidth-285, 415, 270, 100}, 20.0, 3.0, true, player->color); DrawTextRec(font, " click Next Turn once finished all your attacks", (Rectangle){screenWidth - 285, 415, 270, 100}, 20.0, 3.0, true, player->color);
} }
void Graphic_WhoseTurnIsIt(Player * player, int screenWidth, int screenHeight, Font font){ void Graphic_WhoseTurnIsIt(Player *player, int screenWidth, int screenHeight, Font font)
//Rectangle rec = {0, screenHeight - 250, 250, 250}; {
//DrawRectangleLinesEx(rec, 10, player->color); char *whoseTurn = malloc(20 * sizeof(char)); //Display whose turn is it
//Font font = LoadFont("Game On_PersonalUseOnly.ttf");
char * whoseTurn = malloc(20*sizeof(char));
sprintf(whoseTurn, "Player %d Turn", player->ID); sprintf(whoseTurn, "Player %d Turn", player->ID);
DrawTextEx(font, whoseTurn, (Vector2){screenWidth/2 - (MeasureTextEx(font, whoseTurn, 50.0, 3.0).x)/2 , 30} , 50.0, 3.0, player->color); DrawTextEx(font, whoseTurn, (Vector2){screenWidth / 2 - (MeasureTextEx(font, whoseTurn, 50.0, 3.0).x) / 2, 30}, 50.0, 3.0, player->color);
free(whoseTurn); free(whoseTurn);
} }
Rectangle Graphic_ConfirmButton(Font font) Rectangle Graphic_ConfirmButton(Font font)
{ { //Confirm button for the recruitment phase
Rectangle nextPhase = {200, 200, 220, 55}; Rectangle nextPhase = {200, 200, 220, 55};
DrawRectangleRec(nextPhase, GREEN); DrawRectangleRec(nextPhase, GREEN);
DrawTextEx(font, "Confirm",(Vector2){220 , 210} , 40.0, 3.0, BLACK); DrawTextEx(font, "Confirm", (Vector2){220, 210}, 40.0, 3.0, BLACK);
return nextPhase; return nextPhase;
} }
void Graphic_MouseHoverNodeRecrutement(Player * player, Vector2 mousePosition, Panel * panel){ void Graphic_MouseHoverNodeRecrutement(Player *player, Vector2 mousePosition, Panel *panel)
for(int nodeIndex = 0; nodeIndex < player->nodeCount; nodeIndex++){ {
Node* currentNode = player->nodes[nodeIndex]; for (int nodeIndex = 0; nodeIndex < player->nodeCount; nodeIndex++)
if(CheckCollisionPointRec(mousePosition, currentNode->collisionHitbox)){ {
//printf("collision noeud !\n"); Node *currentNode = player->nodes[nodeIndex]; //Draw a small ring when mouse hover one current player's node
Vector2 screenPosition= Panel_pixelFromPosition(panel, &(currentNode->position) ); if (CheckCollisionPointRec(mousePosition, currentNode->collisionHitbox))
{
Vector2 screenPosition = Panel_pixelFromPosition(panel, &(currentNode->position));
DrawRing(screenPosition, 24.0, 28.0, 0.0, 360.0, 0.1, MAGENTA); DrawRing(screenPosition, 24.0, 28.0, 0.0, 360.0, 0.1, MAGENTA);
//DrawCircleV(screenPosition, 45, RAYWHITE); if (player->soldiers > 0)
if(player->soldiers > 0){ {
DrawText("+1", (int)screenPosition.x + 30 , (int)screenPosition.y, 20, MAGENTA); DrawText("+1", (int)screenPosition.x + 30, (int)screenPosition.y, 20, MAGENTA);
} }
} }
} }
} }
void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition, Panel * panel){ void Graphic_MouseHoverNodeChooseAttacker(Player *player, Vector2 mousePosition, Panel *panel)
for(int nodeIndex = 0; nodeIndex < player-> nodeCount; nodeIndex++){ {
Node* currentNode = player->nodes[nodeIndex]; for (int nodeIndex = 0; nodeIndex < player->nodeCount; nodeIndex++)
if(CheckCollisionPointRec(mousePosition, currentNode->collisionHitbox)){ {
Vector2 screenPosition= Panel_pixelFromPosition(panel, &(currentNode->position) ); Node *currentNode = player->nodes[nodeIndex]; //Draw a small ring when mouse hover one current player's node
if(!player->hasSelectedNode && currentNode->soldiers > 1){ if (CheckCollisionPointRec(mousePosition, currentNode->collisionHitbox)) //and draw persistent ring when an attacker node is selected
{
Vector2 screenPosition = Panel_pixelFromPosition(panel, &(currentNode->position));
if (!player->hasSelectedNode && currentNode->soldiers > 1)
{
DrawRing(screenPosition, 24.0, 28.0, 0.0, 360.0, 0.1, GOLD); DrawRing(screenPosition, 24.0, 28.0, 0.0, 360.0, 0.1, GOLD);
DrawText("attacker", (int)screenPosition.x + 30 , (int)screenPosition.y, 20, GOLD); DrawText("attacker", (int)screenPosition.x + 30, (int)screenPosition.y, 20, GOLD);
Graphic_MouseHoverNodeChooseTarget(currentNode, mousePosition, panel); Graphic_MouseHoverNodeChooseTarget(currentNode, mousePosition, panel);
} }
} }
} }
if(player->hasSelectedNode){ if (player->hasSelectedNode)
Vector2 screenPosition= Panel_pixelFromPosition(panel, &(player->selectedNode->position) ); {
Vector2 screenPosition = Panel_pixelFromPosition(panel, &(player->selectedNode->position));
DrawRing(screenPosition, 24.0, 28.0, 0.0, 360.0, 0.1, GOLD); DrawRing(screenPosition, 24.0, 28.0, 0.0, 360.0, 0.1, GOLD);
DrawText("attacker", (int)screenPosition.x + 30 , (int)screenPosition.y, 20, GOLD); DrawText("attacker", (int)screenPosition.x + 30, (int)screenPosition.y, 20, GOLD);
} }
} }
void Graphic_MouseHoverNodeChooseTarget(Node * originNode, Vector2 mousePosition, Panel * panel){
for(int neighbourIndex = 0; neighbourIndex < originNode->card; neighbourIndex++){ void Graphic_MouseHoverNodeChooseTarget(Node *originNode, Vector2 mousePosition, Panel *panel)
Vector2 screenPosition = Panel_pixelFromPosition(panel, &(originNode->edges[neighbourIndex]._target->position) ); {
if( originNode->edges[neighbourIndex]._target->color.r != originNode->color.r || originNode->edges[neighbourIndex]._target->color.g != originNode->color.g || originNode->edges[neighbourIndex]._target->color.b != originNode->color.b || originNode->edges[neighbourIndex]._target->color.a != originNode->color.a){ for (int neighbourIndex = 0; neighbourIndex < originNode->card; neighbourIndex++) //Draw a ring for all the enemy nodes which can be attacked from the current selected attacker
{
Vector2 screenPosition = Panel_pixelFromPosition(panel, &(originNode->edges[neighbourIndex]._target->position));
if (originNode->edges[neighbourIndex]._target->color.r != originNode->color.r || originNode->edges[neighbourIndex]._target->color.g != originNode->color.g || originNode->edges[neighbourIndex]._target->color.b != originNode->color.b || originNode->edges[neighbourIndex]._target->color.a != originNode->color.a)
{
DrawRing(screenPosition, 24.0, 30.0, 0.0, 360.0, 0.1, GREEN); DrawRing(screenPosition, 24.0, 30.0, 0.0, 360.0, 0.1, GREEN);
if(CheckCollisionPointRec(mousePosition, originNode->edges[neighbourIndex]._target->collisionHitbox) && &(originNode->edges[neighbourIndex]._target->color) != &(originNode->color)){ if (CheckCollisionPointRec(mousePosition, originNode->edges[neighbourIndex]._target->collisionHitbox) && &(originNode->edges[neighbourIndex]._target->color) != &(originNode->color))
{
DrawRing(screenPosition, 30.0, 33.0, 0.0, 360.0, 0.1, MAROON); DrawRing(screenPosition, 30.0, 33.0, 0.0, 360.0, 0.1, MAROON);
} }
} }
} }
} }
int Graphic_ChooseNumberOfAttackers(Player *attacker, Player *defender, Node *originNode, Node *targetNode, Font font)
{
#define MAX_FRAME_SPEED 15
#define MIN_FRAME_SPEED 1
int Graphic_ChooseNumberOfAttackers(Player * attacker, Player * defender, Node * originNode, Node * targetNode, Font font)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 1700; const int screenWidth = 1700;
const int screenHeight = 800; const int screenHeight = 800;
bool endAnimation = false; bool endAnimation = false;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60);
//Display rectangles to choose how many soldiers/dices you want to engage in the fight
Rectangle nbAttackerRectangle[10]; Rectangle nbAttackerRectangle[10];
printf("number dice avail %d \n", originNode->soldiersToAdd + originNode->soldiers ); for (int i = 0; i < originNode->soldiersToAdd + originNode->soldiers; i++)
for(int i = 0 ; i < originNode->soldiersToAdd + originNode->soldiers ; i ++){ {
nbAttackerRectangle[i] = (Rectangle){200 + (i-1)*250, screenHeight - 500, 150, 70}; nbAttackerRectangle[i] = (Rectangle){200 + (i - 1) * 250, screenHeight - 500, 150, 70};
printf("rectangle %d position : %f %f \n", i, nbAttackerRectangle[i].x, nbAttackerRectangle[i].y);
} }
//char * whoseTurnToAttack = malloc(20*sizeof(char)); char whoseTurnToAttack[20];
char whoseTurnToAttack[20];
sprintf(whoseTurnToAttack, "Player %d attacks ", attacker->ID); sprintf(whoseTurnToAttack, "Player %d attacks ", attacker->ID);
//char * whoseTurnToDefend = malloc(20*sizeof(char));
char whoseTurnToDefend[20]; char whoseTurnToDefend[20];
sprintf(whoseTurnToDefend, "Player %d", defender->ID); sprintf(whoseTurnToDefend, "Player %d", defender->ID);
//--------------------------------------------------------------------------------------
// Main game loop while (!endAnimation)
while (!endAnimation ) // Detect window close button or ESC key
{ {
// Draw
//----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE);
Vector2 mousePosition = GetMousePosition();
ClearBackground(RAYWHITE); DrawTextEx(font, whoseTurnToAttack, (Vector2){screenWidth / 2 - (MeasureTextEx(font, whoseTurnToAttack, 50.0, 3.0).x) + 100, 70}, 50.0, 3.0, attacker->color);
Vector2 mousePosition = GetMousePosition(); DrawTextEx(font, whoseTurnToDefend, (Vector2){screenWidth / 2 + 100, 70}, 50.0, 3.0, defender->color);
DrawText("How many dices do you want to involve in the fight ?", screenWidth / 2 - (MeasureTextEx(font, "How many dice do you want to involve in the fight ?", 30.0, 3.0).x) / 2 + 50, 150, 30, attacker->color);
DrawTextEx(font, whoseTurnToAttack, (Vector2){screenWidth/2 - (MeasureTextEx(font, whoseTurnToAttack, 50.0, 3.0).x) + 100 , 70} , 50.0, 3.0, attacker->color);
DrawTextEx(font, whoseTurnToDefend, (Vector2){screenWidth/2 + 100 , 70}, 50.0, 3.0, defender->color);
DrawText("How many dices do you want to involve in the fight ?", screenWidth/2 - (MeasureTextEx(font, "How many dice do you want to involve in the fight ?", 30.0, 3.0).x)/2 + 50 , 150 , 30, attacker->color);
for(int i = 1 ; i < originNode->soldiersToAdd + originNode->soldiers ; i ++){
DrawRectangleRec(nbAttackerRectangle[i], BLACK);
char str_i[5];
sprintf(str_i, "%d", i);
DrawTextEx(font, str_i, (Vector2){nbAttackerRectangle[i].x + 55, nbAttackerRectangle[i].y + 5 }, 70.0, 3.0, WHITE);
if(CheckCollisionPointRec(mousePosition, nbAttackerRectangle[i])){
DrawRectangleLinesEx(nbAttackerRectangle[i], 5, GREEN);
}
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
if(CheckCollisionPointRec(mousePosition, nbAttackerRectangle[i])){
printf("colision dés choix %d \n", i);
return i;
}
}
}
for (int i = 1; i < originNode->soldiersToAdd + originNode->soldiers; i++)
{
DrawRectangleRec(nbAttackerRectangle[i], BLACK);
char str_i[5];
sprintf(str_i, "%d", i);
DrawTextEx(font, str_i, (Vector2){nbAttackerRectangle[i].x + 55, nbAttackerRectangle[i].y + 5}, 70.0, 3.0, WHITE);
if (CheckCollisionPointRec(mousePosition, nbAttackerRectangle[i]))
{
DrawRectangleLinesEx(nbAttackerRectangle[i], 5, GREEN);
}
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{
if (CheckCollisionPointRec(mousePosition, nbAttackerRectangle[i]))
{
printf("colision dés choix %d \n", i);
return i;
}
}
}
EndDrawing(); EndDrawing();
//----------------------------------------------------------------------------------
} }
// De-Initialization
//--------------------------------------------------------------------------------------
// Texture unloading
//free(whoseTurnToAttack);
//free(whoseTurnToDefend);
//free(nbAttackerRectangle);
//--------------------------------------------------------------------------------------
} }
void diceRolling(Player * attacker, Player * defender, Node * originNode, Node * targetNode, int nbOfAttackers,int nbOfDefenders, int * listOfDices, Font font)
{
printf("dice rolling begin\n");
// Initialization void Graphic_diceRolling(Player *attacker, Player *defender, Node *originNode, Node *targetNode, int nbOfAttackers, int nbOfDefenders, int *listOfDices, Font font)
//-------------------------------------------------------------------------------------- {
const int screenWidth = 1700; const int screenWidth = 1700;
const int screenHeight = 800; const int screenHeight = 800;
Image texture = LoadImage("diceRolling.png");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) ImageResize(&(texture), 100, 800);
Image texture = LoadImage("diceRolling.png");
ImageResize(&(texture), 100, 800);
//Texture2D diceTexture = LoadTexture("diceRolling.png"); // Texture loading
Texture2D diceTexture = LoadTextureFromImage(texture); Texture2D diceTexture = LoadTextureFromImage(texture);
int defendersCount = nbOfDefenders; int defendersCount = nbOfDefenders;
printf("defender nbofsoldiers : %d \n", defendersCount);
for(int i = 0; i< defendersCount+nbOfAttackers; i++){
printf("listOfdices [%d] : %d \n",i,listOfDices[i]);
}
int attackersCount = nbOfAttackers; int attackersCount = nbOfAttackers;
char *whoseTurnToAttack = malloc(20 * sizeof(char));
Rectangle frameRec = { 0.0f, 0.0f, (float)diceTexture.width, (float)diceTexture.height/9 };
int currentFrame = 0;
int framesCounter = 0;
int framesSpeed = 7;
int frameExit = 0; // Number of spritesheet frames shown by second
bool endAnimationDice = false;
bool endDisplayResult = false;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
char * whoseTurnToAttack = malloc(20*sizeof(char));
sprintf(whoseTurnToAttack, "Player %d ", attacker->ID); sprintf(whoseTurnToAttack, "Player %d ", attacker->ID);
char * whoseTurnToDefend = malloc(20*sizeof(char)); char *whoseTurnToDefend = malloc(20 * sizeof(char));
sprintf(whoseTurnToDefend, "Player %d ", defender->ID); sprintf(whoseTurnToDefend, "Player %d ", defender->ID);
Rectangle skipAnimation = {screenWidth / 2 - 125, 200, 190, 50};
Rectangle skipResult = {screenWidth / 2 - 105, 200, 150, 50};
Vector2 * positionDiceAttacker = malloc(20 * sizeof(Vector2)); Vector2 *positionDiceAttacker = malloc(20 * sizeof(Vector2));
Vector2 * positionDiceDefender = malloc(20 * sizeof(Vector2)); Vector2 *positionDiceDefender = malloc(20 * sizeof(Vector2));
for(int i = 0 ; i < nbOfAttackers ; i++){ for (int i = 0; i < nbOfAttackers; i++)
{
positionDiceAttacker[i] = (Vector2){200 + (i)*150, screenHeight - 500}; positionDiceAttacker[i] = (Vector2){200 + (i)*150, screenHeight - 500};
} }
for(int i = 0 ; i < defendersCount ; i++){ for (int i = 0; i < defendersCount; i++)
{
positionDiceDefender[i] = (Vector2){1000 + (i)*150, screenHeight - 500}; positionDiceDefender[i] = (Vector2){1000 + (i)*150, screenHeight - 500};
} }
// Main game loop Rectangle frameRec = {0.0f, 0.0f, (float)diceTexture.width, (float)diceTexture.height / 9};
while (!endAnimationDice ) // Detect window close button or ESC key int currentFrame = 0;
int framesCounter = 0;
int framesSpeed = 7;
int frameExit = 0;
bool endAnimationDice = false;
SetTargetFPS(60);
while (!endAnimationDice) //Animation of dices
{ {
// Update Vector2 mousePosition = GetMousePosition();
//----------------------------------------------------------------------------------
framesCounter++; framesCounter++;
frameExit++; frameExit++;
//printf("%d frame before Exit0 \n", frameExit);
if(frameExit == 200) endAnimationDice = true; if (frameExit == 200)
if (framesCounter >= (60/framesSpeed)) endAnimationDice = true;
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{
if (CheckCollisionPointRec(mousePosition, skipAnimation))
{
endAnimationDice = true;
}
}
if (framesCounter >= (60 / framesSpeed))
{ {
framesCounter = 0; framesCounter = 0;
currentFrame++; currentFrame++;
if (currentFrame > 8)
if (currentFrame > 8) currentFrame = 0; currentFrame = 0;
frameRec.y = (float)currentFrame * (float)diceTexture.height / 9;
frameRec.y = (float)currentFrame*(float)diceTexture.height/9;
} }
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTextEx(font, whoseTurnToAttack, (Vector2){250 , 100} , 40.0, 3.0, attacker->color); DrawTextEx(font, whoseTurnToAttack, (Vector2){250, 100}, 40.0, 3.0, attacker->color);
DrawTextEx(font, whoseTurnToDefend, (Vector2){screenWidth-700, 100}, 40.0, 3.0, defender->color); DrawTextEx(font, whoseTurnToDefend, (Vector2){screenWidth - 700, 100}, 40.0, 3.0, defender->color);
DrawTextEx(font, " attacker", (Vector2){250 , 150} , 30.0, 3.0, attacker->color); DrawTextEx(font, " attacker", (Vector2){250, 150}, 30.0, 3.0, attacker->color);
DrawTextEx(font, " defender", (Vector2){screenWidth-700, 150}, 30.0, 3.0, defender->color); DrawTextEx(font, " defender", (Vector2){screenWidth - 700, 150}, 30.0, 3.0, defender->color);
for(int i = 0 ; i < nbOfAttackers ; i++){ DrawRectangleRec(skipAnimation, BLUE);
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); DrawTextEx(font, "Skip Animation", (Vector2){screenWidth / 2 - 115, 210}, 18.0, 3.0, BLACK);
} for (int i = 0; i < nbOfAttackers; i++)
for(int i = 0 ; i < defendersCount ; i++){ {
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
} }
for (int i = 0; i < defendersCount; i++)
{
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i], WHITE);
}
EndDrawing(); EndDrawing();
//----------------------------------------------------------------------------------
} }
currentFrame = 0; currentFrame = 0;
framesCounter = 0; framesCounter = 0;
framesSpeed = 7; bool endDisplayResult = false;
endDisplayResult = false;
while (!endDisplayResult ) // Detect window close button or ESC key while (!endDisplayResult) //Display result of the dice rolling
{ {
// Update Vector2 mousePosition = GetMousePosition();
//----------------------------------------------------------------------------------
framesCounter++; framesCounter++;
frameExit++; frameExit++;
//printf("%d frame before Exit1 \n", frameExit);
if(frameExit == 350) endDisplayResult = true; if (frameExit == 300)
if (framesCounter >= (60/framesSpeed)) endDisplayResult = true;
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{
if (CheckCollisionPointRec(mousePosition, skipResult))
{
endDisplayResult = true;
}
}
if (framesCounter >= (60 / framesSpeed))
{ {
framesCounter = 0; framesCounter = 0;
currentFrame++; currentFrame++;
if (currentFrame > 8)
if (currentFrame > 8) currentFrame = 0; currentFrame = 0;
frameRec.y = (float)currentFrame * (float)diceTexture.height / 9;
frameRec.y = (float)currentFrame*(float)diceTexture.height/9;
} }
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTextEx(font, whoseTurnToAttack, (Vector2){250 , 100} , 40.0, 3.0, attacker->color); DrawTextEx(font, whoseTurnToAttack, (Vector2){250, 100}, 40.0, 3.0, attacker->color);
DrawTextEx(font, whoseTurnToDefend, (Vector2){screenWidth-700, 100}, 40.0, 3.0, defender->color); DrawTextEx(font, whoseTurnToDefend, (Vector2){screenWidth - 700, 100}, 40.0, 3.0, defender->color);
DrawTextEx(font, " attacker", (Vector2){250 , 150} , 30.0, 3.0, attacker->color); DrawTextEx(font, " attacker", (Vector2){250, 150}, 30.0, 3.0, attacker->color);
DrawTextEx(font, " defender", (Vector2){screenWidth-700, 150}, 30.0, 3.0, defender->color); DrawTextEx(font, " defender", (Vector2){screenWidth - 700, 150}, 30.0, 3.0, defender->color);
for(int i = 0 ; i < nbOfAttackers ; i++){ DrawRectangleRec(skipResult, BLUE);
switch (listOfDices[i]) DrawTextEx(font, "Skip Result", (Vector2){screenWidth / 2 - 100, 210}, 18.0, 3.0, BLACK);
{ for (int i = 0; i < nbOfAttackers; i++)
case 1: {
frameRec.y = 9*(float)diceTexture.height/9; switch (listOfDices[i])
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); {
DrawTextEx(font, "1", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y+100}, 50.0, 3.0, BLACK); case 1:
break; frameRec.y = 9 * (float)diceTexture.height / 9;
case 2: DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
frameRec.y = 1*(float)diceTexture.height/9; DrawTextEx(font, "1", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK);
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); break;
DrawTextEx(font, "2", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y+100}, 50.0, 3.0, BLACK); case 2:
break; frameRec.y = 1 * (float)diceTexture.height / 9;
case 3: DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
frameRec.y = 2*(float)diceTexture.height/9; DrawTextEx(font, "2", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK);
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); break;
DrawTextEx(font, "3", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y+100}, 50.0, 3.0, BLACK); case 3:
break; frameRec.y = 2 * (float)diceTexture.height / 9;
case 4: DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
frameRec.y = 3*(float)diceTexture.height/9; DrawTextEx(font, "3", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK);
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); break;
DrawTextEx(font, "4", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y+100}, 50.0, 3.0, BLACK); case 4:
break; frameRec.y = 3 * (float)diceTexture.height / 9;
case 5: DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
frameRec.y = 4*(float)diceTexture.height/9; DrawTextEx(font, "4", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK);
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); break;
DrawTextEx(font, "5", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y+100}, 50.0, 3.0, BLACK); case 5:
break; frameRec.y = 4 * (float)diceTexture.height / 9;
case 6: DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
frameRec.y = 5*(float)diceTexture.height/9; DrawTextEx(font, "5", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK);
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); break;
DrawTextEx(font, "6", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y+100}, 50.0, 3.0, BLACK); case 6:
break; frameRec.y = 5 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
default: DrawTextEx(font, "6", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK);
break; break;
}
//DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); default:
break;
} }
for(int i = nbOfAttackers ; i < nbOfAttackers + defendersCount ; i++){ }
switch (listOfDices[i]) for (int i = nbOfAttackers; i < nbOfAttackers + defendersCount; i++)
{ {
case 1: switch (listOfDices[i])
frameRec.y = 9*(float)diceTexture.height/9; {
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i-nbOfAttackers], WHITE); case 1:
DrawTextEx(font, "1", (Vector2){positionDiceDefender[i-nbOfAttackers].x + 30, positionDiceDefender[i-nbOfAttackers].y + 100}, 50.0, 3.0, BLACK); frameRec.y = 9 * (float)diceTexture.height / 9;
break; DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE);
case 2: DrawTextEx(font, "1", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK);
frameRec.y = 1*(float)diceTexture.height/9; break;
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i-nbOfAttackers], WHITE); case 2:
DrawTextEx(font, "2", (Vector2){positionDiceDefender[i-nbOfAttackers].x + 30, positionDiceDefender[i-nbOfAttackers].y + 100}, 50.0, 3.0, BLACK); frameRec.y = 1 * (float)diceTexture.height / 9;
break; DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE);
case 3: DrawTextEx(font, "2", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK);
frameRec.y = 2*(float)diceTexture.height/9; break;
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i-nbOfAttackers], WHITE); case 3:
DrawTextEx(font, "3", (Vector2){positionDiceDefender[i-nbOfAttackers].x + 30, positionDiceDefender[i-nbOfAttackers].y + 100}, 50.0, 3.0, BLACK); frameRec.y = 2 * (float)diceTexture.height / 9;
break; DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE);
case 4: DrawTextEx(font, "3", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK);
frameRec.y = 3*(float)diceTexture.height/9; break;
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i-nbOfAttackers], WHITE); case 4:
DrawTextEx(font, "4", (Vector2){positionDiceDefender[i-nbOfAttackers].x + 30, positionDiceDefender[i-nbOfAttackers].y + 100}, 50.0, 3.0, BLACK); frameRec.y = 3 * (float)diceTexture.height / 9;
break; DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE);
case 5: DrawTextEx(font, "4", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK);
frameRec.y = 4*(float)diceTexture.height/9; break;
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i-nbOfAttackers], WHITE); case 5:
DrawTextEx(font, "5", (Vector2){positionDiceDefender[i-nbOfAttackers].x + 30, positionDiceDefender[i-nbOfAttackers].y+100}, 50.0, 3.0, BLACK); frameRec.y = 4 * (float)diceTexture.height / 9;
break; DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE);
case 6: DrawTextEx(font, "5", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK);
frameRec.y = 5*(float)diceTexture.height/9; break;
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i-nbOfAttackers], WHITE); case 6:
DrawTextEx(font, "6", (Vector2){positionDiceDefender[i-nbOfAttackers].x + 30, positionDiceDefender[i-nbOfAttackers].y + 100}, 50.0, 3.0, BLACK); frameRec.y = 5 * (float)diceTexture.height / 9;
break; DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE);
DrawTextEx(font, "6", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK);
default: break;
break;
} default:
break;
} }
int remainingAttackers = attackersCount; }
for(int index = 0; index < fmin(defendersCount, attackersCount); index++){
if(listOfDices[index] > listOfDices[index + attackersCount]){
//targetNode->soldiers--;
//printf("Defenders lose a soldier\n");
DrawTextEx(font, "Defenders lose a soldier", (Vector2){screenWidth/2 - MeasureTextEx(font, "Defenders lose a soldier",50.0, 3.0 ).x/2 -50 , 600}, 50.0, 3.0, BLACK);
}else{
//originNode->soldiers--;
//remainingAttackers--;
//printf("Attackers lose a soldier\n");
DrawTextEx(font, "Attackers lose a soldier", (Vector2){screenWidth/2 - MeasureTextEx(font, "Attackers lose a soldier",50.0, 3.0 ).x/2 -50 , 600}, 50.0, 3.0, BLACK);
} int remainingAttackers = attackersCount;
for (int index = 0; index < fmin(defendersCount, attackersCount); index++)
{
if (listOfDices[index] > listOfDices[index + attackersCount])
{
DrawTextEx(font, "Defenders lose a soldier", (Vector2){screenWidth / 2 - MeasureTextEx(font, "Defenders lose a soldier", 50.0, 3.0).x / 2 - 50, 600}, 50.0, 3.0, BLACK);
} }
else
if(targetNode->soldiers <= 0){ {
//printf("Node has been conquered\n"); DrawTextEx(font, "Attackers lose a soldier", (Vector2){screenWidth / 2 - MeasureTextEx(font, "Attackers lose a soldier", 50.0, 3.0).x / 2 - 50, 600}, 50.0, 3.0, BLACK);
DrawTextEx(font, "Node has been conquered", (Vector2){screenWidth/2 - MeasureTextEx(font, "Node has been conquered",50.0, 3.0 ).x/2 -50 , 700}, 50.0, 3.0, BLACK);
//Player_remove_Node(defender, targetNode);
//Player_add_Node(self, targetNode);
//targetNode->soldiers = attackersCount;
//originNode->soldiers -= attackersCount;
} }
}
EndDrawing(); if (targetNode->soldiers <= 0)
//---------------------------------------------------------------------------------- {
} DrawTextEx(font, "Node has been conquered", (Vector2){screenWidth / 2 - MeasureTextEx(font, "Node has been conquered", 50.0, 3.0).x / 2 - 50, 700}, 50.0, 3.0, BLACK);
}
// De-Initialization
//--------------------------------------------------------------------------------------
// Texture unloading
//CloseWindow(); EndDrawing();
}
free(whoseTurnToAttack); free(whoseTurnToAttack);
free(whoseTurnToDefend); free(whoseTurnToDefend);
free(positionDiceAttacker); free(positionDiceAttacker);
free(positionDiceDefender); free(positionDiceDefender);
UnloadImage(texture); // Close window and OpenGL context UnloadImage(texture);
UnloadTexture(diceTexture); UnloadTexture(diceTexture);
//--------------------------------------------------------------------------------------
} }
...@@ -8,18 +8,35 @@ ...@@ -8,18 +8,35 @@
//Graphical view //Graphical view
//Display players' number of nodes owned, number of total troops and number of soldier to place on the bottom left of the screen
void Graphic_ShowPlayerInfo(Player * player, const int screenWidth, const int screenHeight, Font font); void Graphic_ShowPlayerInfo(Player * player, const int screenWidth, const int screenHeight, Font font);
//Display recrutement phase rules on the right of the screen
void Graphic_RecrutementPhase(Player * player, const int screenWidth, const int screenHeight, Font font); void Graphic_RecrutementPhase(Player * player, const int screenWidth, const int screenHeight, Font font);
//Display attack phase rules on the right of the screen
void Graphic_AttackPhase(Player * player, const int screenWidth, const int screenHeight, Font font); void Graphic_AttackPhase(Player * player, const int screenWidth, const int screenHeight, Font font);
//Display whose turn is it on the top of the screen
void Graphic_WhoseTurnIsIt(Player * player, const int screenWidth, const int screenHeight, Font font); void Graphic_WhoseTurnIsIt(Player * player, const int screenWidth, const int screenHeight, Font font);
//Confirm button for the recruitment phase
Rectangle Graphic_ConfirmButton(Font font); Rectangle Graphic_ConfirmButton(Font font);
//Animation when mouse hover node during recruitment phase
void Graphic_MouseHoverNodeRecrutement(Player * self, Vector2 mousePosition, Panel * panel); void Graphic_MouseHoverNodeRecrutement(Player * self, Vector2 mousePosition, Panel * panel);
//Animation when mouse hover node when choosing attacker node during attack phase
void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition, Panel * panel); void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition, Panel * panel);
//Animation when mouse hover node when choosing target node during attack phase
void Graphic_MouseHoverNodeChooseTarget(Node * originNode, Vector2 mousePosition, Panel * panel); void Graphic_MouseHoverNodeChooseTarget(Node * originNode, Vector2 mousePosition, Panel * panel);
void Graphic_RectuementBeginTurn(int screenWidth, int screenHeight, Font font);
//Display a window to choose number of dices to involve in a fight + return the number chosen
int Graphic_ChooseNumberOfAttackers(Player * attacker, Player * defender, Node * originNode, Node * targetNode, Font font); int Graphic_ChooseNumberOfAttackers(Player * attacker, Player * defender, Node * originNode, Node * targetNode, Font font);
void diceRolling(Player * attacker, Player * defender, Node * originNode, Node * targetNode, int nbOfAttackers, int nbOfDefenders, int * listOfDices, Font font);
//Display animation of dice rolling + results of the dice rolling
void Graphic_diceRolling(Player * attacker, Player * defender, Node * originNode, Node * targetNode, int nbOfAttackers, int nbOfDefenders, int * listOfDices, Font font);
......
...@@ -242,7 +242,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon ...@@ -242,7 +242,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon
for(int i = 0; i< nbOfDefenders+nbOfAttackers; i++){ for(int i = 0; i< nbOfDefenders+nbOfAttackers; i++){
printf("listOfdices3 [%d] : %d \n",i,listOfDices[i]); printf("listOfdices3 [%d] : %d \n",i,listOfDices[i]);
} }
diceRolling(currentPlayer, &(players[nodePlayerID]), originNode, currentNode, nbOfAttackers ,nbOfDefenders, listOfDices ,font); Graphic_diceRolling(currentPlayer, &(players[nodePlayerID]), originNode, currentNode, nbOfAttackers ,nbOfDefenders, listOfDices, font);
currentPlayer->hasSelectedNode = false; currentPlayer->hasSelectedNode = false;
free(listOfDices); free(listOfDices);
}else{ }else{
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "raylib.h" #include "raylib.h"
double randfrom(double min, double max) double randfrom(double min, double max)
{ {
double range = (max - min); double range = (max - min);
...@@ -22,43 +23,47 @@ double dist(Vector2 vector1, Vector2 vector2) ...@@ -22,43 +23,47 @@ double dist(Vector2 vector1, Vector2 vector2)
{ {
return (sqrt((vector2.x - vector1.x) * (vector2.x - vector1.x) + (vector2.y - vector1.y) * (vector2.y - vector1.y))); return (sqrt((vector2.x - vector1.x) * (vector2.x - vector1.x) + (vector2.y - vector1.y) * (vector2.y - vector1.y)));
} }
double distNode(Node node1, Node node2) double distNode(Node node1, Node node2)
{ {
return (dist(node1.position, node2.position)); return (dist(node1.position, node2.position));
} }
const double rangeForXcoordinates = 30.0;
const double rangeForYcoordinates = 30.0;
const double minimumDistance = 8.0;
void Random_map(NetWorld *world) void Random_map(NetWorld *world)
{ {
int nbNode = world->size; int nbNode = world->size;
float randomX, randomY; float randomX, randomY;
/* Intializes random number generator */ /* Intializes random number generator */
srand(time(NULL)); srand(time(NULL));
/* Generate nbNode*2 random numbers from -15.00 to 15.00 */
/* Generate nbNode*2 random numbers for y-coordinates and x-coordinates of the nodes*/
for (int i = 0; i < nbNode; i++) for (int i = 0; i < nbNode; i++)
{ {
if (i > 0) if (i > 0)
{ {
bool continueLoop = true; bool continueLoop = true;
while (continueLoop) while (continueLoop) //loop until the minimum distance between the new node and the others is respected
{ {
continueLoop = false; continueLoop = false;
randomX = randfrom(-30.0, 30.0); randomX = randfrom(-rangeForXcoordinates, rangeForXcoordinates);
randomY = randfrom(-30.0, 30.0); randomY = randfrom(-rangeForYcoordinates, rangeForYcoordinates);
Vector2 newPosition = (Vector2){randomX, randomY}; Vector2 newPosition = (Vector2){randomX, randomY};
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)); if (dist(world->nodes[j].position, newPosition) < minimumDistance)
if (dist(world->nodes[j].position, newPosition) < 8.0)
{ {
continueLoop = true; continueLoop = true;
} }
} }
} }
//randomX = randfrom(-15.0, 15.0); char *name; name = malloc(20*sizeof(char)); sprintf(name, "name : %d", i);
//randomY = randfrom(-15.0, 15.0);
char *name;
name = malloc(20*sizeof(char));
sprintf(name, "name : %d", i);
Node_set(&(world->nodes[i]), (Vector2){randomX, randomY}, RED, name); Node_set(&(world->nodes[i]), (Vector2){randomX, randomY}, RED, name);
free(name); free(name);
} }
...@@ -66,13 +71,9 @@ void Random_map(NetWorld *world) ...@@ -66,13 +71,9 @@ void Random_map(NetWorld *world)
{ {
randomX = randfrom(-15.0, 15.0); randomX = randfrom(-15.0, 15.0);
randomY = randfrom(-15.0, 15.0); randomY = randfrom(-15.0, 15.0);
char *name; char *name; name = malloc(20*sizeof(char)); sprintf(name, "name : %d", i);
name = malloc(20*sizeof(char));
sprintf(name, "name : %d", i);
Node_set(&(world->nodes[i]), (Vector2){randomX, randomY}, RED, name); Node_set(&(world->nodes[i]), (Vector2){randomX, randomY}, RED, name);
free(name); free(name);
printf("%f\n", randomX);
printf("%f\n", randomY);
} }
} }
//Gabriel graph sort //Gabriel graph sort
...@@ -85,21 +86,17 @@ void Random_map(NetWorld *world) ...@@ -85,21 +86,17 @@ void Random_map(NetWorld *world)
float ym = 0.5 * (world->nodes[i].position.y + world->nodes[j].position.y); float ym = 0.5 * (world->nodes[i].position.y + world->nodes[j].position.y);
Vector2 M = {xm, ym}; Vector2 M = {xm, ym};
float distNodeCenterOfij = dist(world->nodes[i].position, M); float distNodeCenterOfij = dist(world->nodes[i].position, M);
//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));
if (dist(world->nodes[k].position, M) < distNodeCenterOfij - 0.05) if (dist(world->nodes[k].position, M) < distNodeCenterOfij - 0.05)
{ {
compteurPointDansLeCercle++; compteurPointDansLeCercle++;
} }
} }
//printf("compteurPointDansLeCercle : %i\n", compteurPointDansLeCercle);
if (compteurPointDansLeCercle == 0) if (compteurPointDansLeCercle == 0)
{ {
NetWorld_biconnect(world, i, j); NetWorld_biconnect(world, i, j);
} }
} }
} }
} }
\ No newline at end of file
...@@ -4,11 +4,18 @@ ...@@ -4,11 +4,18 @@
#include "raylib.h" #include "raylib.h"
#include "networld.h" #include "networld.h"
void Random_map(NetWorld * world);
double randfrom(double min, double max);
double dist(Vector2 vector1, Vector2 vector2); //random function
double randfrom(double min, double max);
//distance between 2 points(Vector2)
double dist(Vector2 vector1, Vector2 vector2);
//distance between 2 nodes
double distNode(Node node1, Node node2); double distNode(Node node1, Node node2);
//generation of a random map following Gabriel Graph theory
void Random_map(NetWorld * world);
#endif #endif
\ No newline at end of file
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