Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Projet l2
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
VAUTRIN Guillaume
Projet l2
Commits
248aa344
Commit
248aa344
authored
4 years ago
by
vautrin33u
Browse files
Options
Downloads
Patches
Plain Diff
Ajout de certaines fonctions de logique
parent
191f7cab
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
constantes.h
+5
-0
5 additions, 0 deletions
constantes.h
logique.c
+66
-4
66 additions, 4 deletions
logique.c
logique.h
+43
-0
43 additions, 0 deletions
logique.h
tests.c
+1
-0
1 addition, 0 deletions
tests.c
with
115 additions
and
4 deletions
constantes.h
+
5
−
0
View file @
248aa344
...
...
@@ -34,4 +34,9 @@
* */
#define NB_INGREDIENT 5
/**
* \brief taille joueur
* */
#define SIZE_JOUEUR 50
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
logique.c
+
66
−
4
View file @
248aa344
...
...
@@ -15,6 +15,10 @@ void init_data(world_t * world){ //faux
world
->
compteur_plats
=
0
;
world
->
score
=
0
;
world
->
attente
=
0
;
//Initialise le sprite du joueur en haut à gauche de l'écran, en état 0
init_sprite
(
&
world
->
joueur
,
SCREEN_WIDTH
*
0
.
1
,
SCREEN_HEIGHT
*
0
.
1
,
SIZE_JOUEUR
,
SIZE_JOUEUR
,
SIZE_JOUEUR
/
2
);
/*
init_sprite(&world->ship, SCREEN_WIDTH/2, SCREEN_HEIGHT-SHIP_SIZE, SHIP_SIZE, SHIP_SIZE, MOVING_STEP);
...
...
@@ -42,6 +46,31 @@ int aleatoire (int a, int b){
return
rand
()
%
(
b
-
a
)
+
a
;
}
void
set_bas
(
sprite_t
*
sprite
){
// Sprite va vers le bas
sprite
->
etat
=
0
;
}
void
set_haut
(
sprite_t
*
sprite
){
// Sprite va vers le haut
sprite
->
etat
=
1
;
}
void
set_droite
(
sprite_t
*
sprite
){
// Sprite va vers la droite
sprite
->
etat
=
2
;
}
void
set_gauche
(
sprite_t
*
sprite
){
// Sprite va vers la gauche
sprite
->
etat
=
3
;
}
int
return_state
(
sprite_t
*
sprite
){
//Retourne l'état du sprite
return
sprite
->
etat
;
}
void
set_visible
(
sprite_t
*
sprite
){
// Permet de rendre visible un sprite
sprite
->
is_visible
=
0
;
...
...
@@ -57,6 +86,30 @@ int estFini(world_t *world){
return
world
->
gameover
;
}
void
limites_externes
(
sprite_t
*
sprite
){
//Défini les limites selon les murs
if
(
sprite
->
x
>
(
SCREEN_WIDTH
*
0
.
9
)){
//mur droite
sprite
->
x
=
(
SCREEN_WIDTH
*
0
.
9
)
-
sprite
->
w
/
2
;
}
if
(
sprite
->
x
<
(
SCREEN_WIDTH
*
0
.
1
)){
//mur gauche
sprite
->
x
=
(
SCREEN_WIDTH
*
0
.
1
);
}
if
(
sprite
->
y
>
(
SCREEN_HEIGHT
*
0
.
9
)){
//mur bas
sprite
->
y
=
(
SCREEN_HEIGHT
*
0
.
9
)
-
sprite
->
w
/
2
;
}
if
(
sprite
->
y
<
(
SCREEN_HEIGHT
*
0
.
1
)){
//mur haut
sprite
->
y
=
(
SCREEN_HEIGHT
*
0
.
1
);
}
}
void
gestion_events
(
SDL_Event
*
event
,
world_t
*
world
){
SDL_PollEvent
(
event
);
...
...
@@ -67,13 +120,21 @@ void gestion_events(SDL_Event *event, world_t *world){
switch
(
event
->
key
.
keysym
.
sym
){
case
SDLK_ESCAPE
:
world
->
gameover
=
1
;
break
;
/
*
Déplacement du joueur
/
/
Déplacement du joueur
case
SDLK_z
:
set_haut
(
&
world
->
joueur
);
break
;
case
SDLK_s
:
set_bas
(
&
world
->
joueur
);
break
;
case
SDLK_d
:
set_droit
(
&
world
->
joueur
);
break
;
case
SDLK_q
:
case SDLK_SPACE:
*/
set_gauche
(
&
world
->
joueur
);
break
;
//case SDLK_SPACE:
}
}
}
...
...
@@ -135,4 +196,5 @@ char** init_map (){
return tab;
}
*/
\ No newline at end of file
*/
This diff is collapsed.
Click to expand it.
logique.h
+
43
−
0
View file @
248aa344
...
...
@@ -110,5 +110,48 @@ char** init_map ();
*/
void
handle_collisions
(
world_t
world
,
char
**
map
);
/**
* @brief Indique que le sprite face le bas
*
* @param sprite
*/
void
set_bas
(
sprite_t
*
sprite
);
/**
* @brief Indique que le sprite face le haut
*
* @param sprite
*/
void
set_haut
(
sprite_t
*
sprite
);
/**
* @brief Indique que le sprite face vers la droite
*
* @param sprite
*/
void
set_droite
(
sprite_t
*
sprite
);
/**
* @brief Indique que le sprite face vers la gauche
*
* @param sprite
*/
void
set_gauche
(
sprite_t
*
sprite
);
/**
* @brief Retourne l'état du sprite
*
* @param sprite
* @return int valeur de l'état actuel du sprite
*/
int
return_state
(
sprite_t
*
sprite
);
/**
* @brief gestions des limites des murs
*
* @param sprite
*/
void
limites_externes
(
sprite_t
*
sprite
);
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests.c
+
1
−
0
View file @
248aa344
...
...
@@ -103,3 +103,4 @@ test_lire_fichier();
test_generer_map
();
test_lecture_map
();
}
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