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
faf99d87
Commit
faf99d87
authored
Oct 29, 2020
by
Lila NICKLER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
3 types d'Item, +1vie, +speed, +taille tire
parent
f3634285
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
19 deletions
+100
-19
space_invaders.c
space_invaders.c
+100
-19
No files found.
space_invaders.c
View file @
faf99d87
...
...
@@ -26,13 +26,13 @@
#define SECOND_WAVE 10
#define THIRD_WAVE 20
#define FOURTH_WAVE 20
#define ItemNumber
2
#define ItemNumber
3
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
typedef
enum
{
FIRST
=
0
,
SECOND
,
THIRD
,
FOURTH
}
EnemyWave
;
typedef
enum
{
Life
=
0
,
Speed
,
S
peedShot
,
S
izeShoot
}
ItemEffect
;
typedef
enum
{
Life
=
0
,
Speed
,
SizeShoot
}
ItemEffect
;
typedef
struct
Player
{
Rectangle
rec
;
...
...
@@ -55,6 +55,7 @@ typedef struct Shoot{
Vector2
speed
;
bool
active
;
Color
color
;
bool
bonus
;
}
Shoot
;
typedef
struct
Item
{
...
...
@@ -193,6 +194,7 @@ void InitGame(void)
shoot
[
i
].
speed
.
y
=
0
;
shoot
[
i
].
active
=
false
;
shoot
[
i
].
color
=
MAROON
;
shoot
[
i
].
bonus
=
false
;
}
// Initialize Item
...
...
@@ -204,9 +206,23 @@ void InitGame(void)
item
[
i
].
rec
.
height
=
20
;
item
[
i
].
speed
.
x
=
5
;
item
[
i
].
speed
.
y
=
5
;
item
[
i
].
effect
=
Life
;
item
[
i
].
color
=
GOLD
;
item
[
i
].
active
=
true
;
item
[
i
].
effect
=
i
;
switch
(
item
[
i
].
effect
)
{
case
0
:
item
[
i
].
color
=
RED
;
break
;
case
1
:
item
[
i
].
color
=
GOLD
;
break
;
case
2
:
item
[
i
].
color
=
PINK
;
break
;
default:
item
[
i
].
color
=
GRAY
;
break
;
}
item
[
i
].
active
=
false
;
}
...
...
@@ -225,11 +241,16 @@ void UpdateGame(void)
{
case
FIRST
:
{
item
[
0
].
active
=
true
;
if
(
!
smooth
)
{
alpha
+=
0
.
02
f
;
if
(
alpha
>=
1
.
0
f
)
smooth
=
true
;
for
(
int
i
=
0
;
i
<
ItemNumber
;
i
++
)
{
item
[
i
].
effect
=
GetRandomValue
(
0
,
2
);
}
}
if
(
smooth
)
alpha
-=
0
.
02
f
;
...
...
@@ -243,6 +264,10 @@ void UpdateGame(void)
if
(
!
enemy
[
i
].
active
)
enemy
[
i
].
active
=
true
;
}
for
(
int
i
=
0
;
i
<
ItemNumber
;
i
++
)
{
item
[
i
].
effect
=
GetRandomValue
(
0
,
2
);
}
activeEnemies
=
SECOND_WAVE
;
wave
=
SECOND
;
smooth
=
false
;
...
...
@@ -266,17 +291,21 @@ void UpdateGame(void)
for
(
int
i
=
0
;
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
;
enemy
[
i
].
active
=
true
;
enemy
[
i
].
rec
.
width
=
25
;
enemy
[
i
].
rec
.
height
=
25
;
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
<
ItemNumber
;
i
++
)
{
item
[
i
].
effect
=
GetRandomValue
(
0
,
2
);
}
activeEnemies
=
THIRD_WAVE
;
...
...
@@ -331,6 +360,11 @@ void UpdateGame(void)
if
(
!
enemy
[
i
].
active
)
enemy
[
i
].
active
=
true
;
}
for
(
int
i
=
0
;
i
<
ItemNumber
;
i
++
)
{
item
[
i
].
effect
=
GetRandomValue
(
0
,
2
);
}
activeEnemies
=
FOURTH_WAVE
;
wave
=
FOURTH
;
smooth
=
false
;
...
...
@@ -376,6 +410,44 @@ void UpdateGame(void)
}
}
}
// Player get item
for
(
int
i
=
0
;
i
<
ItemNumber
;
i
++
)
{
if
(
CheckCollisionRecs
(
player
.
rec
,
item
[
i
].
rec
))
{
item
[
i
].
active
=
false
;
if
(
i
==
ItemNumber
-
1
)
{
item
[
0
].
active
=
true
;
}
else
{
item
[
i
+
1
].
active
=
true
;
}
item
[
i
].
rec
.
x
=
GetRandomValue
(
screenWidth
,
screenWidth
+
1000
);
item
[
i
].
rec
.
y
=
GetRandomValue
(
0
,
screenHeight
-
item
[
i
].
rec
.
height
);
switch
(
item
[
i
].
effect
)
{
case
Life
:
player
.
life
++
;
break
;
case
Speed
:
player
.
speed
.
x
+=
2
;
player
.
speed
.
y
+=
2
;
break
;
case
SizeShoot
:
for
(
int
i
;
i
<
NUM_SHOOTS
;
i
++
)
{
shoot
[
i
].
bonus
=
true
;
}
break
;
default:
break
;
}
}
}
// Enemy behaviour
for
(
int
i
=
0
;
i
<
activeEnemies
;
i
++
)
...
...
@@ -411,9 +483,16 @@ void UpdateGame(void)
{
if
(
!
shoot
[
i
].
active
&&
shootRate
%
20
==
0
)
{
shoot
[
i
].
rec
.
x
=
player
.
rec
.
x
;
shoot
[
i
].
rec
.
y
=
player
.
rec
.
y
+
player
.
rec
.
height
/
4
;
shoot
[
i
].
active
=
true
;
if
(
shoot
[
i
].
bonus
)
{
shoot
[
i
].
rec
.
x
=
player
.
rec
.
x
+
2
;
shoot
[
i
].
rec
.
y
=
player
.
rec
.
y
+
player
.
rec
.
height
/
4
+
2
;
shoot
[
i
].
active
=
true
;
}
else
{
shoot
[
i
].
rec
.
x
=
player
.
rec
.
x
;
shoot
[
i
].
rec
.
y
=
player
.
rec
.
y
+
player
.
rec
.
height
/
4
;
shoot
[
i
].
active
=
true
;
}
break
;
}
}
...
...
@@ -467,6 +546,7 @@ void UpdateGame(void)
if
(
item
[
i
].
active
)
{
item
[
i
].
rec
.
x
-=
item
[
i
].
speed
.
x
;
item
[
i
].
effect
=
GetRandomValue
(
0
,
2
);
if
(
item
[
i
].
rec
.
x
<
0
)
{
...
...
@@ -522,6 +602,7 @@ void DrawGame(void)
if
(
item
[
i
].
active
)
DrawRectangleRec
(
item
[
i
].
rec
,
item
[
i
].
color
);
}
// Display of score and player life
DrawText
(
"Score:"
,
20
,
10
,
30
,
GRAY
);
DrawText
(
TextFormat
(
"%04i"
,
score
),
120
,
10
,
30
,
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