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
d7f7fb2e
Commit
d7f7fb2e
authored
Oct 27, 2020
by
Lila NICKLER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout d'ennemies de differentes taille avec des niveau de vie
parent
391cbfe6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
33 deletions
+62
-33
space_invaders.c
space_invaders.c
+62
-33
No files found.
space_invaders.c
View file @
d7f7fb2e
...
...
@@ -23,9 +23,9 @@
#define NUM_SHOOTS 50
#define NUM_MAX_ENEMIES 50
#define FIRST_WAVE 10
#define SECOND_WAVE
2
0
#define THIRD_WAVE
5
0
#define FOURTH_WAVE 1
00
#define SECOND_WAVE
1
0
#define THIRD_WAVE
2
0
#define FOURTH_WAVE 1
//----------------------------------------------------------------------------------
// Types and Structures Definition
...
...
@@ -43,6 +43,8 @@ typedef struct Enemy{
Vector2
speed
;
bool
active
;
Color
color
;
bool
boss
;
int
life
;
}
Enemy
;
typedef
struct
Shoot
{
...
...
@@ -52,12 +54,6 @@ typedef struct Shoot{
Color
color
;
}
Shoot
;
typedef
struct
Boss
{
Rectangle
rec
;
Vector2
speed
;
bool
active
;
Color
color
;
}
Boss
;
//------------------------------------------------------------------------------------
...
...
@@ -75,7 +71,6 @@ 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
;
...
...
@@ -169,17 +164,11 @@ void InitGame(void)
enemy
[
i
].
speed
.
y
=
5
;
enemy
[
i
].
active
=
true
;
enemy
[
i
].
color
=
GRAY
;
enemy
[
i
].
boss
=
false
;
enemy
[
i
].
life
=
0
;
}
//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
++
)
{
...
...
@@ -246,9 +235,19 @@ void UpdateGame(void)
{
enemiesKill
=
0
;
for
(
int
i
=
0
;
i
<
activeEnemies
;
i
++
)
for
(
int
i
=
0
;
i
<
activeEnemies
;
i
++
)
{
if
(
!
enemy
[
i
].
active
)
enemy
[
i
].
active
=
true
;
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
=
BLACK
;
enemy
[
i
].
boss
=
false
;
enemy
[
i
].
life
=
10
;
}
activeEnemies
=
THIRD_WAVE
;
...
...
@@ -272,6 +271,21 @@ void UpdateGame(void)
{
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
=
400
;
enemy
[
i
].
rec
.
x
=
screenWidth
;
enemy
[
i
].
rec
.
y
=
screenHeight
/
2
;
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
;
}
for
(
int
i
=
0
;
i
<
activeEnemies
;
i
++
)
{
if
(
!
enemy
[
i
].
active
)
enemy
[
i
].
active
=
true
;
...
...
@@ -286,13 +300,13 @@ void UpdateGame(void)
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
;
}
...
...
@@ -321,8 +335,14 @@ void UpdateGame(void)
if
(
enemy
[
i
].
rec
.
x
<
0
)
{
enemy
[
i
].
rec
.
x
=
GetRandomValue
(
screenWidth
,
screenWidth
+
1000
);
enemy
[
i
].
rec
.
y
=
GetRandomValue
(
0
,
screenHeight
-
enemy
[
i
].
rec
.
height
);
if
(
!
enemy
[
i
].
boss
){
enemy
[
i
].
rec
.
x
=
GetRandomValue
(
screenWidth
,
screenWidth
+
1000
);
enemy
[
i
].
rec
.
y
=
GetRandomValue
(
0
,
screenHeight
-
enemy
[
i
].
rec
.
height
);
}
}
}
}
...
...
@@ -355,6 +375,7 @@ void UpdateGame(void)
{
if
(
shoot
[
i
].
active
)
{
// Movement
shoot
[
i
].
rec
.
x
+=
shoot
[
i
].
speed
.
x
;
...
...
@@ -363,14 +384,22 @@ void UpdateGame(void)
{
if
(
enemy
[
j
].
active
)
{
if
(
CheckCollisionRecs
(
shoot
[
i
].
rec
,
enemy
[
j
].
rec
))
{
shoot
[
i
].
active
=
false
;
enemy
[
j
].
rec
.
x
=
GetRandomValue
(
screenWidth
,
screenWidth
+
1000
);
enemy
[
j
].
rec
.
y
=
GetRandomValue
(
0
,
screenHeight
-
enemy
[
j
].
rec
.
height
);
shootRate
=
0
;
enemiesKill
++
;
score
+=
100
;
if
(
CheckCollisionRecs
(
shoot
[
i
].
rec
,
enemy
[
j
].
rec
)){
if
(
enemy
[
j
].
life
==
0
)
{
shoot
[
i
].
active
=
false
;
enemy
[
j
].
rec
.
x
=
GetRandomValue
(
screenWidth
,
screenWidth
+
1000
);
enemy
[
j
].
rec
.
y
=
GetRandomValue
(
0
,
screenHeight
-
enemy
[
j
].
rec
.
height
);
shootRate
=
0
;
enemiesKill
++
;
score
+=
100
;
}
else
{
shoot
[
i
].
active
=
false
;
shootRate
=
0
;
enemy
[
j
].
life
--
;
score
+=
100
;
}
}
if
(
shoot
[
i
].
rec
.
x
+
shoot
[
i
].
rec
.
width
>=
screenWidth
)
...
...
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