Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mathodo2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MOULIAS Mattheo
Mathodo2
Commits
94a8c631
Commit
94a8c631
authored
2 years ago
by
SmallIshMink
Browse files
Options
Downloads
Patches
Plain Diff
Niveau 2 (4) Presque fini
parent
a82c40d2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
library/World/world.c
+12
-34
12 additions, 34 deletions
library/World/world.c
with
12 additions
and
34 deletions
library/World/world.c
+
12
−
34
View file @
94a8c631
...
@@ -6,16 +6,16 @@
...
@@ -6,16 +6,16 @@
*/
*/
void
update_data
(
world_t
*
world
){
void
update_data
(
world_t
*
world
){
world
->
ligneArriver
->
y
+=
INITIAL_SPEED
-
world
->
speed_h
;
world
->
ligneArriver
->
y
+=
world
->
speed_h
;
world
->
mur
->
y
+=
INITIAL_SPEED
-
world
->
speed_h
;
world
->
mur
->
y
+=
world
->
speed_h
;
if
(
isOverScreen
(
world
->
vaisseau
)){
if
(
isOverScreen
(
world
->
vaisseau
)){
if
(
world
->
vaisseau
->
x
<
0
)
world
->
vaisseau
->
x
=
0
;
if
(
world
->
vaisseau
->
x
<
0
)
world
->
vaisseau
->
x
=
0
;
if
(
world
->
vaisseau
->
x
+
world
->
vaisseau
->
w
>
SCREEN_WIDTH
)
world
->
vaisseau
->
x
=
SCREEN_WIDTH
-
world
->
vaisseau
->
w
;
if
(
world
->
vaisseau
->
x
+
world
->
vaisseau
->
w
>
SCREEN_WIDTH
)
world
->
vaisseau
->
x
=
SCREEN_WIDTH
-
world
->
vaisseau
->
w
;
if
(
world
->
vaisseau
->
y
<
0
)
world
->
vaisseau
->
y
=
0
;
if
(
world
->
vaisseau
->
y
<
0
)
world
->
vaisseau
->
y
=
0
;
if
(
world
->
vaisseau
->
y
+
world
->
vaisseau
->
h
>
SCREEN_HEIGHT
)
world
->
vaisseau
->
y
=
SCREEN_HEIGHT
-
world
->
vaisseau
->
h
;
if
(
world
->
vaisseau
->
y
+
world
->
vaisseau
->
h
>
SCREEN_HEIGHT
)
world
->
vaisseau
->
y
=
SCREEN_HEIGHT
-
world
->
vaisseau
->
h
;
}
}
handle_sprite_collide
(
world
->
vaisseau
,
world
->
mur
,
world
);
}
}
/**
/**
...
@@ -28,35 +28,6 @@ int is_game_over(world_t *world){
...
@@ -28,35 +28,6 @@ int is_game_over(world_t *world){
return
world
->
gameover
;
return
world
->
gameover
;
}
}
int
isOverScreen
(
sprite_t
*
sprite
){
if
(
sprite
->
x
<
0
||
sprite
->
x
+
sprite
->
w
>
SCREEN_WIDTH
||
sprite
->
y
<
0
||
sprite
->
y
+
sprite
->
h
>
SCREEN_HEIGHT
){
return
1
;
}
return
0
;
}
void
print_sprite
(
sprite_t
*
sprite
){
printf
(
"x = %d, y = %d, w = %d, h = %d
\n
"
,
sprite
->
x
,
sprite
->
y
,
sprite
->
w
,
sprite
->
h
);
}
/**
* \brief La fonction initialise les sprites du jeu
*
* \param sprite
* \param x
* \param y
* \param w
* \param h
*/
sprite_t
*
init_sprite
(
sprite_t
*
sprite
,
int
x
,
int
y
,
int
w
,
int
h
){
sprite
=
malloc
(
sizeof
(
sprite_t
));
sprite
->
x
=
x
;
sprite
->
y
=
y
;
sprite
->
w
=
w
;
sprite
->
h
=
h
;
return
sprite
;
}
/**
/**
* \brief La fonction initialise les données du monde du jeu
* \brief La fonction initialise les données du monde du jeu
* \param world les données du monde
* \param world les données du monde
...
@@ -67,7 +38,7 @@ void init_data(world_t * world){
...
@@ -67,7 +38,7 @@ void init_data(world_t * world){
//on n'est pas à la fin du jeu
//on n'est pas à la fin du jeu
world
->
gameover
=
0
;
world
->
gameover
=
0
;
world
->
speed_h
=
0
;
world
->
speed_h
=
INITIAL_SPEED
;
// Initialisation du vaisseau
// Initialisation du vaisseau
world
->
vaisseau
=
init_sprite
(
world
->
vaisseau
,
SCREEN_WIDTH
/
2
-
SHIP_SIZE
/
2
,
SCREEN_HEIGHT
-
SHIP_SIZE
,
SHIP_SIZE
,
SHIP_SIZE
);
world
->
vaisseau
=
init_sprite
(
world
->
vaisseau
,
SCREEN_WIDTH
/
2
-
SHIP_SIZE
/
2
,
SCREEN_HEIGHT
-
SHIP_SIZE
,
SHIP_SIZE
,
SHIP_SIZE
);
...
@@ -89,4 +60,11 @@ void clean_data(world_t *world){
...
@@ -89,4 +60,11 @@ void clean_data(world_t *world){
free
(
world
->
vaisseau
);
free
(
world
->
vaisseau
);
}
}
void
handle_sprite_collide
(
sprite_t
*
sp1
,
sprite_t
*
sp2
,
world_t
*
world
,
int
make_disappear
){
if
(
sprites_collide
(
sp1
,
sp2
)){
world
->
speed_h
=
0
;
}
else
{
world
->
speed_h
=
INITIAL_SPEED
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment