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
99b6ce2a
Commit
99b6ce2a
authored
Oct 28, 2020
by
Pierre MARQUE
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parti boire le dernier verre : Mouvemnts de touts les objets - ok + tir cannons
parent
d27a91c9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
21 deletions
+97
-21
air_defense.c
air_defense.c
+95
-21
air_defense.exe
air_defense.exe
+0
-0
air_defense.h
air_defense.h
+2
-0
No files found.
air_defense.c
View file @
99b6ce2a
...
...
@@ -49,6 +49,9 @@ static bool gameOver = false;
static
bool
pause
=
false
;
static
int
score
=
0
;
const
float
bulletSpeed
=
10
.;
const
float
bombshellSpeed
=
7
.
5
;
AntiParaCanon
antiParaCanon
;
AntiAircraftCanon
antiAircraftCanon
;
Paratrooper
paraInitial
;
...
...
@@ -58,7 +61,7 @@ Bullet bulletInit;
Aircraft
aircraft
[
NUMBER_OF_AIRCRAFTS
];
Bullet
bullet
[
NUMBER_OF_BULLETS
];
Bombshell
bombshells
[
NUMBER_OF_BOMBSHELLS
];
Paratrooper
paratrooper
s
[
NUMBER_MAX_OF_PARATROOPERS
];
Paratrooper
paratrooper
[
NUMBER_MAX_OF_PARATROOPERS
];
//------------------------------------------------------------------------------------
// Program main entry point
...
...
@@ -71,7 +74,7 @@ int main(void)
InitWindow
(
screenWidth
,
screenHeight
,
"raylib [core] example - basic window"
);
InitGame
();
SetTargetFPS
(
60
);
// Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
...
...
@@ -116,32 +119,37 @@ void InitGame(void){
paraInitial
.
hitbox
.
height
=
10
;
paraInitial
.
droped
=
false
;
for
(
int
k
=
0
;
k
<
NUMBER_MAX_OF_PARATROOPERS
;
k
++
){
paratrooper
s
[
k
]
=
paraInitial
;
paratrooper
[
k
]
=
paraInitial
;
}
//Initialize aircrafts
for
(
int
i
=
0
;
i
<
NUMBER_OF_AIRCRAFTS
;
i
++
){
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
){
if
(
aircraft
[
i
].
hitbox
.
height
<
41
)
{
aircraft
[
i
].
hitbox
.
height
=
30
;
}
else
{
else
{
aircraft
[
i
].
hitbox
.
height
=
50
;
}
aircraft
[
i
].
hitbox
.
y
=
GetRandomValue
(
screenHeight
/
3
,
screenHeight
-
aircraft
[
i
].
hitbox
.
height
);
if
(
GetRandomValue
(
0
,
1
)){
aircraft
[
i
].
hitbox
.
x
=
-
GetRandomValue
(
0
,
1000
);
if
(
GetRandomValue
(
0
,
1
))
{
aircraft
[
i
].
position
.
x
=
-
GetRandomValue
(
0
,
1000
);
aircraft
[
i
].
speed
.
x
=
5
;
aircraft
[
i
].
xFirstToJump
=
GetRandomValue
(
10
,
screenHeight
/
2
);
}
else
{
else
{
aircraft
[
i
].
speed
.
x
=
-
5
;
aircraft
[
i
].
hitbox
.
x
=
-
GetRandomValue
(
0
,
1000
);
aircraft
[
i
].
position
.
x
=
-
GetRandomValue
(
0
,
1000
);
aircraft
[
i
].
xFirstToJump
=
GetRandomValue
(
screenHeight
/
2
,
screenHeight
-
10
);
}
aircraft
[
i
].
xLastTrooperDrop
=
-
1
;
aircraft
[
i
].
xLastTrooperDrop
=
aircraft
[
i
].
xFirstToJump
;
aircraft
[
i
].
speed
.
x
=
5
;
aircraft
[
i
].
speed
.
y
=
0
;
aircraft
[
i
].
color
=
BLACK
;
...
...
@@ -172,8 +180,8 @@ void InitGame(void){
bulletInit
.
speed
.
x
=
0
;
bulletInit
.
speed
.
y
=
0
;
bulletInit
.
color
=
RED
;
for
(
int
j
=
0
;
j
<
NUMBER_OF_BULLETS
;
j
++
){
bullet
[
j
]
=
bulletInit
;
for
(
int
j
=
0
;
j
<
NUMBER_OF_BULLETS
;
j
++
){
bullet
[
j
]
=
bulletInit
;
}
//Initialize canons
...
...
@@ -186,24 +194,90 @@ void InitGame(void){
antiAircraftCanon
.
sin
=
0
.;
antiAircraftCanon
.
cos
=
0
.;
antiAircraftCanon
.
position
.
x
=
0
.
;
antiAircraftCanon
.
position
.
x
=
screenWidth
;
antiAircraftCanon
.
position
.
y
=
0
.;
antiAircraftCanon
.
aimingPosition
.
x
=
0
.;
antiAircraftCanon
.
aimingPosition
.
y
=
0
.;
}
void
UpdateGame
(
void
){
if
(
!
gameOver
){
if
(
!
pause
){
//Releasing and animate Aircrafts
if
(
!
gameOver
)
{
if
(
!
pause
)
{
//Moves
//Paratroopers
for
(
int
i
=
0
;
i
<
NUMBER_MAX_OF_PARATROOPERS
;
i
++
)
{
if
(
paratrooper
[
i
].
droped
)
{
paratrooper
[
i
].
position
.
x
+=
paratrooper
[
i
].
speed
.
x
;
paratrooper
[
i
].
position
.
y
+=
paratrooper
[
i
].
speed
.
y
;
}
}
//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
;
}
//Bullets
for
(
int
k
=
0
;
k
<
NUMBER_OF_BULLETS
;
k
++
)
{
if
(
bullet
[
k
].
ammoShot
)
{
bullet
[
k
].
position
.
x
+=
bullet
[
k
].
speed
.
x
;
bullet
[
k
].
position
.
y
+=
bullet
[
k
].
speed
.
y
;
}
}
//Defining where the canons are shooting
float
hypothenuse
=
sqrt
(
powf
(
GetMousePosition
().
x
,
2
)
+
powf
(
GetMousePosition
().
y
,
2
));
antiParaCanon
.
aimingPosition
=
GetMousePosition
();
antiParaCanon
.
sin
=
(
antiParaCanon
.
aimingPosition
.
y
-
antiParaCanon
.
position
.
y
)
/
hypothenuse
;
antiParaCanon
.
cos
=
(
antiParaCanon
.
aimingPosition
.
x
-
antiParaCanon
.
position
.
x
)
/
hypothenuse
;
antiAircraftCanon
.
aimingPosition
=
GetMousePosition
();
antiAircraftCanon
.
sin
=
(
antiAircraftCanon
.
aimingPosition
.
y
-
antiAircraftCanon
.
position
.
y
)
/
hypothenuse
;
antiAircraftCanon
.
cos
=
(
antiAircraftCanon
.
aimingPosition
.
x
-
antiAircraftCanon
.
position
.
x
)
/
hypothenuse
;
//Shooting
// anti-Paratroopers canon
if
(
IsMouseButtonPressed
(
MOUSE_RIGHT_BUTTON
))
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_BULLETS
;
i
++
)
{
if
(
!
bullet
[
i
].
ammoShot
)
{
bullet
[
i
].
ammoShot
=
true
;
bullet
[
i
].
position
.
x
=
antiParaCanon
.
position
.
x
;
bullet
[
i
].
position
.
y
=
antiParaCanon
.
position
.
y
;
bullet
[
i
].
speed
.
x
=
bulletSpeed
*
antiParaCanon
.
cos
;
bullet
[
i
].
speed
.
y
=
bulletSpeed
*
antiParaCanon
.
sin
;
break
;
}
}
}
//anti-aircrafts canon
if
(
IsMouseButtonPressed
(
MOUSE_LEFT_BUTTON
))
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_BOMBSHELLS
;
i
++
)
{
if
(
!
bullet
[
i
].
ammoShot
)
{
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
;
}
}
}
}
}
}
...
...
air_defense.exe
View file @
99b6ce2a
No preview for this file type
air_defense.h
View file @
99b6ce2a
...
...
@@ -8,6 +8,7 @@ typedef struct Paratrooper
int
life
;
bool
droped
;
Rectangle
hitbox
;
Vector2
position
;
Vector2
speed
;
Color
color
;
// yellow or red
}
Paratrooper
;
...
...
@@ -19,6 +20,7 @@ typedef struct Aircraft
float
xLastTrooperDrop
;
int
numberOfParatroopers
;
Rectangle
hitbox
;
Vector2
position
;
Vector2
speed
;
Color
color
;
//black
}
Aircraft
;
...
...
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