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
aaab82b0
Commit
aaab82b0
authored
Oct 31, 2020
by
Fan FEI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
version "3.1"
Add wormhole: snakes can cross the border
parent
1294c380
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
8 deletions
+17
-8
snake_FanFEI.c
snake_FanFEI.c
+17
-8
No files found.
snake_FanFEI.c
View file @
aaab82b0
...
@@ -33,7 +33,7 @@
...
@@ -33,7 +33,7 @@
// Some Defines
// Some Defines
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
#define SNAKE_LENGTH 256
#define SNAKE_LENGTH 256
#define SQUARE_SIZE 3
1
#define SQUARE_SIZE 3
9
Music
soundtrack
;
Music
soundtrack
;
...
@@ -196,7 +196,7 @@ void UpdateGame(void)
...
@@ -196,7 +196,7 @@ void UpdateGame(void)
// Snake movement
// Snake movement
for
(
int
i
=
0
;
i
<
counterTail
;
i
++
)
snakePosition
[
i
]
=
snake
[
i
].
position
;
for
(
int
i
=
0
;
i
<
counterTail
;
i
++
)
snakePosition
[
i
]
=
snake
[
i
].
position
;
if
((
framesCounter
%
5
)
==
0
)
if
((
framesCounter
%
5
)
==
0
)
// The snake advances by one step every five frames
{
{
for
(
int
i
=
0
;
i
<
counterTail
;
i
++
)
for
(
int
i
=
0
;
i
<
counterTail
;
i
++
)
{
{
...
@@ -211,17 +211,26 @@ void UpdateGame(void)
...
@@ -211,17 +211,26 @@ void UpdateGame(void)
}
}
// Wall behaviour
// Wall behaviour
if
(((
snake
[
0
].
position
.
x
)
>
(
screenWidth
-
offset
.
x
))
||
/*
((
snake
[
0
].
position
.
y
)
>
(
screenHeight
-
offset
.
y
))
||
if (((snake[0].position.y) > (screenHeight - offset.y)) || (snake[0].position.y < 0))
(
snake
[
0
].
position
.
x
<
0
)
||
(
snake
[
0
].
position
.
y
<
0
))
{
{
gameOver = true;
gameOver = true;
}
}
*/
if
((
snake
[
0
].
position
.
x
)
>
(
screenWidth
-
offset
.
x
))
snake
[
0
].
position
.
x
=
offset
.
x
/
2
;
if
((
snake
[
0
].
position
.
y
)
>
(
screenHeight
-
offset
.
y
))
snake
[
0
].
position
.
y
=
offset
.
y
/
2
;
if
((
snake
[
0
].
position
.
x
<
0
))
snake
[
0
].
position
.
x
+=
(
screenWidth
-
offset
.
x
);
if
((
snake
[
0
].
position
.
y
<
0
))
snake
[
0
].
position
.
y
+=
(
screenHeight
-
offset
.
y
);
// Collision with yourself
// Collision with yourself
for
(
int
i
=
1
;
i
<
counterTail
;
i
++
)
for
(
int
i
=
1
;
i
<
counterTail
;
i
++
)
{
{
if
((
snake
[
0
].
position
.
x
==
snake
[
i
].
position
.
x
)
&&
(
snake
[
0
].
position
.
y
==
snake
[
i
].
position
.
y
))
gameOver
=
true
;
if
((
snake
[
0
].
position
.
x
==
snake
[
i
].
position
.
x
)
&&
(
snake
[
0
].
position
.
y
==
snake
[
i
].
position
.
y
))
gameOver
=
true
;
}
}
// Fruit position calculation
// Fruit position calculation
...
@@ -290,8 +299,8 @@ void DrawGame(void)
...
@@ -290,8 +299,8 @@ void DrawGame(void)
DrawRectangleV
(
fruit
.
position
,
fruit
.
size
,
fruit
.
color
);
DrawRectangleV
(
fruit
.
position
,
fruit
.
size
,
fruit
.
color
);
// Show time and score
// Show time and score
DrawText
(
TextFormat
(
"TIME : %.1f s"
,
(
float
)
framesCounter
/
60
),
SQUARE_SIZE
,
SQUARE_SIZE
,
SQUARE_SIZE
,
DARKGRAY
);
DrawText
(
TextFormat
(
"TIME : %.1f s"
,
(
float
)
framesCounter
/
60
),
screenWidth
-
SQUARE_SIZE
*
8
,
SQUARE_SIZE
,
SQUARE_SIZE
,
DARKGRAY
);
DrawText
(
TextFormat
(
"SCORE: %03d"
,
counterTail
),
SQUARE_SIZE
,
SQUARE_SIZE
*
2
,
SQUARE_SIZE
,
DARKGRAY
);
DrawText
(
TextFormat
(
"SCORE: %03d"
,
counterTail
),
screenWidth
-
SQUARE_SIZE
*
8
,
SQUARE_SIZE
*
2
,
SQUARE_SIZE
,
DARKGRAY
);
// Show pause
// Show pause
if
(
pause
)
DrawText
(
"GAME PAUSED"
,
screenWidth
/
2
-
MeasureText
(
"GAME PAUSED"
,
40
)
/
2
,
screenHeight
/
2
-
40
,
40
,
GRAY
);
if
(
pause
)
DrawText
(
"GAME PAUSED"
,
screenWidth
/
2
-
MeasureText
(
"GAME PAUSED"
,
40
)
/
2
,
screenHeight
/
2
-
40
,
40
,
GRAY
);
...
...
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