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
b793d23f
Commit
b793d23f
authored
Oct 31, 2020
by
Fan FEI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
version "0.1"
add notes
parent
36e2a683
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
+13
-13
snake_FanFEI.c
snake_FanFEI.c
+13
-13
No files found.
snake_FanFEI.c
View file @
b793d23f
...
@@ -43,8 +43,8 @@ typedef struct Food {
...
@@ -43,8 +43,8 @@ typedef struct Food {
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// Global Variables Declaration
// Global Variables Declaration
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
static
const
int
screenWidth
=
800
;
static
const
int
screenWidth
=
1500
;
//Set the width of the game interface
static
const
int
screenHeight
=
450
;
static
const
int
screenHeight
=
1500
;
//Set the Height of the game interface
static
int
framesCounter
=
0
;
static
int
framesCounter
=
0
;
static
bool
gameOver
=
false
;
static
bool
gameOver
=
false
;
...
@@ -73,9 +73,9 @@ int main(void)
...
@@ -73,9 +73,9 @@ int main(void)
{
{
// Initialization (Note windowTitle is unused on Android)
// Initialization (Note windowTitle is unused on Android)
//---------------------------------------------------------
//---------------------------------------------------------
InitWindow
(
screenWidth
,
screenHeight
,
"sample game: snake
"
);
InitWindow
(
screenWidth
,
screenHeight
,
"sample game: snake
By FanFEI"
);
//Initialize the interface and title
InitGame
();
InitGame
();
//Initialize the game
#if defined(PLATFORM_WEB)
#if defined(PLATFORM_WEB)
emscripten_set_main_loop
(
UpdateDrawFrame
,
60
,
1
);
emscripten_set_main_loop
(
UpdateDrawFrame
,
60
,
1
);
...
@@ -110,10 +110,10 @@ int main(void)
...
@@ -110,10 +110,10 @@ int main(void)
void
InitGame
(
void
)
void
InitGame
(
void
)
{
{
framesCounter
=
0
;
framesCounter
=
0
;
gameOver
=
false
;
gameOver
=
false
;
//Game state
pause
=
false
;
pause
=
false
;
counterTail
=
1
;
counterTail
=
2
;
//The initial length of the snake
allowMove
=
false
;
allowMove
=
false
;
offset
.
x
=
screenWidth
%
SQUARE_SIZE
;
offset
.
x
=
screenWidth
%
SQUARE_SIZE
;
...
@@ -125,8 +125,8 @@ void InitGame(void)
...
@@ -125,8 +125,8 @@ void InitGame(void)
snake
[
i
].
size
=
(
Vector2
){
SQUARE_SIZE
,
SQUARE_SIZE
};
snake
[
i
].
size
=
(
Vector2
){
SQUARE_SIZE
,
SQUARE_SIZE
};
snake
[
i
].
speed
=
(
Vector2
){
SQUARE_SIZE
,
0
};
snake
[
i
].
speed
=
(
Vector2
){
SQUARE_SIZE
,
0
};
if
(
i
==
0
)
snake
[
i
].
color
=
DARKBLUE
;
if
(
i
==
0
)
snake
[
i
].
color
=
DARKBLUE
;
//Snake head color
else
snake
[
i
].
color
=
BLUE
;
else
snake
[
i
].
color
=
BLUE
;
//Snake body color
}
}
for
(
int
i
=
0
;
i
<
SNAKE_LENGTH
;
i
++
)
for
(
int
i
=
0
;
i
<
SNAKE_LENGTH
;
i
++
)
...
@@ -134,7 +134,7 @@ void InitGame(void)
...
@@ -134,7 +134,7 @@ void InitGame(void)
snakePosition
[
i
]
=
(
Vector2
){
0
.
0
f
,
0
.
0
f
};
snakePosition
[
i
]
=
(
Vector2
){
0
.
0
f
,
0
.
0
f
};
}
}
fruit
.
size
=
(
Vector2
){
SQUARE_SIZE
,
SQUARE_SIZE
};
fruit
.
size
=
(
Vector2
){
SQUARE_SIZE
,
SQUARE_SIZE
};
//The color, coordinates and status of the props
fruit
.
color
=
SKYBLUE
;
fruit
.
color
=
SKYBLUE
;
fruit
.
active
=
false
;
fruit
.
active
=
false
;
}
}
...
@@ -144,7 +144,7 @@ void UpdateGame(void)
...
@@ -144,7 +144,7 @@ void UpdateGame(void)
{
{
if
(
!
gameOver
)
if
(
!
gameOver
)
{
{
if
(
IsKeyPressed
(
'P'
))
pause
=
!
pause
;
if
(
IsKeyPressed
(
'P'
))
pause
=
!
pause
;
//Keyboard input p pause
if
(
!
pause
)
if
(
!
pause
)
{
{
...
@@ -204,10 +204,10 @@ void UpdateGame(void)
...
@@ -204,10 +204,10 @@ void UpdateGame(void)
// Fruit position calculation
// Fruit position calculation
if
(
!
fruit
.
active
)
if
(
!
fruit
.
active
)
{
{
fruit
.
active
=
true
;
fruit
.
active
=
true
;
//Randomly generate a fruit on the map
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
};
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
};
for
(
int
i
=
0
;
i
<
counterTail
;
i
++
)
for
(
int
i
=
0
;
i
<
counterTail
;
i
++
)
//The position of the fruit will not overlap with the snake
{
{
while
((
fruit
.
position
.
x
==
snake
[
i
].
position
.
x
)
&&
(
fruit
.
position
.
y
==
snake
[
i
].
position
.
y
))
while
((
fruit
.
position
.
x
==
snake
[
i
].
position
.
x
)
&&
(
fruit
.
position
.
y
==
snake
[
i
].
position
.
y
))
{
{
...
@@ -231,7 +231,7 @@ void UpdateGame(void)
...
@@ -231,7 +231,7 @@ void UpdateGame(void)
}
}
else
else
{
{
if
(
IsKeyPressed
(
KEY_ENTER
))
if
(
IsKeyPressed
(
KEY_ENTER
))
//Press enter to start the game
{
{
InitGame
();
InitGame
();
gameOver
=
false
;
gameOver
=
false
;
...
...
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