Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SpaceInvaders_upgrade
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
Lila NICKLER
SpaceInvaders_upgrade
Commits
0efc18fc
Commit
0efc18fc
authored
Oct 27, 2020
by
Lila NICKLER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Affichage vie du joueur + meilleure affichage score + victoire si le boss est tué
parent
da176a20
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
24 deletions
+53
-24
space_invaders.c
space_invaders.c
+53
-24
No files found.
space_invaders.c
View file @
0efc18fc
...
...
@@ -25,7 +25,7 @@
#define FIRST_WAVE 10
#define SECOND_WAVE 10
#define THIRD_WAVE 20
#define FOURTH_WAVE
1
#define FOURTH_WAVE
20
//----------------------------------------------------------------------------------
// Types and Structures Definition
...
...
@@ -36,6 +36,7 @@ typedef struct Player{
Rectangle
rec
;
Vector2
speed
;
Color
color
;
int
life
;
}
Player
;
typedef
struct
Enemy
{
...
...
@@ -146,12 +147,13 @@ void InitGame(void)
// Initialize player
player
.
rec
.
x
=
20
;
player
.
rec
.
y
=
5
0
;
player
.
rec
.
y
=
10
0
;
player
.
rec
.
width
=
20
;
player
.
rec
.
height
=
20
;
player
.
speed
.
x
=
5
;
player
.
speed
.
y
=
5
;
player
.
color
=
BLACK
;
player
.
life
=
3
;
// Initialize enemies
for
(
int
i
=
0
;
i
<
NUM_MAX_ENEMIES
;
i
++
)
...
...
@@ -245,7 +247,7 @@ void UpdateGame(void)
enemy
[
i
].
speed
.
x
=
5
;
enemy
[
i
].
speed
.
y
=
5
;
enemy
[
i
].
active
=
true
;
enemy
[
i
].
color
=
BLACK
;
enemy
[
i
].
color
=
GRAY
;
enemy
[
i
].
boss
=
false
;
enemy
[
i
].
life
=
10
;
}
...
...
@@ -270,21 +272,32 @@ void UpdateGame(void)
if
(
enemiesKill
==
activeEnemies
)
{
enemiesKill
=
0
;
for
(
int
i
=
0
;
i
<
activeEnemies
;
i
++
)
{
//Initiliaze the boss
enemy
[
i
].
active
=
true
;
enemy
[
i
].
rec
.
width
=
200
;
enemy
[
i
].
rec
.
height
=
700
;
enemy
[
i
].
rec
.
x
=
screenWidth
;
enemy
[
i
].
rec
.
y
=
0
;
enemy
[
i
].
speed
.
x
=
1
;
enemy
[
i
].
speed
.
y
=
1
;
enemy
[
i
].
active
=
true
;
enemy
[
i
].
color
=
BLACK
;
enemy
[
i
].
boss
=
true
;
enemy
[
i
].
life
=
100
;
enemy
[
0
].
active
=
true
;
enemy
[
0
].
rec
.
width
=
200
;
enemy
[
0
].
rec
.
height
=
700
;
enemy
[
0
].
rec
.
x
=
screenWidth
;
enemy
[
0
].
rec
.
y
=
0
;
enemy
[
0
].
speed
.
x
=
1
;
enemy
[
0
].
speed
.
y
=
1
;
enemy
[
0
].
active
=
true
;
enemy
[
0
].
color
=
MAROON
;
enemy
[
0
].
boss
=
true
;
enemy
[
0
].
life
=
100
;
for
(
int
i
=
1
;
i
<
activeEnemies
;
i
++
)
{
enemy
[
i
].
active
=
true
;
enemy
[
i
].
rec
.
width
=
50
;
enemy
[
i
].
rec
.
height
=
50
;
enemy
[
i
].
rec
.
x
=
screenWidth
/
2
;
enemy
[
i
].
rec
.
y
=
200
;
enemy
[
i
].
speed
.
x
=
5
;
enemy
[
i
].
speed
.
y
=
5
;
enemy
[
i
].
active
=
true
;
enemy
[
i
].
color
=
GRAY
;
enemy
[
i
].
boss
=
false
;
enemy
[
i
].
life
=
10
;
}
for
(
int
i
=
0
;
i
<
activeEnemies
;
i
++
)
{
...
...
@@ -307,7 +320,7 @@ void UpdateGame(void)
}
if
(
smooth
)
alpha
-=
0
.
02
f
;
if
(
enem
iesKill
==
activeEnemies
)
victory
=
true
;
if
(
enem
y
[
0
].
life
==
0
)
victory
=
true
;
}
...
...
@@ -323,7 +336,16 @@ void UpdateGame(void)
// Player collision with enemy
for
(
int
i
=
0
;
i
<
activeEnemies
;
i
++
)
{
if
(
CheckCollisionRecs
(
player
.
rec
,
enemy
[
i
].
rec
))
gameOver
=
false
;
if
(
CheckCollisionRecs
(
player
.
rec
,
enemy
[
i
].
rec
))
{
if
(
player
.
life
==
1
)
{
gameOver
=
false
;
}
else
{
player
.
life
--
;
}
}
}
// Enemy behaviour
...
...
@@ -341,8 +363,6 @@ void UpdateGame(void)
enemy
[
i
].
rec
.
y
=
GetRandomValue
(
0
,
screenHeight
-
enemy
[
i
].
rec
.
height
);
}
}
}
}
...
...
@@ -437,19 +457,27 @@ void DrawGame(void)
if
(
wave
==
FIRST
)
DrawText
(
"FIRST WAVE"
,
screenWidth
/
2
-
MeasureText
(
"FIRST WAVE"
,
40
)
/
2
,
screenHeight
/
2
-
40
,
40
,
Fade
(
BLACK
,
alpha
));
else
if
(
wave
==
SECOND
)
DrawText
(
"SECOND WAVE"
,
screenWidth
/
2
-
MeasureText
(
"SECOND WAVE"
,
40
)
/
2
,
screenHeight
/
2
-
40
,
40
,
Fade
(
BLACK
,
alpha
));
else
if
(
wave
==
THIRD
)
DrawText
(
"THIRD WAVE"
,
screenWidth
/
2
-
MeasureText
(
"THIRD WAVE"
,
40
)
/
2
,
screenHeight
/
2
-
40
,
40
,
Fade
(
BLACK
,
alpha
));
else
if
(
wave
==
FOURTH
)
DrawText
(
"FOURTH WAVE"
,
screenWidth
/
2
-
MeasureText
(
"FOURTH WAVE"
,
40
)
/
2
,
screenHeight
/
2
-
40
,
40
,
Fade
(
BLACK
,
alpha
));
else
if
(
wave
==
FOURTH
)
{
DrawText
(
"FOURTH WAVE:"
,
screenWidth
/
2
-
MeasureText
(
"FOURTH WAVE"
,
40
)
/
2
,
screenHeight
/
2
-
40
,
40
,
Fade
(
BLACK
,
alpha
));
DrawText
(
"BOSS IN COMMING"
,
screenWidth
/
2
-
MeasureText
(
"BOSS IN COMMING"
,
40
)
/
2
,
2
*
screenHeight
/
3
-
40
,
40
,
Fade
(
MAROON
,
alpha
));
}
for
(
int
i
=
0
;
i
<
activeEnemies
;
i
++
)
{
if
(
enemy
[
i
].
active
)
DrawRectangleRec
(
enemy
[
i
].
rec
,
enemy
[
i
].
color
);
}
for
(
int
i
=
0
;
i
<
NUM_SHOOTS
;
i
++
)
{
if
(
shoot
[
i
].
active
)
DrawRectangleRec
(
shoot
[
i
].
rec
,
shoot
[
i
].
color
);
}
DrawText
(
TextFormat
(
"%04i"
,
score
),
20
,
20
,
40
,
GRAY
);
DrawText
(
"Score:"
,
20
,
10
,
30
,
GRAY
);
DrawText
(
TextFormat
(
"%04i"
,
score
),
120
,
10
,
30
,
GRAY
);
DrawText
(
"Life:"
,
20
,
40
,
30
,
GRAY
);
DrawText
(
TextFormat
(
"%i"
,
player
.
life
),
100
,
40
,
30
,
RED
);
if
(
victory
)
DrawText
(
"YOU WIN"
,
screenWidth
/
2
-
MeasureText
(
"YOU WIN"
,
40
)
/
2
,
screenHeight
/
2
-
40
,
40
,
BLACK
);
...
...
@@ -457,6 +485,7 @@ void DrawGame(void)
}
else
DrawText
(
"PRESS [ENTER] TO PLAY AGAIN"
,
GetScreenWidth
()
/
2
-
MeasureText
(
"PRESS [ENTER] TO PLAY AGAIN"
,
20
)
/
2
,
GetScreenHeight
()
/
2
-
50
,
20
,
GRAY
);
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