Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SnakeProject
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
Benjamin LEROUX
SnakeProject
Commits
0e5877be
Commit
0e5877be
authored
Oct 30, 2020
by
Benjamin LEROUX
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ajout difficultes et menu de demarrage
parent
a1ecc9bf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
45 deletions
+72
-45
snake.c
snake.c
+72
-45
No files found.
snake.c
View file @
0e5877be
...
...
@@ -24,8 +24,6 @@
#define SQUARE_SIZE 31
#define NUMBEROFWALL 8
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
...
...
@@ -71,8 +69,8 @@ static Sound goldenFruitSound;
static
Sound
deathSound
;
static
Music
music
;
static
bool
isMute
;
static
bool
isReady
=
false
;
static
int
level
;
//easy = 1 AND hard =2
//------------------------------------------------------------------------------------
// Module Functions Declaration (local)
...
...
@@ -82,6 +80,7 @@ static void UpdateGame(void); // Update game (one frame)
static
void
DrawGame
(
void
);
// Draw game (one frame)
static
void
UnloadGame
(
void
);
// Unload game
static
void
UpdateDrawFrame
(
void
);
// Update and Draw (one frame)
static
void
SelectScreen
();
//------------------------------------------------------------------------------------
// Program main entry point
...
...
@@ -92,11 +91,16 @@ int main(void)
//---------------------------------------------------------
InitWindow
(
screenWidth
,
screenHeight
,
"sample game: snake"
);
// Select screen loop
while
(
!
WindowShouldClose
()
&&
!
isReady
)
// Detect window close button or ESC key
{
SelectScreen
();
}
InitGame
();
InitAudioDevice
();
// Initialize audio device
StopMusicStream
(
music
);
PlayMusicStream
(
music
);
#if defined(PLATFORM_WEB)
...
...
@@ -136,7 +140,6 @@ void InitGame(void)
gameOver
=
false
;
pause
=
false
;
isMute
=
false
;
counterTail
=
1
;
allowMove
=
false
;
...
...
@@ -173,45 +176,47 @@ void InitGame(void)
deadFruit
.
active
=
false
;
//murs
recTab
[
0
].
x
=
2
*
SQUARE_SIZE
+
offset
.
x
/
2
;
//mur haut gauche
recTab
[
0
].
y
=
2
*
SQUARE_SIZE
+
offset
.
y
/
2
;
recTab
[
0
].
width
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
0
].
height
=
(
SQUARE_SIZE
*
4
)
-
0
.
1
;
recTab
[
1
].
x
=
3
*
SQUARE_SIZE
+
offset
.
x
/
2
;
recTab
[
1
].
y
=
2
*
SQUARE_SIZE
+
offset
.
y
/
2
;
recTab
[
1
].
width
=
(
SQUARE_SIZE
*
3
)
-
0
.
1
;
recTab
[
1
].
height
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
2
].
x
=
screenWidth
-
(
offset
.
x
/
2
)
-
(
3
*
SQUARE_SIZE
);
//mur haut droit
recTab
[
2
].
y
=
2
*
SQUARE_SIZE
+
offset
.
y
/
2
;
recTab
[
2
].
width
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
2
].
height
=
(
SQUARE_SIZE
*
4
)
-
0
.
1
;
recTab
[
3
].
x
=
screenWidth
-
(
offset
.
x
/
2
)
-
(
6
*
SQUARE_SIZE
);
recTab
[
3
].
y
=
2
*
SQUARE_SIZE
+
offset
.
y
/
2
;
recTab
[
3
].
width
=
(
SQUARE_SIZE
*
3
)
-
0
.
1
;
recTab
[
3
].
height
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
4
].
x
=
2
*
SQUARE_SIZE
+
offset
.
x
/
2
;
//mur bas gauche
recTab
[
4
].
y
=
screenHeight
-
(
offset
.
y
/
2
)
-
(
6
*
SQUARE_SIZE
);
recTab
[
4
].
width
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
4
].
height
=
(
SQUARE_SIZE
*
3
)
-
0
.
1
;
recTab
[
5
].
x
=
2
*
SQUARE_SIZE
+
offset
.
x
/
2
;
recTab
[
5
].
y
=
screenHeight
-
(
offset
.
y
/
2
)
-
(
3
*
SQUARE_SIZE
);
recTab
[
5
].
width
=
(
SQUARE_SIZE
*
4
)
-
0
.
1
;
recTab
[
5
].
height
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
6
].
x
=
screenWidth
-
(
offset
.
x
/
2
)
-
(
3
*
SQUARE_SIZE
);
//mur bas droit
recTab
[
6
].
y
=
screenHeight
-
(
offset
.
y
/
2
)
-
(
6
*
SQUARE_SIZE
);
recTab
[
6
].
width
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
6
].
height
=
(
SQUARE_SIZE
*
4
)
-
0
.
1
;
recTab
[
7
].
x
=
screenWidth
-
(
offset
.
x
/
2
)
-
(
6
*
SQUARE_SIZE
);
recTab
[
7
].
y
=
screenHeight
-
(
offset
.
y
/
2
)
-
(
3
*
SQUARE_SIZE
);
recTab
[
7
].
width
=
(
SQUARE_SIZE
*
3
)
-
0
.
1
;
recTab
[
7
].
height
=
(
SQUARE_SIZE
)
-
0
.
1
;
if
(
level
==
2
){
recTab
[
0
].
x
=
2
*
SQUARE_SIZE
+
offset
.
x
/
2
;
//mur haut gauche
recTab
[
0
].
y
=
2
*
SQUARE_SIZE
+
offset
.
y
/
2
;
recTab
[
0
].
width
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
0
].
height
=
(
SQUARE_SIZE
*
4
)
-
0
.
1
;
recTab
[
1
].
x
=
3
*
SQUARE_SIZE
+
offset
.
x
/
2
;
recTab
[
1
].
y
=
2
*
SQUARE_SIZE
+
offset
.
y
/
2
;
recTab
[
1
].
width
=
(
SQUARE_SIZE
*
3
)
-
0
.
1
;
recTab
[
1
].
height
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
2
].
x
=
screenWidth
-
(
offset
.
x
/
2
)
-
(
3
*
SQUARE_SIZE
);
//mur haut droit
recTab
[
2
].
y
=
2
*
SQUARE_SIZE
+
offset
.
y
/
2
;
recTab
[
2
].
width
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
2
].
height
=
(
SQUARE_SIZE
*
4
)
-
0
.
1
;
recTab
[
3
].
x
=
screenWidth
-
(
offset
.
x
/
2
)
-
(
6
*
SQUARE_SIZE
);
recTab
[
3
].
y
=
2
*
SQUARE_SIZE
+
offset
.
y
/
2
;
recTab
[
3
].
width
=
(
SQUARE_SIZE
*
3
)
-
0
.
1
;
recTab
[
3
].
height
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
4
].
x
=
2
*
SQUARE_SIZE
+
offset
.
x
/
2
;
//mur bas gauche
recTab
[
4
].
y
=
screenHeight
-
(
offset
.
y
/
2
)
-
(
6
*
SQUARE_SIZE
);
recTab
[
4
].
width
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
4
].
height
=
(
SQUARE_SIZE
*
3
)
-
0
.
1
;
recTab
[
5
].
x
=
2
*
SQUARE_SIZE
+
offset
.
x
/
2
;
recTab
[
5
].
y
=
screenHeight
-
(
offset
.
y
/
2
)
-
(
3
*
SQUARE_SIZE
);
recTab
[
5
].
width
=
(
SQUARE_SIZE
*
4
)
-
0
.
1
;
recTab
[
5
].
height
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
6
].
x
=
screenWidth
-
(
offset
.
x
/
2
)
-
(
3
*
SQUARE_SIZE
);
//mur bas droit
recTab
[
6
].
y
=
screenHeight
-
(
offset
.
y
/
2
)
-
(
6
*
SQUARE_SIZE
);
recTab
[
6
].
width
=
(
SQUARE_SIZE
)
-
0
.
1
;
recTab
[
6
].
height
=
(
SQUARE_SIZE
*
4
)
-
0
.
1
;
recTab
[
7
].
x
=
screenWidth
-
(
offset
.
x
/
2
)
-
(
6
*
SQUARE_SIZE
);
recTab
[
7
].
y
=
screenHeight
-
(
offset
.
y
/
2
)
-
(
3
*
SQUARE_SIZE
);
recTab
[
7
].
width
=
(
SQUARE_SIZE
*
3
)
-
0
.
1
;
recTab
[
7
].
height
=
(
SQUARE_SIZE
)
-
0
.
1
;
}
highscore
=
LoadStorageValue
(
0
);
...
...
@@ -502,3 +507,25 @@ void UpdateDrawFrame(void)
DrawGame
();
}
void
SelectScreen
(){
BeginDrawing
();
ClearBackground
(
RAYWHITE
);
DrawText
(
"SNAKE"
,
screenWidth
/
2
-
MeasureText
(
"SNAKE"
,
120
)
/
2
,
screenHeight
-
440
,
120
,
BLACK
);
DrawText
(
"1: EASY"
,
screenWidth
/
2
-
MeasureText
(
"1: EASY"
,
60
)
/
2
,
screenHeight
-
300
,
60
,
GREEN
);
DrawText
(
"2: HARD"
,
screenWidth
/
2
-
MeasureText
(
"2: HARD"
,
60
)
/
2
,
screenHeight
-
230
,
60
,
RED
);
DrawText
(
"PRESS 1 OR 2"
,
screenWidth
/
2
-
MeasureText
(
"PRESS 1 OR 2"
,
40
)
/
2
,
screenHeight
-
140
,
40
,
GRAY
);
DrawText
(
"TO SELECT YOUR LEVEL"
,
screenWidth
/
2
-
MeasureText
(
"TO SELECT YOUR LEVEL"
,
40
)
/
2
,
screenHeight
-
100
,
40
,
GRAY
);
if
(
IsKeyPressed
(
KEY_ONE
)
||
IsKeyPressed
(
KEY_KP_1
)){
//niveau facile
isReady
=
true
;
level
=
1
;
}
if
(
IsKeyPressed
(
KEY_TWO
)
||
IsKeyPressed
(
KEY_KP_2
)){
//niveau difficile
isReady
=
true
;
level
=
2
;
}
EndDrawing
();
}
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