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
e1ba205b
Commit
e1ba205b
authored
Oct 30, 2020
by
Pierre MARQUE
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tout fonctionne :reste réglages de difficultés et d'apparence
parent
99b6ce2a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
336 additions
and
114 deletions
+336
-114
air_defense.c
air_defense.c
+322
-108
air_defense.exe
air_defense.exe
+0
-0
air_defense.h
air_defense.h
+14
-6
No files found.
air_defense.c
View file @
e1ba205b
...
...
@@ -16,7 +16,7 @@
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2013-2020 Ramon Santamaria (@raysan5
)
* Copyright (c) 2013-2020 Ramon Santamaria (@raysan5
*
********************************************************************************************/
#include "raylib.h"
...
...
@@ -32,10 +32,10 @@
//---------------------------------------------------------------------------------
#define NUMBER_MAX_OF_PARATROOPERS 150
#define NUMBER_OF_AIRCRAFTS
5
0
#define NUMBER_OF_BULLETS
50
#define NUMBER_OF_BOMBSHELLS
50
#define TROOPERS_PER_PLANE
1
5
#define NUMBER_OF_AIRCRAFTS
1
0
#define NUMBER_OF_BULLETS
25
#define NUMBER_OF_BOMBSHELLS
25
#define TROOPERS_PER_PLANE 5
//------------------------------------------------------------------------------------
...
...
@@ -44,13 +44,20 @@
const
int
screenWidth
=
1200
;
const
int
screenHeight
=
550
;
double
shoot_rate
;
static
bool
gameOver
=
false
;
static
bool
pause
=
false
;
static
int
score
=
0
;
const
float
bulletSpeed
=
10
.;
const
float
bombshellSpeed
=
7
.
5
;
const
float
bulletSpeed
=
10
;
const
float
bombshellSpeed
=
6
;
float
hypothenuse1
;
float
hypothenuse2
;
double
shoot_rate
;
double
tempsAAC
;
double
tempsAPC
;
AntiParaCanon
antiParaCanon
;
AntiAircraftCanon
antiAircraftCanon
;
...
...
@@ -58,10 +65,10 @@ Paratrooper paraInitial;
Bombshell
bombshellInit
;
Bullet
bulletInit
;
Aircraft
aircraft
[
NUMBER_OF_AIRCRAFTS
];
Bullet
bullet
[
NUMBER_OF_BULLETS
];
Bombshell
bombshells
[
NUMBER_OF_BOMBSHELLS
];
Paratrooper
paratrooper
[
NUMBER_MAX_OF_PARATROOPERS
];
Aircraft
aircraft
[
NUMBER_OF_AIRCRAFTS
]
;
Bullet
bullet
[
NUMBER_OF_BULLETS
]
;
Bombshell
bombshells
[
NUMBER_OF_BOMBSHELLS
]
;
Paratrooper
paratrooper
[
NUMBER_MAX_OF_PARATROOPERS
]
;
//------------------------------------------------------------------------------------
// Program main entry point
...
...
@@ -73,32 +80,26 @@ int main(void)
//--------------------------------------------------------------------------------------
InitWindow
(
screenWidth
,
screenHeight
,
"raylib [core] example - basic window"
);
InitWindow
(
screenWidth
,
screenHeight
,
"Air defense"
);
InitGame
();
SetTargetFPS
(
60
);
// Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while
(
!
WindowShouldClose
())
// Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
// void
UpdateGame();
UpdateGame
();
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing
();
ClearBackground
(
SKYBLUE
);
DrawText
(
"Congrats! You created your first window!"
,
190
,
200
,
20
,
SKYBLUE
);
EndDrawing
();
DrawGame
();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
//UnloadGame();
...
...
@@ -108,99 +109,51 @@ int main(void)
return
0
;
}
void
InitGame
(
void
){
//-----------------------------------------------------------------------------------------
// Module Functions Definition
//-----------------------------------------------------------------------------------------
void
InitGame
(
void
)
{
//Initialize paratroopers
paraInitial
.
speed
.
y
=
-
2
;
paraInitial
.
speed
.
x
=
0
;
paraInitial
.
color
=
RED
;
paraInitial
.
life
=
2
;
paraInitial
.
hitbox
.
width
=
10
;
paraInitial
.
hitbox
.
height
=
10
;
paraInitial
.
droped
=
false
;
for
(
int
k
=
0
;
k
<
NUMBER_MAX_OF_PARATROOPERS
;
k
++
){
paratrooper
[
k
]
=
paraInitial
;
paratrooper
[
k
]
=
InitializeParatrooper
()
;
}
//Initialize aircrafts
for
(
int
i
=
0
;
i
<
NUMBER_OF_AIRCRAFTS
;
i
++
)
{
aircraft
[
i
].
hitbox
.
width
=
10
;
aircraft
[
i
].
hitbox
.
height
=
GetRandomValue
(
30
,
50
);
aircraft
[
i
].
numberOfParatroopers
=
GetRandomValue
(
0
,
TROOPERS_PER_PLANE
);
if
(
aircraft
[
i
].
hitbox
.
height
<
41
)
{
aircraft
[
i
].
hitbox
.
height
=
30
;
}
else
{
aircraft
[
i
].
hitbox
.
height
=
50
;
}
aircraft
[
i
].
hitbox
.
y
=
GetRandomValue
(
screenHeight
/
3
,
screenHeight
-
aircraft
[
i
].
hitbox
.
height
);
if
(
GetRandomValue
(
0
,
1
))
{
aircraft
[
i
].
position
.
x
=
-
GetRandomValue
(
0
,
1000
);
aircraft
[
i
].
speed
.
x
=
5
;
aircraft
[
i
].
xFirstToJump
=
GetRandomValue
(
10
,
screenHeight
/
2
);
}
else
{
aircraft
[
i
].
speed
.
x
=
-
5
;
aircraft
[
i
].
position
.
x
=
-
GetRandomValue
(
0
,
1000
);
aircraft
[
i
].
xFirstToJump
=
GetRandomValue
(
screenHeight
/
2
,
screenHeight
-
10
);
}
aircraft
[
i
].
xLastTrooperDrop
=
aircraft
[
i
].
xFirstToJump
;
aircraft
[
i
].
speed
.
x
=
5
;
aircraft
[
i
].
speed
.
y
=
0
;
aircraft
[
i
].
color
=
BLACK
;
aircraft
[
i
]
=
InitializeAircraft
();
}
//Initialize bombshells and bullets
bombshellInit
.
radius
=
5
;
bombshellInit
.
damageDone
=
2
;
bombshellInit
.
sin
=
0
;
bombshellInit
.
cos
=
0
;
bombshellInit
.
ammoShot
=
false
;
bombshellInit
.
position
.
x
=
screenHeight
;
bombshellInit
.
position
.
y
=
0
;
bombshellInit
.
speed
.
x
=
0
;
bombshellInit
.
speed
.
y
=
0
;
bombshellInit
.
color
=
RED
;
for
(
int
j
=
0
;
j
<
NUMBER_OF_BOMBSHELLS
;
j
++
){
bombshells
[
j
]
=
bombshellInit
;
bombshells
[
j
]
=
InitializeBombshell
()
;
}
bulletInit
.
radius
=
1
;
bulletInit
.
damageDone
=
2
;
bulletInit
.
sin
=
0
;
bulletInit
.
cos
=
0
;
bulletInit
.
ammoShot
=
false
;
bulletInit
.
position
.
x
=
0
;
bulletInit
.
position
.
y
=
0
;
bulletInit
.
speed
.
x
=
0
;
bulletInit
.
speed
.
y
=
0
;
bulletInit
.
color
=
RED
;
for
(
int
j
=
0
;
j
<
NUMBER_OF_BULLETS
;
j
++
){
bullet
[
j
]
=
bulletInit
;
bullet
[
j
]
=
InitializeBullet
()
;
}
//Initialize canons
antiParaCanon
.
sin
=
0
.;
antiParaCanon
.
cos
=
0
.;
antiParaCanon
.
position
.
x
=
0
.
;
antiParaCanon
.
position
.
y
=
0
.
;
antiParaCanon
.
position
.
x
=
screenWidth
/
4
;
antiParaCanon
.
position
.
y
=
screenHeight
;
antiParaCanon
.
aimingPosition
.
x
=
0
.;
antiParaCanon
.
aimingPosition
.
y
=
0
.;
antiAircraftCanon
.
sin
=
0
.;
antiAircraftCanon
.
cos
=
0
.;
antiAircraftCanon
.
position
.
x
=
screenWidth
;
antiAircraftCanon
.
position
.
y
=
0
.
;
antiAircraftCanon
.
position
.
x
=
screenWidth
*
(
0
.
75
)
;
antiAircraftCanon
.
position
.
y
=
screenHeight
;
antiAircraftCanon
.
aimingPosition
.
x
=
0
.;
antiAircraftCanon
.
aimingPosition
.
y
=
0
.;
}
void
UpdateGame
(
void
){
void
UpdateGame
(
void
)
{
if
(
!
gameOver
)
{
if
(
!
pause
)
...
...
@@ -212,16 +165,31 @@ void UpdateGame(void){
{
if
(
paratrooper
[
i
].
droped
)
{
paratrooper
[
i
].
position
.
x
+=
paratrooper
[
i
].
speed
.
x
;
paratrooper
[
i
].
position
.
y
+=
paratrooper
[
i
].
speed
.
y
;
paratrooper
[
i
].
hitbox
.
x
+=
paratrooper
[
i
].
speed
.
x
;
paratrooper
[
i
].
hitbox
.
y
+=
paratrooper
[
i
].
speed
.
y
;
}
if
(
IsRectangleOut
(
paratrooper
[
i
].
hitbox
))
{
paratrooper
[
i
]
=
InitializeParatrooper
();
}
}
//Planes
for
(
int
j
=
0
;
j
<
NUMBER_OF_AIRCRAFTS
;
j
++
)
{
aircraft
[
j
].
position
.
x
+=
aircraft
[
j
].
speed
.
x
;
aircraft
[
j
].
position
.
y
+=
aircraft
[
j
].
speed
.
y
;
aircraft
[
j
].
hitbox
.
x
+=
aircraft
[
j
].
speed
.
x
;
aircraft
[
j
].
hitbox
.
y
+=
aircraft
[
j
].
speed
.
y
;
if
(
IsRectangleOut
(
aircraft
[
j
].
hitbox
))
{
if
(
aircraft
[
j
].
speed
.
x
>
0
&&
aircraft
[
j
].
hitbox
.
x
>
screenWidth
)
{
aircraft
[
j
]
=
InitializeAircraft
();
}
else
if
(
aircraft
[
j
].
speed
.
x
<
0
&&
aircraft
[
j
].
hitbox
.
x
<
0
)
{
aircraft
[
j
]
=
InitializeAircraft
();
}
}
}
//Bullets
...
...
@@ -232,22 +200,57 @@ void UpdateGame(void){
bullet
[
k
].
position
.
x
+=
bullet
[
k
].
speed
.
x
;
bullet
[
k
].
position
.
y
+=
bullet
[
k
].
speed
.
y
;
}
if
(
IsCircleOut
(
bullet
[
k
].
position
,
bullet
[
k
].
radius
))
{
bullet
[
k
]
=
InitializeBullet
();
}
}
//Bombshells
for
(
int
k
=
0
;
k
<
NUMBER_OF_BOMBSHELLS
;
k
++
)
{
if
(
bombshells
[
k
].
ammoShot
)
{
bombshells
[
k
].
position
.
x
+=
bombshells
[
k
].
speed
.
x
;
bombshells
[
k
].
position
.
y
+=
bombshells
[
k
].
speed
.
y
;
}
if
(
IsCircleOut
(
bombshells
[
k
].
position
,
bombshells
[
k
].
radius
))
{
bombshells
[
k
]
=
InitializeBombshell
();
}
}
//Defining where the canons are shooting
float
hypothenuse
=
sqrt
(
powf
(
GetMousePosition
().
x
,
2
)
+
powf
(
GetMousePosition
().
y
,
2
));
hypothenuse1
=
sqrt
(
powf
(
GetMousePosition
().
x
-
antiAircraftCanon
.
position
.
x
,
2
)
+
powf
(
GetMousePosition
().
y
-
antiAircraftCanon
.
position
.
y
,
2
));
hypothenuse2
=
sqrt
(
powf
(
GetMousePosition
().
x
-
antiParaCanon
.
position
.
x
,
2
)
+
powf
(
GetMousePosition
().
y
-
antiParaCanon
.
position
.
y
,
2
));
antiParaCanon
.
aimingPosition
=
GetMousePosition
();
antiParaCanon
.
sin
=
(
antiParaCanon
.
aimingPosition
.
y
-
antiParaCanon
.
position
.
y
)
/
hypothenuse
;
antiParaCanon
.
cos
=
(
antiParaCanon
.
aimingPosition
.
x
-
antiParaCanon
.
position
.
x
)
/
hypothenuse
;
antiParaCanon
.
sin
=
(
antiParaCanon
.
aimingPosition
.
y
-
antiParaCanon
.
position
.
y
)
/
hypothenuse
2
;
antiParaCanon
.
cos
=
(
antiParaCanon
.
aimingPosition
.
x
-
antiParaCanon
.
position
.
x
)
/
hypothenuse
2
;
antiAircraftCanon
.
aimingPosition
=
GetMousePosition
();
antiAircraftCanon
.
sin
=
(
antiAircraftCanon
.
aimingPosition
.
y
-
antiAircraftCanon
.
position
.
y
)
/
hypothenuse
;
antiAircraftCanon
.
cos
=
(
antiAircraftCanon
.
aimingPosition
.
x
-
antiAircraftCanon
.
position
.
x
)
/
hypothenuse
;
antiAircraftCanon
.
sin
=
(
antiAircraftCanon
.
aimingPosition
.
y
-
antiAircraftCanon
.
position
.
y
)
/
hypothenuse
1
;
antiAircraftCanon
.
cos
=
(
antiAircraftCanon
.
aimingPosition
.
x
-
antiAircraftCanon
.
position
.
x
)
/
hypothenuse
1
;
//Shooting
//anti-aircrafts canon ((double) tempsAAC/CLOCKS_PER_SEC))<(shoot_rate)
if
(
IsMouseButtonPressed
(
MOUSE_LEFT_BUTTON
))
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_BOMBSHELLS
;
i
++
)
{
if
(
!
bombshells
[
i
].
ammoShot
)
{
bombshells
[
i
].
ammoShot
=
true
;
bombshells
[
i
].
position
.
x
=
antiAircraftCanon
.
position
.
x
;
bombshells
[
i
].
position
.
y
=
antiAircraftCanon
.
position
.
y
;
bombshells
[
i
].
speed
.
x
=
bombshellSpeed
*
antiAircraftCanon
.
cos
;
bombshells
[
i
].
speed
.
y
=
bombshellSpeed
*
antiAircraftCanon
.
sin
;
break
;
}
}
}
// anti-Paratroopers canon
if
(
IsMouseButtonPressed
(
MOUSE_RIGHT_BUTTON
))
if
(
IsMouseButtonPressed
(
MOUSE_RIGHT_BUTTON
)
)
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_BULLETS
;
i
++
)
{
...
...
@@ -262,24 +265,235 @@ void UpdateGame(void){
}
}
}
//anti-aircrafts canon
if
(
IsMouseButtonPressed
(
MOUSE_LEFT_BUTTON
))
//Destructions
//Paratroopers
for
(
int
i
=
0
;
i
<
NUMBER_MAX_OF_PARATROOPERS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_BOMBSHELLS
;
i
++
)
{
if
(
!
bullet
[
i
].
ammoShot
)
if
(
paratrooper
[
i
].
droped
)
{
for
(
int
j
=
0
;
j
<
NUMBER_OF_BULLETS
;
j
++
)
{
bombshells
[
i
].
ammoShot
=
true
;
bombshells
[
i
].
position
.
x
=
antiAircraftCanon
.
position
.
x
;
bombshells
[
i
].
position
.
y
=
antiAircraftCanon
.
position
.
y
;
bombshells
[
i
].
speed
.
x
=
bulletSpeed
*
antiAircraftCanon
.
cos
;
bombshells
[
i
].
speed
.
y
=
bulletSpeed
*
antiAircraftCanon
.
sin
;
break
;
if
(
CheckCollisionCircleRec
(
bullet
[
j
].
position
,
bullet
[
j
].
radius
,
paratrooper
[
i
].
hitbox
))
{
bullet
[
j
].
ammoShot
=
false
;
paratrooper
[
i
].
life
--
;
//Kill paras
if
(
paratrooper
[
i
].
life
==
0
)
{
paratrooper
[
i
]
=
InitializeParatrooper
();
}
}
}
}
}
//Planes
for
(
int
i
=
0
;
i
<
NUMBER_OF_AIRCRAFTS
;
i
++
)
{
if
((
aircraft
[
i
].
hitbox
.
x
>
0
)
&&
(
aircraft
[
i
].
hitbox
.
x
<
screenWidth
))
{
for
(
int
j
=
0
;
j
<
NUMBER_OF_BOMBSHELLS
;
j
++
)
{
if
(
CheckCollisionCircleRec
(
bombshells
[
j
].
position
,
bombshells
[
j
].
radius
,
aircraft
[
i
].
hitbox
))
{
bombshells
[
j
].
ammoShot
=
false
;
aircraft
[
i
].
life
=
aircraft
[
i
].
life
-
1
;
//Kill aircrafts
if
(
aircraft
[
i
].
life
==
0
){
aircraft
[
i
]
=
InitializeAircraft
();
}
}
}
//Dropping paratroopers
if
(
aircraft
[
i
].
speed
.
x
>
0
)
{
if
(
aircraft
[
i
].
hitbox
.
x
>
aircraft
[
i
].
xFirstToJump
)
{
for
(
int
j
=
0
;
j
<
NUMBER_MAX_OF_PARATROOPERS
;
j
++
)
{
if
((
!
paratrooper
[
j
].
droped
)
&&
(
aircraft
[
i
].
hitbox
.
x
>
aircraft
[
i
].
xFirstToJump
+
50
)
&&
(
aircraft
[
i
].
numberOfParatroopers
>
-
1
))
{
paratrooper
[
j
].
droped
=
true
;
paratrooper
[
j
].
hitbox
.
x
=
aircraft
[
i
].
hitbox
.
x
;
paratrooper
[
j
].
hitbox
.
y
=
aircraft
[
i
].
hitbox
.
y
;
aircraft
[
i
].
numberOfParatroopers
--
;
aircraft
[
i
].
xFirstToJump
=
aircraft
[
i
].
hitbox
.
x
;
}
}
}
}
else
{
if
(
aircraft
[
i
].
hitbox
.
x
<
aircraft
[
i
].
xFirstToJump
)
{
for
(
int
j
=
0
;
j
<
NUMBER_MAX_OF_PARATROOPERS
;
j
++
)
{
if
((
!
paratrooper
[
j
].
droped
)
&&
(
aircraft
[
i
].
hitbox
.
x
<
aircraft
[
i
].
xFirstToJump
-
50
)
&&
(
aircraft
[
i
].
numberOfParatroopers
>
-
1
))
{
paratrooper
[
j
].
droped
=
true
;
paratrooper
[
j
].
hitbox
.
x
=
aircraft
[
i
].
hitbox
.
x
;
paratrooper
[
j
].
hitbox
.
y
=
aircraft
[
i
].
hitbox
.
y
;
aircraft
[
i
].
numberOfParatroopers
--
;
aircraft
[
i
].
xFirstToJump
=
aircraft
[
i
].
hitbox
.
x
;
}
}
}
}
}
}
}
}
}
void
DrawGame
(
void
)
{
BeginDrawing
();
ClearBackground
(
SKYBLUE
);
if
(
!
gameOver
)
{
//Draw planes
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
++
)
{
if
(
paratrooper
[
i
].
droped
)
{
DrawRectangleRec
(
paratrooper
[
i
].
hitbox
,
paratrooper
[
i
].
color
);
}
}
//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
for
(
int
i
=
0
;
i
<
NUMBER_OF_BOMBSHELLS
;
i
++
)
{
if
(
bombshells
[
i
].
ammoShot
)
{
DrawCircleV
(
bombshells
[
i
].
position
,
bombshells
[
i
].
radius
,
bombshells
[
i
].
color
);
}
}
//Draw viewfinder
DrawCircleV
(
GetMousePosition
(),
5
,
RED
);
}
EndDrawing
();
}
//------------------------------------------------------------------------------------
// Other Functions
//------------------------------------------------------------------------------------
//Initialization functions------------------------------------------------------------
Aircraft
InitializeAircraft
(
void
)
{
Aircraft
aircraft
;
aircraft
.
life
=
2
;
aircraft
.
hitbox
.
width
=
GetRandomValue
(
30
,
50
);
aircraft
.
hitbox
.
height
=
5
;
aircraft
.
numberOfParatroopers
=
GetRandomValue
(
0
,
TROOPERS_PER_PLANE
);
if
(
aircraft
.
hitbox
.
width
<
41
)
{
aircraft
.
hitbox
.
width
=
30
;
}
else
{
aircraft
.
hitbox
.
width
=
50
;
}
aircraft
.
hitbox
.
y
=
GetRandomValue
(
0
+
aircraft
.
hitbox
.
height
,
screenHeight
/
2
);
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
);
}
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
.
speed
.
y
=
0
;
aircraft
.
color
=
GRAY
;
return
aircraft
;
}
Bombshell
InitializeBombshell
(
void
)
{
Bombshell
bombshellInit
;
bombshellInit
.
radius
=
7
;
bombshellInit
.
sin
=
0
;
bombshellInit
.
cos
=
0
;
bombshellInit
.
ammoShot
=
false
;
bombshellInit
.
position
.
x
=
screenHeight
;
bombshellInit
.
position
.
y
=
0
;
bombshellInit
.
speed
.
x
=
0
;
bombshellInit
.
speed
.
y
=
0
;
bombshellInit
.
color
=
RED
;
return
bombshellInit
;
}
Bullet
InitializeBullet
(
void
)
{
Bullet
bulletInit
;
bulletInit
.
radius
=
3
;
bulletInit
.
sin
=
0
;
bulletInit
.
cos
=
0
;
bulletInit
.
ammoShot
=
false
;
bulletInit
.
position
.
x
=
0
;
bulletInit
.
position
.
y
=
screenWidth
;
bulletInit
.
speed
.
x
=
0
;
bulletInit
.
speed
.
y
=
0
;
bulletInit
.
color
=
RED
;
return
bulletInit
;
}
Paratrooper
InitializeParatrooper
(
void
)
{
Paratrooper
paraInitial
;
paraInitial
.
speed
.
y
=
0
.
7
;
paraInitial
.
speed
.
x
=
0
;
paraInitial
.
color
=
RED
;
paraInitial
.
life
=
2
;
paraInitial
.
hitbox
.
width
=
10
;
paraInitial
.
hitbox
.
height
=
10
;
paraInitial
.
droped
=
false
;
return
paraInitial
;
}
//Game Functions-------------------------------------------------------------------------
bool
IsRectangleOut
(
Rectangle
rec
)
{
if
(
rec
.
x
<
0
||
rec
.
x
>
screenWidth
)
{
return
true
;
}
if
(
rec
.
y
<
0
||
rec
.
y
>
screenHeight
)
{
return
true
;
}
return
false
;
}
void
DrawGame
(
void
){}
bool
IsCircleOut
(
Vector2
center
,
float
radius
)
{
if
(
center
.
x
+
radius
<
0
||
center
.
x
-
radius
>
screenWidth
)
{
return
true
;
}
if
(
center
.
y
+
radius
<
0
||
center
.
y
-
radius
>
screenHeight
)
{
return
true
;
}
return
false
;
}
air_defense.exe
View file @
e1ba205b
No preview for this file type
air_defense.h
View file @
e1ba205b
...
...
@@ -8,7 +8,6 @@ typedef struct Paratrooper
int
life
;
bool
droped
;
Rectangle
hitbox
;
Vector2
position
;
Vector2
speed
;
Color
color
;
// yellow or red
}
Paratrooper
;
...
...
@@ -17,10 +16,8 @@ typedef struct Aircraft
{
int
life
;
float
xFirstToJump
;
float
xLastTrooperDrop
;
int
numberOfParatroopers
;
Rectangle
hitbox
;
Vector2
position
;
Vector2
speed
;
Color
color
;
//black
}
Aircraft
;
...
...
@@ -28,7 +25,6 @@ typedef struct Aircraft
typedef
struct
Bombshell
{
float
radius
;
int
damageDone
;
float
sin
;
float
cos
;
bool
ammoShot
;
...
...
@@ -67,12 +63,24 @@ typedef struct AntiParaCanon
//------------------------------------------------------------------------------------
// Module Functions Declaration
(local)
// Module Functions Declaration
//------------------------------------------------------------------------------------
static
void
InitGame
(
void
);
// Initialize game
static
void
UpdateGame
();
// Update game (one frame)
static
void
DrawGame
(
void
);
// Draw game (one frame)
static
void
UnloadGame
(
void
);
// Unload game
void
IsParaAlive
(
void
);
//------------------------------------------------------------------------------------
// Other Functions
//------------------------------------------------------------------------------------
//Initialization functions------------------------------------------------------------
Aircraft
InitializeAircraft
(
void
);
Bombshell
InitializeBombshell
(
void
);
Bullet
InitializeBullet
(
void
);
Paratrooper
InitializeParatrooper
(
void
);
//Game functions----------------------------------------------------------------------
bool
IsRectangleOut
(
Rectangle
rec
);
bool
IsCircleOut
(
Vector2
center
,
float
radius
);
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