Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
TP7projet_jeu_air_defense
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
MARQUE Pierre
TP7projet_jeu_air_defense
Commits
a0796251
Commit
a0796251
authored
Oct 31, 2020
by
Pierre MARQUE
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fini mais pas de son
parent
64ca4b53
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
288 additions
and
54 deletions
+288
-54
air_defense.c
air_defense.c
+262
-53
air_defense.exe
air_defense.exe
+0
-0
air_defense.h
air_defense.h
+26
-1
No files found.
air_defense.c
View file @
a0796251
...
...
@@ -29,13 +29,14 @@
//----------------------------------------------------------------------------------
// Some Defines
//--------------------------------------------------------------------------------
-
//--------------------------------------------------------------------------------
#define NUMBER_MAX_OF_PARATROOPERS 150
#define NUMBER_OF_AIRCRAFTS 10
#define NUMBER_MAX_OF_PARATROOPERS 100
#define NUMBER_MAX_OF_AIRCRAFTS 50
#define NUMBER_OF_BULLETS 25
#define NUMBER_OF_BOMBSHELLS 25
#define TROOPERS_PER_PLANE
5
#define TROOPERS_PER_PLANE
3
//------------------------------------------------------------------------------------
...
...
@@ -48,12 +49,15 @@ double shoot_rate;
static
bool
gameOver
=
false
;
static
bool
pause
=
false
;
static
int
score
=
0
;
int
score
=
0
;
int
life
=
5
;
int
NUMBER_OF_AIRCRAFTS
=
5
;
const
float
bulletSpeed
=
10
;
const
float
bombshellSpeed
=
6
;
float
hypothenuse1
;
float
hypothenuse2
;
int
framesCounter
=
0
;
double
shoot_rate
;
double
tempsAAC
;
...
...
@@ -64,12 +68,16 @@ AntiAircraftCanon antiAircraftCanon;
Paratrooper
paraInitial
;
Bombshell
bombshellInit
;
Bullet
bulletInit
;
Viewfinder
viewfinder
;
int
jalon
;
Aircraft
aircraft
[
NUMBER_OF_AIRCRAFTS
]
;
Aircraft
aircraft
[
NUMBER_
MAX_
OF_AIRCRAFTS
]
;
Bullet
bullet
[
NUMBER_OF_BULLETS
]
;
Bombshell
bombshells
[
NUMBER_OF_BOMBSHELLS
]
;
Paratrooper
paratrooper
[
NUMBER_MAX_OF_PARATROOPERS
]
;
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
...
...
@@ -116,70 +124,80 @@ int main(void)
void
InitGame
(
void
)
{
score
=
0
;
life
=
5
;
gameOver
=
false
;
pause
=
false
;
jalon
=
100
;
//Initialize paratroopers
for
(
int
k
=
0
;
k
<
NUMBER_MAX_OF_PARATROOPERS
;
k
++
){
for
(
int
k
=
0
;
k
<
NUMBER_MAX_OF_PARATROOPERS
;
k
++
)
{
paratrooper
[
k
]
=
InitializeParatrooper
();
}
//Initialize aircrafts
for
(
int
i
=
0
;
i
<
NUMBER_OF_AIRCRAFTS
;
i
++
)
for
(
int
i
=
0
;
i
<
NUMBER_
MAX_
OF_AIRCRAFTS
;
i
++
)
{
aircraft
[
i
]
=
InitializeAircraft
();
}
//Initialize bombshells and bullets
for
(
int
j
=
0
;
j
<
NUMBER_OF_BOMBSHELLS
;
j
++
){
for
(
int
j
=
0
;
j
<
NUMBER_OF_BOMBSHELLS
;
j
++
)
{
bombshells
[
j
]
=
InitializeBombshell
();
}
for
(
int
j
=
0
;
j
<
NUMBER_OF_BULLETS
;
j
++
){
for
(
int
j
=
0
;
j
<
NUMBER_OF_BULLETS
;
j
++
)
{
bullet
[
j
]
=
InitializeBullet
();
}
//Initialize canons
antiParaCanon
.
sin
=
0
.
;
antiParaCanon
.
cos
=
0
.;
anti
ParaCanon
.
position
.
x
=
screenWidth
/
4
;
antiParaCanon
.
position
.
y
=
screenHeight
;
antiParaCanon
.
aimingPosition
.
x
=
0
.;
antiParaCanon
.
aimingPosition
.
y
=
0
.
;
antiParaCanon
=
InitializeAntiParaCanon
()
;
anti
AircraftCanon
=
InitializeAntiAircraftCanon
()
;
//Initialize viewfinder
viewfinder
=
InitializeViewfinder
(
0
.)
;
antiAircraftCanon
.
sin
=
0
.;
antiAircraftCanon
.
cos
=
0
.;
antiAircraftCanon
.
position
.
x
=
screenWidth
*
(
0
.
75
);
antiAircraftCanon
.
position
.
y
=
screenHeight
;
antiAircraftCanon
.
aimingPosition
.
x
=
0
.;
antiAircraftCanon
.
aimingPosition
.
y
=
0
.;
}
void
UpdateGame
(
void
)
{
if
(
!
gameOver
)
{
if
(
IsKeyPressed
(
'P'
))
pause
=
!
pause
;
if
(
!
pause
)
{
//Moves
framesCounter
++
;
if
((
score
>
jalon
)
&&
(
NUMBER_OF_AIRCRAFTS
<
NUMBER_MAX_OF_AIRCRAFTS
)){
NUMBER_OF_AIRCRAFTS
+=
5
;
jalon
+=
1000
;
life
+=
5
;
}
//Moves
//Paratroopers
for
(
int
i
=
0
;
i
<
NUMBER_MAX_OF_PARATROOPERS
;
i
++
)
{
if
(
paratrooper
[
i
].
droped
)
{
paratrooper
[
i
].
hitbox
.
x
+=
paratrooper
[
i
].
speed
.
x
;
paratrooper
[
i
].
hitbox
.
y
+=
paratrooper
[
i
].
speed
.
y
;
paratrooper
[
i
]
=
MoveParatrooper
(
paratrooper
[
i
]);
}
if
(
IsRectangleOut
(
paratrooper
[
i
].
hitbox
))
{
paratrooper
[
i
]
=
InitializeParatrooper
();
life
--
;
gameOver
=
(
life
==
0
);
}
}
//Planes
for
(
int
j
=
0
;
j
<
NUMBER_OF_AIRCRAFTS
;
j
++
)
{
aircraft
[
j
].
hitbox
.
x
+=
aircraft
[
j
].
speed
.
x
;
aircraft
[
j
].
hitbox
.
y
+=
aircraft
[
j
].
speed
.
y
;
aircraft
[
j
]
=
MoveAircrafts
(
aircraft
[
j
]);
if
(
IsRectangleOut
(
aircraft
[
j
].
hitbox
))
{
if
(
aircraft
[
j
].
speed
.
x
>
0
&&
aircraft
[
j
].
hitbox
.
x
>
screenWidth
)
...
...
@@ -198,8 +216,7 @@ void UpdateGame(void)
{
if
(
bullet
[
k
].
ammoShot
)
{
bullet
[
k
].
position
.
x
+=
bullet
[
k
].
speed
.
x
;
bullet
[
k
].
position
.
y
+=
bullet
[
k
].
speed
.
y
;
bullet
[
k
]
=
MoveBullet
(
bullet
[
k
]);
}
if
(
IsCircleOut
(
bullet
[
k
].
position
,
bullet
[
k
].
radius
))
{
...
...
@@ -212,8 +229,7 @@ void UpdateGame(void)
{
if
(
bombshells
[
k
].
ammoShot
)
{
bombshells
[
k
].
position
.
x
+=
bombshells
[
k
].
speed
.
x
;
bombshells
[
k
].
position
.
y
+=
bombshells
[
k
].
speed
.
y
;
bombshells
[
k
]
=
MoveBombshell
(
bombshells
[
k
]);
}
if
(
IsCircleOut
(
bombshells
[
k
].
position
,
bombshells
[
k
].
radius
))
{
...
...
@@ -235,7 +251,7 @@ void UpdateGame(void)
//Shooting
//anti-aircrafts canon ((double) tempsAAC/CLOCKS_PER_SEC))<(shoot_rate)
if
(
IsMouseButtonPressed
(
MOUSE_
LEF
T_BUTTON
))
if
(
IsMouseButtonPressed
(
MOUSE_
RIGH
T_BUTTON
))
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_BOMBSHELLS
;
i
++
)
{
...
...
@@ -251,7 +267,7 @@ void UpdateGame(void)
}
}
// anti-Paratroopers canon
if
(
IsMouseButtonPressed
(
MOUSE_
RIGH
T_BUTTON
)
)
if
(
IsMouseButtonPressed
(
MOUSE_
LEF
T_BUTTON
)
)
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_BULLETS
;
i
++
)
{
...
...
@@ -276,13 +292,33 @@ void UpdateGame(void)
{
if
(
CheckCollisionCircleRec
(
bullet
[
j
].
position
,
bullet
[
j
].
radius
,
paratrooper
[
i
].
hitbox
))
{
bullet
[
j
].
ammoShot
=
false
;
DrawCircleLines
(
bullet
[
j
].
position
.
x
,
bullet
[
j
].
position
.
y
,
bullet
[
j
].
radius
+
20
,
WHITE
);
DrawCircleLines
(
bullet
[
j
].
position
.
x
+
4
,
bullet
[
j
].
position
.
y
,
10
,
YELLOW
);
DrawCircleLines
(
bullet
[
j
].
position
.
x
+
8
,
bullet
[
j
].
position
.
y
,
5
,
RED
);
paratrooper
[
i
].
life
--
;
Vector2
v
=
bullet
[
j
].
position
;
bullet
[
j
].
ammoShot
=
false
;
//Kill paras
if
(
paratrooper
[
i
].
life
==
0
)
{
paratrooper
[
i
]
=
InitializeParatrooper
();
}
//explosive ammo
for
(
int
s
=
0
;
s
<
NUMBER_MAX_OF_PARATROOPERS
;
s
++
)
{
if
(
paratrooper
[
s
].
droped
)
{
if
(
CheckCollisionCircleRec
(
v
,
bullet
[
j
].
radius
+
20
,
paratrooper
[
s
].
hitbox
))
{
paratrooper
[
s
].
life
--
;
//Kill paras
if
(
paratrooper
[
s
].
life
==
0
)
{
paratrooper
[
s
]
=
InitializeParatrooper
();
}
}
}
}
}
}
}
...
...
@@ -297,9 +333,17 @@ void UpdateGame(void)
if
(
CheckCollisionCircleRec
(
bombshells
[
j
].
position
,
bombshells
[
j
].
radius
,
aircraft
[
i
].
hitbox
))
{
bombshells
[
j
].
ammoShot
=
false
;
DrawCircle
(
bombshells
[
j
].
position
.
x
,
bombshells
[
j
].
position
.
y
,
15
,
RED
);
DrawCircle
(
bombshells
[
j
].
position
.
x
+
4
,
bombshells
[
j
].
position
.
y
,
10
,
YELLOW
);
aircraft
[
i
].
life
=
aircraft
[
i
].
life
-
1
;
//Kill aircrafts
if
(
aircraft
[
i
].
life
==
0
){
if
(
aircraft
[
i
].
life
==
0
)
{
score
+=
50
;
DrawCircle
(
aircraft
[
i
].
hitbox
.
x
,
aircraft
[
i
].
hitbox
.
y
,
15
,
WHITE
);
DrawCircle
(
aircraft
[
i
].
hitbox
.
x
+
4
,
aircraft
[
i
].
hitbox
.
y
,
10
,
YELLOW
);
DrawCircle
(
aircraft
[
i
].
hitbox
.
x
+
8
,
aircraft
[
i
].
hitbox
.
y
,
5
,
RED
);
aircraft
[
i
]
=
InitializeAircraft
();
}
}
...
...
@@ -311,11 +355,14 @@ void UpdateGame(void)
{
for
(
int
j
=
0
;
j
<
NUMBER_MAX_OF_PARATROOPERS
;
j
++
)
{
if
((
!
paratrooper
[
j
].
droped
)
&&
(
aircraft
[
i
].
hitbox
.
x
>
aircraft
[
i
].
xFirstToJump
+
5
0
)
&&
(
aircraft
[
i
].
numberOfParatroopers
>
-
1
))
if
((
!
paratrooper
[
j
].
droped
)
&&
(
aircraft
[
i
].
hitbox
.
x
>
aircraft
[
i
].
xFirstToJump
+
2
0
)
&&
(
aircraft
[
i
].
numberOfParatroopers
>
-
1
))
{
paratrooper
[
j
].
droped
=
true
;
paratrooper
[
j
].
whichWay
=
false
;
paratrooper
[
j
].
hitbox
.
x
=
aircraft
[
i
].
hitbox
.
x
;
paratrooper
[
j
].
hitbox
.
y
=
aircraft
[
i
].
hitbox
.
y
;
paratrooper
[
j
].
xDrop
=
aircraft
[
i
].
hitbox
.
x
;
paratrooper
[
j
].
yDrop
=
aircraft
[
i
].
hitbox
.
y
;
aircraft
[
i
].
numberOfParatroopers
--
;
aircraft
[
i
].
xFirstToJump
=
aircraft
[
i
].
hitbox
.
x
;
...
...
@@ -329,9 +376,12 @@ void UpdateGame(void)
{
for
(
int
j
=
0
;
j
<
NUMBER_MAX_OF_PARATROOPERS
;
j
++
)
{
if
((
!
paratrooper
[
j
].
droped
)
&&
(
aircraft
[
i
].
hitbox
.
x
<
aircraft
[
i
].
xFirstToJump
-
5
0
)
&&
(
aircraft
[
i
].
numberOfParatroopers
>
-
1
))
if
((
!
paratrooper
[
j
].
droped
)
&&
(
aircraft
[
i
].
hitbox
.
x
<
aircraft
[
i
].
xFirstToJump
-
2
0
)
&&
(
aircraft
[
i
].
numberOfParatroopers
>
-
1
))
{
paratrooper
[
j
].
droped
=
true
;
paratrooper
[
j
].
whichWay
=
true
;
paratrooper
[
j
].
xDrop
=
aircraft
[
i
].
hitbox
.
x
;
paratrooper
[
j
].
yDrop
=
aircraft
[
i
].
hitbox
.
y
;
paratrooper
[
j
].
hitbox
.
x
=
aircraft
[
i
].
hitbox
.
x
;
paratrooper
[
j
].
hitbox
.
y
=
aircraft
[
i
].
hitbox
.
y
;
aircraft
[
i
].
numberOfParatroopers
--
;
...
...
@@ -342,7 +392,14 @@ void UpdateGame(void)
}
}
}
}
}
else
{
if
(
IsKeyPressed
(
KEY_ENTER
))
{
InitGame
();
gameOver
=
false
;
}
}
}
...
...
@@ -351,7 +408,7 @@ void DrawGame(void)
{
BeginDrawing
();
ClearBackground
(
SKYBLUE
);
ClearBackground
(
BLACK
);
if
(
!
gameOver
)
{
...
...
@@ -359,6 +416,7 @@ void DrawGame(void)
for
(
int
i
=
0
;
i
<
NUMBER_OF_AIRCRAFTS
;
i
++
)
{
DrawRectangleRec
(
aircraft
[
i
].
hitbox
,
aircraft
[
i
].
color
);
}
//Draw paratroopers
for
(
int
i
=
0
;
i
<
NUMBER_MAX_OF_PARATROOPERS
;
i
++
)
...
...
@@ -366,14 +424,20 @@ void DrawGame(void)
if
(
paratrooper
[
i
].
droped
)
{
DrawRectangleRec
(
paratrooper
[
i
].
hitbox
,
paratrooper
[
i
].
color
);
if
(
framesCounter
%
32
<
16
)
{
DrawRectangleRec
(
paratrooper
[
i
].
hitbox
,
ORANGE
);;
}
}
//Draw drag
}
//Draw bullets
for
(
int
i
=
0
;
i
<
NUMBER_OF_BULLETS
;
i
++
)
{
if
(
bullet
[
i
].
ammoShot
)
{
DrawCircleV
(
bullet
[
i
].
position
,
bullet
[
i
].
radius
,
bullet
[
i
].
color
);
}
}
//Draw bombshells
...
...
@@ -381,12 +445,60 @@ void DrawGame(void)
{
if
(
bombshells
[
i
].
ammoShot
)
{
DrawCircleV
(
bombshells
[
i
].
position
,
bombshells
[
i
].
radius
,
bombshells
[
i
].
color
);
DrawCircleV
(
bombshells
[
i
].
position
,
bombshells
[
i
].
radius
-
10
,
bombshells
[
i
].
color
);
if
(
framesCounter
%
32
<
16
)
{
DrawText
(
"< >"
,
bombshells
[
i
].
position
.
x
-
4
,
bombshells
[
i
].
position
.
y
-
2
,
15
,
GREEN
);
}
}
}
if
(
pause
){
DrawText
(
"GAME PAUSED"
,
screenWidth
/
2
-
MeasureText
(
"GAME PAUSED"
,
40
)
/
2
,
screenHeight
/
2
-
40
,
40
,
GREEN
);}
}
else
{
DrawText
(
"Press ENTER to play again"
,
450
,
250
,
20
,
GREEN
);
}
//ATH
//Beware of paras
for
(
int
i
=
0
;
i
<
NUMBER_MAX_OF_PARATROOPERS
;
i
++
)
{
if
(
paratrooper
[
i
].
droped
)
{
if
(
paratrooper
[
i
].
hitbox
.
y
>
350
)
{
if
(
framesCounter
%
16
<
8
)
{
DrawText
(
"ALERT -- Invaders close to contact --"
,
0
,
500
,
20
,
GREEN
);
DrawText
(
">> <<"
,
paratrooper
[
i
].
hitbox
.
x
-
12
,
paratrooper
[
i
].
hitbox
.
y
-
4
,
20
,
GREEN
);
}
}
}
}
//Draw viewfinder
DrawCircleV
(
GetMousePosition
(),
5
,
RED
);
if
((
IsMouseButtonPressed
(
MOUSE_LEFT_BUTTON
))
||
(
IsMouseButtonPressed
(
MOUSE_RIGHT_BUTTON
)))
{
viewfinder
=
InitializeViewfinder
(
10
);
}
else
{
viewfinder
=
InitializeViewfinder
(
15
);
}
DrawRectangleRec
(
viewfinder
.
up
,
viewfinder
.
color
);
DrawRectangleRec
(
viewfinder
.
down
,
viewfinder
.
color
);
DrawRectangleRec
(
viewfinder
.
right
,
viewfinder
.
color
);
DrawRectangleRec
(
viewfinder
.
left
,
viewfinder
.
color
);
//Score
DrawText
(
"
\\
>>>|"
,
500
,
500
,
20
,
GREEN
);
DrawText
(
TextFormat
(
"%04i"
,
score
),
550
,
500
,
20
,
GREEN
);
DrawText
(
"|<<</"
,
600
,
500
,
20
,
GREEN
);
DrawText
(
TextFormat
(
"LIVES = %04i"
,
life
),
510
,
520
,
20
,
GREEN
);
EndDrawing
();
}
...
...
@@ -399,7 +511,7 @@ void DrawGame(void)
Aircraft
InitializeAircraft
(
void
)
{
Aircraft
aircraft
;
aircraft
.
life
=
2
;
aircraft
.
life
=
1
;
aircraft
.
hitbox
.
width
=
GetRandomValue
(
30
,
50
);
aircraft
.
hitbox
.
height
=
5
;
aircraft
.
numberOfParatroopers
=
GetRandomValue
(
0
,
TROOPERS_PER_PLANE
);
...
...
@@ -412,27 +524,52 @@ Aircraft InitializeAircraft(void)
aircraft
.
hitbox
.
width
=
50
;
}
aircraft
.
hitbox
.
y
=
GetRandomValue
(
0
+
aircraft
.
hitbox
.
height
,
screenHeight
/
2
);
aircraft
.
height
=
aircraft
.
hitbox
.
y
;
if
(
GetRandomValue
(
0
,
1
)
==
0
)
{
aircraft
.
hitbox
.
x
=
-
GetRandomValue
(
0
,
300
);
aircraft
.
speed
.
x
=
0
.
5
+
0
.
5
*
((
float
)
GetRandomValue
(
0
,
1
));
aircraft
.
xFirstToJump
=
GetRandomValue
(
10
,
screenWidth
/
2
);
aircraft
.
xFirstToJump
=
GetRandomValue
(
10
0
,
screenWidth
/
2
);
}
else
{
aircraft
.
speed
.
x
=
-
(
0
.
5
+
0
.
5
*
((
float
)
GetRandomValue
(
0
,
1
)));
aircraft
.
hitbox
.
x
=
GetRandomValue
(
screenWidth
,
screenWidth
+
300
);
aircraft
.
xFirstToJump
=
GetRandomValue
(
screenWidth
/
2
,
screenWidth
-
10
);
aircraft
.
xFirstToJump
=
GetRandomValue
(
screenWidth
/
2
,
screenWidth
-
10
0
);
}
aircraft
.
speed
.
y
=
0
;
aircraft
.
color
=
GRAY
;
return
aircraft
;
}
AntiAircraftCanon
InitializeAntiAircraftCanon
(
void
)
{
AntiAircraftCanon
antiAircraftCanon
;
antiAircraftCanon
.
sin
=
0
.;
antiAircraftCanon
.
cos
=
0
.;
antiAircraftCanon
.
position
.
x
=
screenWidth
*
(
0
.
75
);
antiAircraftCanon
.
position
.
y
=
screenHeight
;
antiAircraftCanon
.
aimingPosition
.
x
=
0
.;
antiAircraftCanon
.
aimingPosition
.
y
=
0
.;
return
antiAircraftCanon
;
}
AntiParaCanon
InitializeAntiParaCanon
(
void
)
{
AntiParaCanon
antiParaCanon
;
antiParaCanon
.
sin
=
0
.;
antiParaCanon
.
cos
=
0
.;
antiParaCanon
.
position
.
x
=
screenWidth
/
4
;
antiParaCanon
.
position
.
y
=
screenHeight
;
antiParaCanon
.
aimingPosition
.
x
=
0
.;
antiParaCanon
.
aimingPosition
.
y
=
0
.;
return
antiParaCanon
;
}
Bombshell
InitializeBombshell
(
void
)
{
Bombshell
bombshellInit
;
bombshellInit
.
radius
=
7
;
bombshellInit
.
radius
=
15
;
bombshellInit
.
sin
=
0
;
bombshellInit
.
cos
=
0
;
bombshellInit
.
ammoShot
=
false
;
...
...
@@ -440,7 +577,7 @@ Bombshell InitializeBombshell(void)
bombshellInit
.
position
.
y
=
0
;
bombshellInit
.
speed
.
x
=
0
;
bombshellInit
.
speed
.
y
=
0
;
bombshellInit
.
color
=
RED
;
bombshellInit
.
color
=
DARKPURPLE
;
return
bombshellInit
;
}
...
...
@@ -462,16 +599,52 @@ Bullet InitializeBullet(void)
Paratrooper
InitializeParatrooper
(
void
)
{
Paratrooper
paraInitial
;
paraInitial
.
speed
.
y
=
0
.
7
;
paraInitial
.
hitbox
.
x
=
0
;
paraInitial
.
hitbox
.
y
=
0
;
paraInitial
.
xDrop
=
0
.;
paraInitial
.
yDrop
=
0
.;
paraInitial
.
speed
.
y
=
0
.
3
;
paraInitial
.
speed
.
x
=
0
;
paraInitial
.
color
=
RED
;
paraInitial
.
life
=
2
;
paraInitial
.
life
=
1
;
paraInitial
.
hitbox
.
width
=
10
;
paraInitial
.
hitbox
.
height
=
10
;
paraInitial
.
droped
=
false
;
paraInitial
.
whichWay
=
true
;
return
paraInitial
;
}
Viewfinder
InitializeViewfinder
(
float
decalage
)
{
Viewfinder
v
;
v
.
color
=
GREEN
;
float
d1
=
13
;
float
d2
=
2
;
v
.
center
=
GetMousePosition
();
v
.
up
.
width
=
d2
;
v
.
up
.
height
=
d1
;
v
.
up
.
y
=
v
.
center
.
y
+
decalage
-
d1
/
2
;
v
.
up
.
x
=
v
.
center
.
x
-
d2
/
2
;
v
.
down
.
width
=
d2
;
v
.
down
.
height
=
d1
;
v
.
down
.
y
=
v
.
center
.
y
-
decalage
-
d1
/
2
;
v
.
down
.
x
=
v
.
center
.
x
-
d2
/
2
;
v
.
right
.
width
=
d1
;
v
.
right
.
height
=
d2
;
v
.
right
.
x
=
v
.
center
.
x
+
decalage
-
d1
/
2
;
v
.
right
.
y
=
v
.
center
.
y
-
d2
/
2
;
v
.
left
.
width
=
d1
;
v
.
left
.
height
=
d2
;
v
.
left
.
x
=
v
.
center
.
x
-
decalage
-
d1
/
2
;
v
.
left
.
y
=
v
.
center
.
y
-
d2
/
2
;
return
v
;
}
//Game Functions-------------------------------------------------------------------------
bool
IsRectangleOut
(
Rectangle
rec
)
{
...
...
@@ -498,3 +671,39 @@ bool IsCircleOut(Vector2 center, float radius)
}
return
false
;
}
Aircraft
MoveAircrafts
(
Aircraft
aircraft
)
{
aircraft
.
hitbox
.
x
+=
aircraft
.
speed
.
x
;
aircraft
.
hitbox
.
y
=
aircraft
.
height
+
10
*
cos
(
0
.
01
*
aircraft
.
hitbox
.
x
);
return
aircraft
;
}
Bullet
MoveBullet
(
Bullet
bullet
)
{
bullet
.
position
.
x
+=
bullet
.
speed
.
x
;
bullet
.
position
.
y
+=
bullet
.
speed
.
y
;
return
bullet
;
}
Bombshell
MoveBombshell
(
Bombshell
bombshell
)
{
bombshell
.
position
.
x
+=
bombshell
.
speed
.
x
;
bombshell
.
position
.
y
+=
bombshell
.
speed
.
y
;
return
bombshell
;
}
Paratrooper
MoveParatrooper
(
Paratrooper
paratrooper
)
{
paratrooper
.
hitbox
.
y
+=
paratrooper
.
speed
.
y
;
if
(
paratrooper
.
whichWay
)
{
paratrooper
.
hitbox
.
x
=
100
*
(
1
-
exp
(
-
(
paratrooper
.
hitbox
.
y
-
paratrooper
.
yDrop
)
/
5
))
+
paratrooper
.
xDrop
;
}
else
{
paratrooper
.
hitbox
.
x
=
-
100
*
(
1
-
exp
(
-
(
paratrooper
.
hitbox
.
y
-
paratrooper
.
yDrop
)
/
5
))
+
paratrooper
.
xDrop
;
}
return
paratrooper
;
}
air_defense.exe
View file @
a0796251
No preview for this file type
air_defense.h
View file @
a0796251
...
...
@@ -6,15 +6,20 @@
typedef
struct
Paratrooper
{
int
life
;
float
xDrop
;
float
yDrop
;
bool
droped
;
bool
whichWay
;
Rectangle
hitbox
;
Vector2
speed
;
Color
color
;
// yellow or red
Rectangle
drag
[
10
];
}
Paratrooper
;
typedef
struct
Aircraft
{
int
life
;
float
height
;
float
xFirstToJump
;
int
numberOfParatroopers
;
Rectangle
hitbox
;
...
...
@@ -61,12 +66,24 @@ typedef struct AntiParaCanon
Vector2
aimingPosition
;
}
AntiParaCanon
;
typedef
struct
Viewfinder
{
Rectangle
up
;
Rectangle
down
;
Rectangle
left
;
Rectangle
right
;
float
radius
;
Vector2
center
;
Color
color
;
}
Viewfinder
;
//------------------------------------------------------------------------------------
// Module Functions Declaration
//------------------------------------------------------------------------------------
static
void
InitGame
(
void
);
// Initialize game
static
void
UpdateGame
();
// Update game (one frame)
static
void
UpdateGame
(
void
);
// Update game (one frame)
static
void
DrawGame
(
void
);
// Draw game (one frame)
static
void
UnloadGame
(
void
);
// Unload game
...
...
@@ -76,11 +93,19 @@ static void UnloadGame(void); // Unload game
//Initialization functions------------------------------------------------------------
Aircraft
InitializeAircraft
(
void
);
AntiAircraftCanon
InitializeAntiAircraftCanon
(
void
);
AntiParaCanon
InitializeAntiParaCanon
(
void
);
Bombshell
InitializeBombshell
(
void
);
Bullet
InitializeBullet
(
void
);
Paratrooper
InitializeParatrooper
(
void
);
Viewfinder
InitializeViewfinder
(
float
decalage
);
//Game functions----------------------------------------------------------------------
bool
IsRectangleOut
(
Rectangle
rec
);
bool
IsCircleOut
(
Vector2
center
,
float
radius
);
Aircraft
MoveAircrafts
(
Aircraft
aircraft
);
Bombshell
MoveBombshell
(
Bombshell
bombshell
);
Bullet
MoveBullet
(
Bullet
bullet
);
Paratrooper
MoveParatrooper
(
Paratrooper
paratrooper
);
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