Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
FanFEI_Jeu
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
Fan FEI
FanFEI_Jeu
Commits
b3a5282b
Commit
b3a5282b
authored
Oct 31, 2020
by
Fan FEI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Version "2.0"
add soundtrack
parent
67c5b302
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
snake_FanFEI.c
snake_FanFEI.c
+22
-6
No files found.
snake_FanFEI.c
View file @
b3a5282b
...
...
@@ -13,14 +13,19 @@
* Expanded on this basis by Fan FEI
*
*
*
*
*
*
********************************************************************************************/
#include "raylib.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <errno.h>
#include <string.h>
#include <stdbool.h>
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
#endif
...
...
@@ -31,6 +36,8 @@
#define SNAKE_LENGTH 256
#define SQUARE_SIZE 31
Music
soundtrack
;
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
...
...
@@ -83,6 +90,11 @@ int main(void)
//---------------------------------------------------------
InitWindow
(
screenWidth
,
screenHeight
,
"sample game: snake By FanFEI"
);
// Initialize the interface and title
InitAudioDevice
();
char
*
music
=
"Music_snake_FanFEI.mp3"
;
soundtrack
=
LoadMusicStream
(
music
);
PlayMusicStream
(
soundtrack
);
InitGame
();
//Initialize the game
#if defined(PLATFORM_WEB)
...
...
@@ -97,6 +109,7 @@ int main(void)
// Update and Draw
//----------------------------------------------------------------------------------
UpdateDrawFrame
();
UpdateMusicStream
(
soundtrack
);
//----------------------------------------------------------------------------------
}
#endif
...
...
@@ -117,6 +130,7 @@ int main(void)
// Initialize game variables
void
InitGame
(
void
)
{
framesCounter
=
0
;
gameOver
=
false
;
// Game state
pause
=
false
;
...
...
@@ -183,7 +197,7 @@ void UpdateGame(void)
// Snake movement
for
(
int
i
=
0
;
i
<
counterTail
;
i
++
)
snakePosition
[
i
]
=
snake
[
i
].
position
;
if
((
framesCounter
%
10
)
==
0
)
if
((
framesCounter
%
5
)
==
0
)
{
for
(
int
i
=
0
;
i
<
counterTail
;
i
++
)
{
...
...
@@ -222,7 +236,6 @@ void UpdateGame(void)
while
((
fruit
.
position
.
x
==
snake
[
i
].
position
.
x
)
&&
(
fruit
.
position
.
y
==
snake
[
i
].
position
.
y
))
{
fruit
.
position
=
(
Vector2
){
GetRandomValue
(
0
,
(
screenWidth
/
SQUARE_SIZE
)
-
1
)
*
SQUARE_SIZE
+
offset
.
x
/
2
,
GetRandomValue
(
0
,
(
screenHeight
/
SQUARE_SIZE
)
-
1
)
*
SQUARE_SIZE
+
offset
.
y
/
2
};
i
=
0
;
}
}
}
...
...
@@ -241,10 +254,12 @@ void UpdateGame(void)
}
else
{
StopMusicStream
(
soundtrack
);
if
(
IsKeyPressed
(
KEY_ENTER
))
//Press enter to start the game
{
InitGame
();
gameOver
=
false
;
PlayMusicStream
(
soundtrack
);
}
}
}
...
...
@@ -285,6 +300,7 @@ void DrawGame(void)
// Unload game variables
void
UnloadGame
(
void
)
{
UnloadMusicStream
(
soundtrack
);
// TODO: Unload all dynamic loaded data (textures, sounds, models...)
}
...
...
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