Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NetWorld
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LAIRD Timothy
NetWorld
Commits
032bace8
Commit
032bace8
authored
Apr 26, 2021
by
LAIRD Timothy
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'animation' into 'dev'
Animation to dev See merge request
!6
parents
879e5d31
3ef9800b
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
312 additions
and
46 deletions
+312
-46
CMakeLists.txt
CMakeLists.txt
+2
-2
controlpanel.c
src/controlpanel.c
+4
-4
graphical-aspect.c
src/graphical-aspect.c
+273
-28
graphical-aspect.h
src/graphical-aspect.h
+3
-1
main-viewer.c
src/main-viewer.c
+6
-3
player.c
src/player.c
+17
-2
player.h
src/player.h
+4
-3
random-map.c
src/random-map.c
+3
-3
No files found.
CMakeLists.txt
View file @
032bace8
...
@@ -20,9 +20,9 @@ link_directories( ${PROJECT_SOURCE_DIR}/dpd )
...
@@ -20,9 +20,9 @@ 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 src/int-input.c src/options-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
(
risk
raylib pthread dl rt X11 m
)
#without cmake package...
#without cmake package...
#include_directories(${PROJECT_SOURCE_DIR}/raylib/src)
#include_directories(${PROJECT_SOURCE_DIR}/raylib/src)
#link_directories(${PROJECT_SOURCE_DIR}/raylib)
#link_directories(${PROJECT_SOURCE_DIR}/raylib)
#target_link_libraries(
nw-viewer
raylib GL m pthread dl rt X11)
#target_link_libraries(
risk
raylib GL m pthread dl rt X11)
src/controlpanel.c
View file @
032bace8
...
@@ -32,8 +32,8 @@ void Panel_initialize(Panel * self, NetWorld * world, const int screenWidth, con
...
@@ -32,8 +32,8 @@ void Panel_initialize(Panel * self, NetWorld * world, const int screenWidth, con
self
->
world
=
world
;
self
->
world
=
world
;
self
->
camera
.
x
=
0
.
f
;
self
->
camera
.
x
=
0
.
f
;
self
->
camera
.
y
=
0
.
f
;
self
->
camera
.
y
=
0
.
f
;
self
->
screenCenter
.
x
=
400
.
f
;
self
->
screenCenter
.
x
=
screenWidth
/
2
;
self
->
screenCenter
.
y
=
300
.
f
;
self
->
screenCenter
.
y
=
screenHeight
/
2
;
self
->
scale
=
10
.
f
;
//pixel per meters
self
->
scale
=
10
.
f
;
//pixel per meters
self
->
screenWidth
=
screenWidth
;
self
->
screenWidth
=
screenWidth
;
self
->
screenHeight
=
screenHeight
;
self
->
screenHeight
=
screenHeight
;
...
@@ -84,7 +84,7 @@ void Panel_drawOptionsMenu(Panel * self, Options_Menu * menu){
...
@@ -84,7 +84,7 @@ void Panel_drawOptionsMenu(Panel * self, Options_Menu * menu){
void
Panel_drawGame
(
Panel
*
self
)
void
Panel_drawGame
(
Panel
*
self
)
{
{
BeginDrawing
();
//
BeginDrawing();
ClearBackground
(
RAYWHITE
);
ClearBackground
(
RAYWHITE
);
// Draw the edges for each nodes:
// Draw the edges for each nodes:
...
@@ -101,7 +101,7 @@ void Panel_drawGame(Panel * self)
...
@@ -101,7 +101,7 @@ void Panel_drawGame(Panel * self)
Panel_drawNode
(
self
,
&
(
self
->
world
->
nodes
[
i
])
);
Panel_drawNode
(
self
,
&
(
self
->
world
->
nodes
[
i
])
);
}
}
//Panel_drawBasis(self);
//Panel_drawBasis(self);
EndDrawing
();
//
EndDrawing();
}
}
void
Panel_drawBasis
(
Panel
*
self
)
void
Panel_drawBasis
(
Panel
*
self
)
...
...
src/graphical-aspect.c
View file @
032bace8
...
@@ -55,12 +55,12 @@ void Graphic_RecrutementPhase(Player * player, int screenWidth, int screenHeight
...
@@ -55,12 +55,12 @@ void Graphic_RecrutementPhase(Player * player, int screenWidth, int screenHeight
}
}
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
,
4
0
0
};
Rectangle
rec
=
{
screenWidth
-
300
,
100
,
300
,
4
5
0
};
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"
,
(
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
){
...
@@ -88,7 +88,7 @@ void Graphic_MouseHoverNodeRecrutement(Player * player, Vector2 mousePosition, P
...
@@ -88,7 +88,7 @@ void Graphic_MouseHoverNodeRecrutement(Player * player, Vector2 mousePosition, P
if
(
CheckCollisionPointRec
(
mousePosition
,
currentNode
->
collisionHitbox
)){
if
(
CheckCollisionPointRec
(
mousePosition
,
currentNode
->
collisionHitbox
)){
//printf("collision noeud !\n");
//printf("collision noeud !\n");
Vector2
screenPosition
=
Panel_pixelFromPosition
(
panel
,
&
(
currentNode
->
position
)
);
Vector2
screenPosition
=
Panel_pixelFromPosition
(
panel
,
&
(
currentNode
->
position
)
);
Draw
CircleV
(
screenPosition
,
29
,
MAGENTA
);
Draw
Ring
(
screenPosition
,
24
.
0
,
28
.
0
,
0
.
0
,
360
.
0
,
0
.
1
,
MAGENTA
);
//DrawCircleV(screenPosition, 45, RAYWHITE);
//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
);
...
@@ -103,7 +103,7 @@ void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition
...
@@ -103,7 +103,7 @@ void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition
Node
*
currentNode
=
player
->
nodes
[
nodeIndex
];
Node
*
currentNode
=
player
->
nodes
[
nodeIndex
];
if
(
CheckCollisionPointRec
(
mousePosition
,
currentNode
->
collisionHitbox
)){
if
(
CheckCollisionPointRec
(
mousePosition
,
currentNode
->
collisionHitbox
)){
Vector2
screenPosition
=
Panel_pixelFromPosition
(
panel
,
&
(
currentNode
->
position
)
);
Vector2
screenPosition
=
Panel_pixelFromPosition
(
panel
,
&
(
currentNode
->
position
)
);
Draw
CircleV
(
screenPosition
,
29
,
GOLD
);
Draw
Ring
(
screenPosition
,
24
.
0
,
28
.
0
,
0
.
0
,
360
.
0
,
0
.
1
,
GOLD
);
//DrawCircleV(screenPosition, 45, RAYWHITE);
//DrawCircleV(screenPosition, 45, RAYWHITE);
if
(
!
player
->
hasSelectedNode
){
if
(
!
player
->
hasSelectedNode
){
DrawText
(
"attacker"
,
(
int
)
screenPosition
.
x
+
30
,
(
int
)
screenPosition
.
y
,
20
,
GOLD
);
DrawText
(
"attacker"
,
(
int
)
screenPosition
.
x
+
30
,
(
int
)
screenPosition
.
y
,
20
,
GOLD
);
...
@@ -112,16 +112,19 @@ void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition
...
@@ -112,16 +112,19 @@ void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition
}
}
if
(
player
->
hasSelectedNode
){
if
(
player
->
hasSelectedNode
){
Vector2
screenPosition
=
Panel_pixelFromPosition
(
panel
,
&
(
player
->
selectedNode
->
position
)
);
Vector2
screenPosition
=
Panel_pixelFromPosition
(
panel
,
&
(
player
->
selectedNode
->
position
)
);
Draw
CircleV
(
screenPosition
,
29
,
GOLD
);
Draw
Ring
(
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
){
void
Graphic_MouseHoverNodeChooseTarget
(
Node
*
originNode
,
Vector2
mousePosition
,
Panel
*
panel
){
for
(
int
neighbourIndex
=
0
;
neighbourIndex
<
originNode
->
card
;
neighbourIndex
++
){
for
(
int
neighbourIndex
=
0
;
neighbourIndex
<
originNode
->
card
;
neighbourIndex
++
){
Vector2
screenPosition
=
Panel_pixelFromPosition
(
panel
,
&
(
originNode
->
edges
[
neighbourIndex
].
_target
->
position
)
);
Vector2
screenPosition
=
Panel_pixelFromPosition
(
panel
,
&
(
originNode
->
edges
[
neighbourIndex
].
_target
->
position
)
);
/* if( &(originNode->edges[neighbourIndex]._target->color) = &(originNode->color)){
if
(
&
(
originNode
->
edges
[
neighbourIndex
].
_target
->
color
)
!=
&
(
originNode
->
color
)){
DrawCircleV(screenPosition, 29, 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
)){
DrawRing
(
screenPosition
,
30
.
0
,
33
.
0
,
0
.
0
,
360
.
0
,
0
.
1
,
MAROON
);
}
}
}
}
}
...
@@ -129,40 +132,178 @@ void Graphic_MouseHoverNodeChooseTarget(Node * originNode, Vector2 mousePosition
...
@@ -129,40 +132,178 @@ void Graphic_MouseHoverNodeChooseTarget(Node * originNode, Vector2 mousePosition
#define MAX_FRAME_SPEED 15
#define MAX_FRAME_SPEED 15
#define MIN_FRAME_SPEED 1
#define MIN_FRAME_SPEED 1
void
diceRolling
()
int
Graphic_ChooseNumberOfAttackers
(
Player
*
attacker
,
Player
*
defender
,
Node
*
originNode
,
Node
*
targetNode
,
Font
font
)
{
printf
(
"dice rolling begin
\n
"
);
// Initialization
{
// Initialization
//--------------------------------------------------------------------------------------
const
int
screenWidth
=
1700
;
const
int
screenHeight
=
800
;
bool
endAnimation
=
false
;
SetTargetFPS
(
60
);
// Set our game to run at 60 frames-per-second
Rectangle
*
nbAttackerRectangle
=
malloc
(
10
*
sizeof
(
Rectangle
));
printf
(
"number dice avail %d
\n
"
,
originNode
->
soldiersToAdd
+
originNode
->
soldiers
);
for
(
int
i
=
0
;
i
<
originNode
->
soldiersToAdd
+
originNode
->
soldiers
;
i
++
){
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
));
sprintf
(
whoseTurnToAttack
,
"Player %d attacks "
,
attacker
->
ID
);
char
*
whoseTurnToDefend
=
malloc
(
20
*
sizeof
(
char
));
sprintf
(
whoseTurnToDefend
,
"Player %d"
,
defender
->
ID
);
//--------------------------------------------------------------------------------------
// Main game loop
while
(
!
endAnimation
)
// Detect window close button or ESC key
{
// Draw
//----------------------------------------------------------------------------------
BeginDrawing
();
ClearBackground
(
RAYWHITE
);
Vector2
mousePosition
=
GetMousePosition
();
DrawTextEx
(
font
,
whoseTurnToAttack
,
(
Vector2
){
screenWidth
/
2
-
(
MeasureTextEx
(
font
,
whoseTurnToAttack
,
50
.
0
,
3
.
0
).
x
)
+
50
,
70
}
,
50
.
0
,
3
.
0
,
attacker
->
color
);
DrawTextEx
(
font
,
whoseTurnToDefend
,
(
Vector2
){
screenWidth
/
2
+
50
,
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
=
malloc
(
sizeof
(
int
));
sprintf
(
str_i
,
"%d"
,
i
);
DrawTextEx
(
font
,
str_i
,
(
Vector2
){
nbAttackerRectangle
[
i
].
x
+
55
,
nbAttackerRectangle
[
i
].
y
+
5
},
70
.
0
,
3
.
0
,
WHITE
);
free
(
str_i
);
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
();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
// Texture unloading
free
(
whoseTurnToAttack
);
free
(
whoseTurnToDefend
);
free
(
nbAttackerRectangle
);
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
const
int
screenWidth1
=
800
;
const
int
screenHeight1
=
450
;
InitWindow
(
screenWidth1
,
screenHeight1
,
"raylib [texture] example - texture rectangle"
);
}
void
diceRolling
(
Player
*
attacker
,
Player
*
defender
,
Node
*
originNode
,
Node
*
targetNode
,
int
nbOfAttackers
,
int
*
listOfDices
,
Font
font
)
{
printf
(
"dice rolling begin
\n
"
);
// Initialization
//--------------------------------------------------------------------------------------
const
int
screenWidth
=
1700
;
const
int
screenHeight
=
800
;
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture2D
diceTexture
=
LoadTexture
(
"diceRolling.png"
);
// Texture loading
Image
texture
=
LoadImage
(
"diceRolling.png"
);
ImageResize
(
&
(
texture
),
100
,
800
);
//Texture2D diceTexture = LoadTexture("diceRolling.png"); // Texture loading
Texture2D
diceTexture
=
LoadTextureFromImage
(
texture
);
int
defendersCount
=
targetNode
->
soldiers
>=
3
?
2
:
1
;
int
attackersCount
=
nbOfAttackers
;
Vector2
position
=
{
350
.
0
f
,
100
.
0
f
};
Rectangle
frameRec
=
{
0
.
0
f
,
0
.
0
f
,
(
float
)
diceTexture
.
width
,
(
float
)
diceTexture
.
height
/
9
};
Rectangle
frameRec
=
{
0
.
0
f
,
0
.
0
f
,
(
float
)
diceTexture
.
width
,
(
float
)
diceTexture
.
height
/
9
};
int
currentFrame
=
0
;
int
currentFrame
=
0
;
int
framesCounter
=
0
;
int
framesCounter
=
0
;
int
framesSpeed
=
10
;
int
framesSpeed
=
7
;
int
frameExit
=
0
;
// Number of spritesheet frames shown by second
int
frameExit
=
0
;
// Number of spritesheet frames shown by second
bool
endAnimation
=
false
;
bool
endAnimationDice
=
false
;
bool
endDisplayResult
=
false
;
SetTargetFPS
(
60
);
// Set our game to run at 60 frames-per-second
SetTargetFPS
(
60
);
// Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
char
*
whoseTurnToAttack
=
malloc
(
20
*
sizeof
(
char
));
sprintf
(
whoseTurnToAttack
,
"Player %d "
,
attacker
->
ID
);
char
*
whoseTurnToDefend
=
malloc
(
20
*
sizeof
(
char
));
sprintf
(
whoseTurnToDefend
,
"Player %d "
,
defender
->
ID
);
Vector2
*
positionDiceAttacker
=
malloc
(
20
*
sizeof
(
Vector2
));
Vector2
*
positionDiceDefender
=
malloc
(
20
*
sizeof
(
Vector2
));
for
(
int
i
=
0
;
i
<
nbOfAttackers
;
i
++
){
positionDiceAttacker
[
i
]
=
(
Vector2
){
200
+
(
i
)
*
150
,
screenHeight
-
500
};
}
for
(
int
i
=
0
;
i
<
defendersCount
+
1
;
i
++
){
positionDiceDefender
[
i
]
=
(
Vector2
){
1000
+
(
i
)
*
150
,
screenHeight
-
500
};
printf
(
"position dice defender %d x : %f
\n
"
,
i
,
positionDiceDefender
[
i
].
x
);
printf
(
"position dice defender %d y : %f
\n
"
,
i
,
positionDiceDefender
[
i
].
y
);
}
// Main game loop
// Main game loop
while
(
!
WindowShouldClose
()
)
// Detect window close button or ESC key
while
(
!
endAnimationDice
)
// Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
framesCounter
++
;
frameExit
++
;
//printf("%d frame before Exit0 \n", frameExit);
if
(
frameExit
==
200
)
endAnimationDice
=
true
;
if
(
framesCounter
>=
(
60
/
framesSpeed
))
{
framesCounter
=
0
;
currentFrame
++
;
if
(
currentFrame
>
8
)
currentFrame
=
0
;
frameRec
.
y
=
(
float
)
currentFrame
*
(
float
)
diceTexture
.
height
/
9
;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing
();
ClearBackground
(
RAYWHITE
);
DrawTextEx
(
font
,
whoseTurnToAttack
,
(
Vector2
){
250
,
200
}
,
30
.
0
,
3
.
0
,
attacker
->
color
);
DrawTextEx
(
font
,
whoseTurnToDefend
,
(
Vector2
){
screenWidth
-
700
,
200
},
30
.
0
,
3
.
0
,
defender
->
color
);
DrawTextEx
(
font
,
" attacker"
,
(
Vector2
){
250
+
MeasureTextEx
(
font
,
"Player X "
,
30
.
0
,
3
.
0
).
x
,
210
}
,
15
.
0
,
3
.
0
,
attacker
->
color
);
DrawTextEx
(
font
,
" defender"
,
(
Vector2
){
screenWidth
-
700
+
MeasureTextEx
(
font
,
"Player X "
,
30
.
0
,
3
.
0
).
x
,
210
},
15
.
0
,
3
.
0
,
defender
->
color
);
for
(
int
i
=
0
;
i
<
nbOfAttackers
;
i
++
){
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceAttacker
[
i
],
WHITE
);
}
for
(
int
i
=
0
;
i
<
defendersCount
;
i
++
){
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceDefender
[
i
],
WHITE
);
}
EndDrawing
();
//----------------------------------------------------------------------------------
}
currentFrame
=
0
;
framesCounter
=
0
;
framesSpeed
=
7
;
endDisplayResult
=
false
;
while
(
!
endDisplayResult
)
// Detect window close button or ESC key
{
{
// Update
// Update
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
framesCounter
++
;
framesCounter
++
;
frameExit
++
;
frameExit
++
;
printf
(
"%d frameExit
\n
"
,
frameExit
);
//printf("%d frame before Exit1
\n", frameExit);
if
(
frameExit
==
100
)
endAnimation
=
true
;
if
(
frameExit
==
450
)
endDisplayResult
=
true
;
if
(
framesCounter
>=
(
60
/
framesSpeed
))
if
(
framesCounter
>=
(
60
/
framesSpeed
))
{
{
framesCounter
=
0
;
framesCounter
=
0
;
...
@@ -179,11 +320,112 @@ void diceRolling()
...
@@ -179,11 +320,112 @@ void diceRolling()
BeginDrawing
();
BeginDrawing
();
ClearBackground
(
RAYWHITE
);
ClearBackground
(
RAYWHITE
);
//Vector2 * positionDiceAttacker = malloc(sizeof(Vector2)*attackerNbDice) ;
/* for(int attackerDice = 0; attackerDice < attackerNbDice ; attackerDice++){
} */
DrawTextEx
(
font
,
whoseTurnToAttack
,
(
Vector2
){
250
,
200
}
,
30
.
0
,
3
.
0
,
attacker
->
color
);
DrawTextureRec
(
diceTexture
,
frameRec
,
position
,
WHITE
);
// Draw part of the texture
DrawTextEx
(
font
,
whoseTurnToDefend
,
(
Vector2
){
screenWidth
-
700
,
200
},
30
.
0
,
3
.
0
,
defender
->
color
);
DrawTextEx
(
font
,
" attacker"
,
(
Vector2
){
250
+
MeasureTextEx
(
font
,
"Player X "
,
30
.
0
,
3
.
0
).
x
,
210
}
,
15
.
0
,
3
.
0
,
attacker
->
color
);
DrawTextEx
(
font
,
" defender"
,
(
Vector2
){
screenWidth
-
700
+
MeasureTextEx
(
font
,
"Player X "
,
30
.
0
,
3
.
0
).
x
,
210
},
15
.
0
,
3
.
0
,
defender
->
color
);
for
(
int
i
=
0
;
i
<
nbOfAttackers
;
i
++
){
switch
(
listOfDices
[
i
])
{
case
1
:
frameRec
.
y
=
9
*
(
float
)
diceTexture
.
height
/
9
;
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceAttacker
[
i
],
WHITE
);
DrawTextEx
(
font
,
"1"
,
(
Vector2
){
positionDiceAttacker
[
i
].
x
+
30
,
positionDiceAttacker
[
i
].
y
+
100
},
50
.
0
,
3
.
0
,
BLACK
);
break
;
case
2
:
frameRec
.
y
=
1
*
(
float
)
diceTexture
.
height
/
9
;
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceAttacker
[
i
],
WHITE
);
DrawTextEx
(
font
,
"2"
,
(
Vector2
){
positionDiceAttacker
[
i
].
x
+
30
,
positionDiceAttacker
[
i
].
y
+
100
},
50
.
0
,
3
.
0
,
BLACK
);
break
;
case
3
:
frameRec
.
y
=
2
*
(
float
)
diceTexture
.
height
/
9
;
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceAttacker
[
i
],
WHITE
);
DrawTextEx
(
font
,
"3"
,
(
Vector2
){
positionDiceAttacker
[
i
].
x
+
30
,
positionDiceAttacker
[
i
].
y
+
100
},
50
.
0
,
3
.
0
,
BLACK
);
break
;
case
4
:
frameRec
.
y
=
3
*
(
float
)
diceTexture
.
height
/
9
;
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceAttacker
[
i
],
WHITE
);
DrawTextEx
(
font
,
"4"
,
(
Vector2
){
positionDiceAttacker
[
i
].
x
+
30
,
positionDiceAttacker
[
i
].
y
+
100
},
50
.
0
,
3
.
0
,
BLACK
);
break
;
case
5
:
frameRec
.
y
=
4
*
(
float
)
diceTexture
.
height
/
9
;
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceAttacker
[
i
],
WHITE
);
DrawTextEx
(
font
,
"5"
,
(
Vector2
){
positionDiceAttacker
[
i
].
x
+
30
,
positionDiceAttacker
[
i
].
y
+
100
},
50
.
0
,
3
.
0
,
BLACK
);
break
;
case
6
:
frameRec
.
y
=
5
*
(
float
)
diceTexture
.
height
/
9
;
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceAttacker
[
i
],
WHITE
);
DrawTextEx
(
font
,
"6"
,
(
Vector2
){
positionDiceAttacker
[
i
].
x
+
30
,
positionDiceAttacker
[
i
].
y
+
100
},
50
.
0
,
3
.
0
,
BLACK
);
break
;
default
:
break
;
}
//DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
}
for
(
int
i
=
nbOfAttackers
;
i
<
nbOfAttackers
+
defendersCount
+
1
;
i
++
){
switch
(
listOfDices
[
i
])
{
case
1
:
frameRec
.
y
=
9
*
(
float
)
diceTexture
.
height
/
9
;
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceDefender
[
i
-
nbOfAttackers
],
WHITE
);
DrawTextEx
(
font
,
"1"
,
(
Vector2
){
positionDiceDefender
[
i
-
nbOfAttackers
].
x
+
30
,
positionDiceDefender
[
i
-
nbOfAttackers
].
y
+
100
},
50
.
0
,
3
.
0
,
BLACK
);
break
;
case
2
:
frameRec
.
y
=
1
*
(
float
)
diceTexture
.
height
/
9
;
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceDefender
[
i
-
nbOfAttackers
],
WHITE
);
DrawTextEx
(
font
,
"2"
,
(
Vector2
){
positionDiceDefender
[
i
-
nbOfAttackers
].
x
+
30
,
positionDiceDefender
[
i
-
nbOfAttackers
].
y
+
100
},
50
.
0
,
3
.
0
,
BLACK
);
break
;
case
3
:
frameRec
.
y
=
2
*
(
float
)
diceTexture
.
height
/
9
;
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceDefender
[
i
-
nbOfAttackers
],
WHITE
);
DrawTextEx
(
font
,
"3"
,
(
Vector2
){
positionDiceDefender
[
i
-
nbOfAttackers
].
x
+
30
,
positionDiceDefender
[
i
-
nbOfAttackers
].
y
+
100
},
50
.
0
,
3
.
0
,
BLACK
);
break
;
case
4
:
frameRec
.
y
=
3
*
(
float
)
diceTexture
.
height
/
9
;
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceDefender
[
i
-
nbOfAttackers
],
WHITE
);
DrawTextEx
(
font
,
"4"
,
(
Vector2
){
positionDiceDefender
[
i
-
nbOfAttackers
].
x
+
30
,
positionDiceDefender
[
i
-
nbOfAttackers
].
y
+
100
},
50
.
0
,
3
.
0
,
BLACK
);
break
;
case
5
:
frameRec
.
y
=
4
*
(
float
)
diceTexture
.
height
/
9
;
DrawTextureRec
(
diceTexture
,
frameRec
,
positionDiceDefender
[
i
-
nbOfAttackers
],
WHITE
);
DrawTextEx
(
font
,
"5"
,
(
Vector2
){
positionDiceDefender
[
i
-
nbOfAttackers
].
x
+
30
,
positionDiceDefender
[
i
-
nbOfAttackers
].
y
+
100
},
50
.
0
,
3
.
0
,
BLACK
);
break
;
case
6
:
frameRec
.
y
=
5
*
(
float
)
diceTexture
.
height
/
9
;
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
);
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
,
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
,
600
},
50
.
0
,
3
.
0
,
BLACK
);
}
}
if
(
targetNode
->
soldiers
<=
0
){
//printf("Node has been conquered\n");
DrawTextEx
(
font
,
"Node has been conquered"
,
(
Vector2
){
screenWidth
/
2
-
MeasureTextEx
(
font
,
"Node has been conquered"
,
50
.
0
,
3
.
0
).
x
/
2
,
700
},
50
.
0
,
3
.
0
,
BLACK
);
//Player_remove_Node(defender, targetNode);
//Player_add_Node(self, targetNode);
//targetNode->soldiers = attackersCount;
//originNode->soldiers -= attackersCount;
}
EndDrawing
();
EndDrawing
();
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
...
@@ -193,10 +435,13 @@ void diceRolling()
...
@@ -193,10 +435,13 @@ void diceRolling()
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Texture unloading
// Texture unloading
CloseWindow
();
// Close window and OpenGL context
//CloseWindow();
free
(
whoseTurnToAttack
);
free
(
whoseTurnToDefend
);
free
(
positionDiceAttacker
);
free
(
positionDiceDefender
);
// Close window and OpenGL context
UnloadTexture
(
diceTexture
);
UnloadTexture
(
diceTexture
);
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
}
}
src/graphical-aspect.h
View file @
032bace8
...
@@ -17,7 +17,9 @@ Rectangle Graphic_ConfirmButton(Font font);
...
@@ -17,7 +17,9 @@ 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
);
void
Graphic_MouseHoverNodeChooseTarget
(
Node
*
originNode
,
Vector2
mousePosition
,
Panel
*
panel
);
void
Graphic_MouseHoverNodeChooseTarget
(
Node
*
originNode
,
Vector2
mousePosition
,
Panel
*
panel
);
void
diceRolling
();
void
Graphic_RectuementBeginTurn
(
int
screenWidth
,
int
screenHeight
,
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
*
listOfDices
,
Font
font
);
...
...
src/main-viewer.c
View file @
032bace8
...
@@ -192,9 +192,12 @@ void game_update(NetWorld * world, Player * players, Font font, Panel * panel)
...
@@ -192,9 +192,12 @@ void game_update(NetWorld * world, Player * players, Font font, Panel * panel)
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
(
"Engaging attack on target Node
\n
"
);
printf
(
"Engagine attack on target Node
\n
"
);
Player_attack_Node
(
currentPlayer
,
&
(
players
[
nodePlayerID
]),
originNode
,
currentNode
);
int
nbOfAttackers
=
Graphic_ChooseNumberOfAttackers
(
currentPlayer
,
&
(
players
[
nodePlayerID
]),
originNode
,
currentNode
,
font
);
//diceRolling();
int
*
listOfDices
=
Player_attack_Node
(
currentPlayer
,
&
(
players
[
nodePlayerID
]),
originNode
,
currentNode
,
nbOfAttackers
);
int
defendersCount
=
currentNode
->
soldiers
>=
3
?
2
:
1
;
diceRolling
(
currentPlayer
,
&
(
players
[
nodePlayerID
]),
originNode
,
currentNode
,
nbOfAttackers
,
listOfDices
,
font
);
free
(
listOfDices
);
}
else
{
}
else
{
}
}
}
}
...
...
src/player.c
View file @
032bace8
...
@@ -46,6 +46,9 @@ void Player_add_Node( Player * self, Node * node )
...
@@ -46,6 +46,9 @@ void Player_add_Node( Player * self, Node * node )
newNodes
[
i
]
=
self
->
nodes
[
i
];
newNodes
[
i
]
=
self
->
nodes
[
i
];
}
}
node
->
color
=
self
->
color
;
node
->
color
=
self
->
color
;
for
(
int
i
=
0
;
i
<
node
->
card
;
i
++
){
node
->
edges
[
i
].
color
=
self
->
color
;
}
node
->
playerID
=
self
->
ID
;
node
->
playerID
=
self
->
ID
;
newNodes
[
self
->
nodeCount
]
=
node
;
newNodes
[
self
->
nodeCount
]
=
node
;
free
(
self
->
nodes
);
free
(
self
->
nodes
);
...
@@ -147,8 +150,9 @@ void Player_confirm_recrutement(Player * self){
...
@@ -147,8 +150,9 @@ void Player_confirm_recrutement(Player * self){
};
};
void
Player_attack_Node
(
Player
*
self
,
Player
*
defender
,
Node
*
originNode
,
Node
*
targetNode
){
int
*
Player_attack_Node
(
Player
*
self
,
Player
*
defender
,
Node
*
originNode
,
Node
*
targetNode
,
int
numberOfAttackers
){
int
attackersCount
=
fmin
(
3
,
(
originNode
->
soldiers
-
1
));
int
*
listOfDices
=
malloc
(
20
*
sizeof
(
int
));
int
attackersCount
=
numberOfAttackers
;
int
defendersCount
=
targetNode
->
soldiers
>=
3
?
2
:
1
;
int
defendersCount
=
targetNode
->
soldiers
>=
3
?
2
:
1
;
int
attDiceRolls
[
attackersCount
];
int
attDiceRolls
[
attackersCount
];
int
defDiceRolls
[
defendersCount
];
int
defDiceRolls
[
defendersCount
];
...
@@ -182,6 +186,12 @@ void Player_attack_Node(Player * self, Player * defender, Node * originNode, Nod
...
@@ -182,6 +186,12 @@ void Player_attack_Node(Player * self, Player * defender, Node * originNode, Nod
}
}
}
}
}
}
for
(
int
index
=
0
;
index
<
attackersCount
;
index
++
){
listOfDices
[
index
]
=
attDiceRolls
[
index
];
}
for
(
int
index
=
0
;
index
<
defendersCount
;
index
++
){
listOfDices
[
index
+
attackersCount
]
=
defDiceRolls
[
index
];
}
printf
(
"Attackers dice rolls :
\t
"
);
printf
(
"Attackers dice rolls :
\t
"
);
for
(
int
index
=
0
;
index
<
attackersCount
;
index
++
){
for
(
int
index
=
0
;
index
<
attackersCount
;
index
++
){
...
@@ -216,4 +226,9 @@ void Player_attack_Node(Player * self, Player * defender, Node * originNode, Nod
...
@@ -216,4 +226,9 @@ void Player_attack_Node(Player * self, Player * defender, Node * originNode, Nod
}
}
originNode
->
canAttack
=
false
;
originNode
->
canAttack
=
false
;
return
listOfDices
;
}
void
Delete_Player_attack_Node
(
int
*
listOfDices
){
free
(
listOfDices
);
}
}
src/player.h
View file @
032bace8
...
@@ -120,10 +120,11 @@ void Player_unselect_Node(Player * self, Vector2 mousePos);
...
@@ -120,10 +120,11 @@ void Player_unselect_Node(Player * self, Vector2 mousePos);
* @param defender The defending player
* @param defender The defending player
* @param originNode The attacker's node
* @param originNode The attacker's node
* @param targetNode The defender's node
* @param targetNode The defender's node
* @param numberOfAttackers Number of attacking soldiers
*/
*/
void
Player_attack_Node
(
Player
*
self
,
Player
*
defender
,
Node
*
originNode
,
Node
*
targetNode
);
int
*
Player_attack_Node
(
Player
*
self
,
Player
*
defender
,
Node
*
originNode
,
Node
*
targetNode
,
int
numberOfAttackers
);
/**
/**
* @brief Confirm placement of soldiers
* @brief Confirm placement of soldiers
* @param self The player context
* @param self The player context
*/
*/
...
...
src/random-map.c
View file @
032bace8
...
@@ -60,6 +60,7 @@ void Random_map(NetWorld *world)
...
@@ -60,6 +60,7 @@ void Random_map(NetWorld *world)
name
=
malloc
(
20
*
sizeof
(
char
));
name
=
malloc
(
20
*
sizeof
(
char
));
sprintf
(
name
,
"name : %d"
,
i
);
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
);
}
}
else
else
{
{
...
@@ -69,6 +70,7 @@ void Random_map(NetWorld *world)
...
@@ -69,6 +70,7 @@ void Random_map(NetWorld *world)
name
=
malloc
(
20
*
sizeof
(
char
));
name
=
malloc
(
20
*
sizeof
(
char
));
sprintf
(
name
,
"name : %d"
,
i
);
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
);
printf
(
"%f
\n
"
,
randomX
);
printf
(
"%f
\n
"
,
randomX
);
printf
(
"%f
\n
"
,
randomY
);
printf
(
"%f
\n
"
,
randomY
);
}
}
...
@@ -83,9 +85,6 @@ void Random_map(NetWorld *world)
...
@@ -83,9 +85,6 @@ 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("xm : %f\n", xm);
//printf("ym : %f\n", ym);
//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
++
)
{
{
...
@@ -102,4 +101,5 @@ void Random_map(NetWorld *world)
...
@@ -102,4 +101,5 @@ void Random_map(NetWorld *world)
}
}
}
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment