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
391cbfe6
Commit
391cbfe6
authored
Oct 26, 2020
by
Lila NICKLER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout d'une 4eme vague d'enemies + declaration du boss
parent
d8727672
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
4 deletions
+51
-4
space_invaders.c
space_invaders.c
+51
-4
No files found.
space_invaders.c
View file @
391cbfe6
...
...
@@ -25,11 +25,12 @@
#define FIRST_WAVE 10
#define SECOND_WAVE 20
#define THIRD_WAVE 50
#define FOURTH_WAVE 100
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
typedef
enum
{
FIRST
=
0
,
SECOND
,
THIRD
}
EnemyWave
;
typedef
enum
{
FIRST
=
0
,
SECOND
,
THIRD
,
FOURTH
}
EnemyWave
;
typedef
struct
Player
{
Rectangle
rec
;
...
...
@@ -51,6 +52,14 @@ typedef struct Shoot{
Color
color
;
}
Shoot
;
typedef
struct
Boss
{
Rectangle
rec
;
Vector2
speed
;
bool
active
;
Color
color
;
}
Boss
;
//------------------------------------------------------------------------------------
// Global Variables Declaration
//------------------------------------------------------------------------------------
...
...
@@ -66,6 +75,8 @@ static Player player = { 0 };
static
Enemy
enemy
[
NUM_MAX_ENEMIES
]
=
{
0
};
static
Shoot
shoot
[
NUM_SHOOTS
]
=
{
0
};
static
EnemyWave
wave
=
{
0
};
static
Boss
boss
=
{
0
};
static
int
shootRate
=
0
;
static
float
alpha
=
0
.
0
f
;
...
...
@@ -160,6 +171,15 @@ void InitGame(void)
enemy
[
i
].
color
=
GRAY
;
}
//Initialize boss
boss
.
rec
.
x
=
50
;
boss
.
rec
.
y
=
50
;
boss
.
rec
.
width
=
20
;
boss
.
rec
.
height
=
20
;
boss
.
speed
.
x
=
2
;
boss
.
speed
.
y
=
2
;
boss
.
color
=
GRAY
;
// Initialize shoots
for
(
int
i
=
0
;
i
<
NUM_SHOOTS
;
i
++
)
{
...
...
@@ -167,7 +187,7 @@ void InitGame(void)
shoot
[
i
].
rec
.
y
=
player
.
rec
.
y
+
player
.
rec
.
height
/
4
;
shoot
[
i
].
rec
.
width
=
10
;
shoot
[
i
].
rec
.
height
=
5
;
shoot
[
i
].
speed
.
x
=
7
;
shoot
[
i
].
speed
.
x
=
10
;
shoot
[
i
].
speed
.
y
=
0
;
shoot
[
i
].
active
=
false
;
shoot
[
i
].
color
=
MAROON
;
...
...
@@ -248,9 +268,35 @@ void UpdateGame(void)
if
(
smooth
)
alpha
-=
0
.
02
f
;
if
(
enemiesKill
==
activeEnemies
)
victory
=
true
;
if
(
enemiesKill
==
activeEnemies
)
{
enemiesKill
=
0
;
for
(
int
i
=
0
;
i
<
activeEnemies
;
i
++
)
{
if
(
!
enemy
[
i
].
active
)
enemy
[
i
].
active
=
true
;
}
activeEnemies
=
FOURTH_WAVE
;
wave
=
FOURTH
;
smooth
=
false
;
alpha
=
0
.
0
f
;
}
}
break
;
case
FOURTH
:
{
if
(
!
smooth
)
{
alpha
+=
0
.
02
f
;
if
(
alpha
>=
1
.
0
f
)
smooth
=
true
;
}
if
(
smooth
)
alpha
-=
0
.
02
f
;
if
(
enemiesKill
==
activeEnemies
)
victory
=
true
;
}
default:
break
;
}
...
...
@@ -263,7 +309,7 @@ void UpdateGame(void)
// Player collision with enemy
for
(
int
i
=
0
;
i
<
activeEnemies
;
i
++
)
{
if
(
CheckCollisionRecs
(
player
.
rec
,
enemy
[
i
].
rec
))
gameOver
=
tru
e
;
if
(
CheckCollisionRecs
(
player
.
rec
,
enemy
[
i
].
rec
))
gameOver
=
fals
e
;
}
// Enemy behaviour
...
...
@@ -362,6 +408,7 @@ 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
));
for
(
int
i
=
0
;
i
<
activeEnemies
;
i
++
)
{
...
...
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