Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
VAUTRIN Guillaume
Projet l2
Commits
ea049db7
Commit
ea049db7
authored
Dec 25, 2020
by
vautrin33u
Browse files
Gestion des mouvements (a compléter et tester) et du score actuel fait
parent
24b555b7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Ressources/save.txt
View file @
ea049db7
This source diff could not be displayed because it is too large. You can
view the blob
instead.
constantes.h
View file @
ea049db7
...
...
@@ -11,7 +11,7 @@
//enum état pour décrire la direction du sprite
enum
etat
{
BAS
,
HAUT
,
DROITE
,
GAUCHE
,
MOBILE
,
FIXE
,
PORTE
,
POSE
};
enum
cuisson
{
INCONCERNE
,
FRIGO
,
FRAIS
,
SALE
,
PROPRE
,
CUIT
,
CRU
,
JETE
};
enum
cuisson
{
INCONCERNE
,
FRIGO
,
SALE
,
PROPRE
,
CUIT
,
CRU
,
JETE
};
/**
* \brief Largeur de l'écran
...
...
graphisme.c
View file @
ea049db7
...
...
@@ -21,17 +21,17 @@ void clean_textures(textures_t *textures){
if
(
textures
->
comptoire
!=
NULL
){
SDL_DestroyTexture
(
textures
->
comptoire
);
}
if
(
textures
->
envoi
[
0
]
!=
NULL
){
SDL_DestroyTexture
(
textures
->
envoi
[
0
]
);
if
(
textures
->
envoi
!=
NULL
){
SDL_DestroyTexture
(
textures
->
envoi
);
}
if
(
textures
->
frigo
[
0
]
!=
NULL
){
SDL_DestroyTexture
(
textures
->
frigo
[
0
]
);
if
(
textures
->
frigo
!=
NULL
){
SDL_DestroyTexture
(
textures
->
frigo
);
}
if
(
textures
->
four
[
0
]
!=
NULL
){
SDL_DestroyTexture
(
textures
->
four
[
0
]
);
if
(
textures
->
four
!=
NULL
){
SDL_DestroyTexture
(
textures
->
four
);
}
if
(
textures
->
lavabo
[
0
]
!=
NULL
){
SDL_DestroyTexture
(
textures
->
lavabo
[
0
]
);
if
(
textures
->
lavabo
!=
NULL
){
SDL_DestroyTexture
(
textures
->
lavabo
);
}
if
(
textures
->
poubelle
!=
NULL
){
SDL_DestroyTexture
(
textures
->
poubelle
);
...
...
@@ -56,11 +56,11 @@ void init_textures (SDL_Renderer *renderer, textures_t *textures, TTF_Font *font
textures
->
fond
=
charger_image
(
"Ressources/fond1.bmp"
,
renderer
);
textures
->
joueur
=
charger_image
(
"Ressources/joueur.bmp"
,
renderer
);
textures
->
comptoire
=
charger_image
(
"Ressources/compt0.bmp"
,
renderer
);
textures
->
envoi
[
0
]
=
charger_image
(
"Ressources/envoi0.bmp"
,
renderer
);
textures
->
frigo
[
0
]
=
charger_image
(
"Ressources/frigo0.bmp"
,
renderer
);
textures
->
four
[
0
]
=
charger_image
(
"Ressources/four0.bmp"
,
renderer
);
textures
->
envoi
=
charger_image
(
"Ressources/envoi0.bmp"
,
renderer
);
textures
->
frigo
=
charger_image
(
"Ressources/frigo0.bmp"
,
renderer
);
textures
->
four
=
charger_image
(
"Ressources/four0.bmp"
,
renderer
);
textures
->
poubelle
=
charger_image
(
"Ressources/trash0.bmp"
,
renderer
);
textures
->
lavabo
[
0
]
=
charger_image
(
"Ressources/lavabo0.bmp"
,
renderer
);
textures
->
lavabo
=
charger_image
(
"Ressources/lavabo0.bmp"
,
renderer
);
textures
->
ingredient
=
charger_image_transparente
(
"Ressources/ingredient.bmp"
,
renderer
,
r
,
g
,
b
);
textures
->
police
=
font
;
...
...
@@ -78,25 +78,33 @@ void apply_graphics (SDL_Renderer *renderer, textures_t *textures, world_t *worl
if
(
textures
->
joueur
!=
NULL
&&
est_visible
(
&
world
->
joueur
)){
SDL_RenderCopy
(
renderer
,
textures
->
joueur
,
NULL
,
&
world
->
joueur
.
rect
);
}
//Affichage de la poubelle
apply_mobilier
(
renderer
,
textures
,
world
);
apply_ingredients
(
renderer
,
textures
,
world
->
en_cuisine
);
apply_texte
(
renderer
,
&
world
->
etat_stocks
,
textures
);
}
void
apply_mobilier
(
SDL_Renderer
*
renderer
,
textures_t
*
textures
,
world_t
*
world
){
// Affichage des meubles (fixes)
//Affichage de la poubelle
if
(
textures
->
poubelle
!=
NULL
&&
est_visible
(
&
world
->
poubelle
)){
SDL_RenderCopy
(
renderer
,
textures
->
poubelle
,
NULL
,
&
world
->
poubelle
.
rect
);
}
//Affichage du lavabo
if
(
textures
->
lavabo
[
0
]
!=
NULL
&&
est_visible
(
&
world
->
lavabo
)){
SDL_RenderCopy
(
renderer
,
textures
->
lavabo
[
0
]
,
NULL
,
&
world
->
lavabo
.
rect
);
if
(
textures
->
lavabo
!=
NULL
&&
est_visible
(
&
world
->
lavabo
)){
SDL_RenderCopy
(
renderer
,
textures
->
lavabo
,
NULL
,
&
world
->
lavabo
.
rect
);
}
//Affichage du frigo
if
(
textures
->
frigo
[
0
]
!=
NULL
&&
est_visible
(
&
world
->
frigo
)){
SDL_RenderCopy
(
renderer
,
textures
->
frigo
[
0
]
,
NULL
,
&
world
->
frigo
.
rect
);
if
(
textures
->
frigo
!=
NULL
&&
est_visible
(
&
world
->
frigo
)){
SDL_RenderCopy
(
renderer
,
textures
->
frigo
,
NULL
,
&
world
->
frigo
.
rect
);
}
//Affichage du four
if
(
textures
->
four
[
0
]
!=
NULL
&&
est_visible
(
&
world
->
four
)){
SDL_RenderCopy
(
renderer
,
textures
->
four
[
0
]
,
NULL
,
&
world
->
four
.
rect
);
if
(
textures
->
four
!=
NULL
&&
est_visible
(
&
world
->
four
)){
SDL_RenderCopy
(
renderer
,
textures
->
four
,
NULL
,
&
world
->
four
.
rect
);
}
//Affichage de la zone d'envoi
if
(
textures
->
envoi
[
0
]
!=
NULL
&&
est_visible
(
&
world
->
envoi
)){
SDL_RenderCopy
(
renderer
,
textures
->
envoi
[
0
]
,
NULL
,
&
world
->
envoi
.
rect
);
if
(
textures
->
envoi
!=
NULL
&&
est_visible
(
&
world
->
envoi
)){
SDL_RenderCopy
(
renderer
,
textures
->
envoi
,
NULL
,
&
world
->
envoi
.
rect
);
}
//Affichage des comptoires
if
(
textures
->
comptoire
!=
NULL
){
...
...
@@ -106,14 +114,18 @@ void apply_graphics (SDL_Renderer *renderer, textures_t *textures, world_t *worl
}
}
}
}
void
apply_ingredients
(
SDL_Renderer
*
renderer
,
textures_t
*
textures
,
sprite_t
*
ingredients
){
//Affichage des ingrédients
SDL_Rect
temp
;
if
(
textures
->
ingredient
!=
NULL
){
for
(
int
i
=
0
;
i
<
NB_INGREDIENT
;
i
++
){
if
(
est_visible
(
&
world
->
en_cuisine
[
i
])){
if
(
est_visible
(
&
ingredients
[
i
])){
//Afficher la texture approprié au sprite détecté
switch
(
world
->
en_cuisine
[
i
].
nom
){
char
name
=
ingredients
[
i
].
nom
;
switch
(
name
){
case
NOM_TOMATE
:
temp
=
create_SDL_rect_from_texture
(
textures
->
ingredient
,
0
,
0
,
PLAT_SIZE
,
PLAT_SIZE
);
break
;
...
...
@@ -138,19 +150,22 @@ void apply_graphics (SDL_Renderer *renderer, textures_t *textures, world_t *worl
temp
=
create_SDL_rect_from_texture
(
textures
->
ingredient
,
125
,
0
,
PLAT_SIZE
,
PLAT_SIZE
);
break
;
}
SDL_RenderCopy
(
renderer
,
textures
->
ingredient
,
&
temp
,
&
world
->
en_cuisine
[
i
].
rect
);
SDL_Rect
*
rectangle
=
&
ingredients
[
i
].
rect
;
SDL_RenderCopy
(
renderer
,
textures
->
ingredient
,
&
temp
,
rectangle
);
}
}
}
}
//Affichage du score:
void
apply_texte
(
SDL_Renderer
*
renderer
,
stock_t
*
stock
,
textures_t
*
textures
){
//Affichage du score
if
(
textures
->
police
!=
NULL
){
//Zone d'affichage du score -- taille du score s'adapte à son contenu
SDL_Rect
zone_message
=
create_SDL_rect
(
20
,
550
,
75
,
50
);
SDL_Rect
zone_score
;
if
(
get_score
(
&
world
->
etat_
stock
s
)
<
100
){
if
(
get_score
(
stock
)
<
100
){
zone_score
=
create_SDL_rect
(
90
,
555
,
40
,
40
);
}
else
if
(
get_score
(
&
world
->
etat_
stock
s
)
<
10000
){
}
else
if
(
get_score
(
stock
)
<
10000
){
zone_score
=
create_SDL_rect
(
90
,
555
,
60
,
40
);
}
else
{
zone_score
=
create_SDL_rect
(
90
,
555
,
100
,
40
);
...
...
@@ -162,23 +177,14 @@ void apply_graphics (SDL_Renderer *renderer, textures_t *textures, world_t *worl
//affichage en deux partie de score et de la valeur du score
message
=
charger_texte
(
"Score : "
,
renderer
,
textures
->
police
,
color
);
char
score_j
[
10
];
sprintf
(
score_j
,
" %d"
,
get_score
(
&
world
->
etat_stocks
));
//Nécessaire pour afficher le score -- limite le nombre de points max!
sprintf
(
score_j
,
" %d"
,
stock
->
score
);
//Nécessaire pour afficher le score -- limite le nombre de points max!
printf
(
"
\n
SCORE : %d"
,
get_score
(
stock
));
points
=
charger_texte
(
score_j
,
renderer
,
textures
->
police
,
color
);
render_texte
(
renderer
,
zone_message
,
message
);
render_texte
(
renderer
,
zone_score
,
points
);
}
}
void
colorier_rect
(
SDL_Renderer
*
renderer
,
SDL_Rect
rectangle
,
SDL_Color
couleur
){
SDL_SetRenderDrawColor
(
renderer
,
couleur
.
r
,
couleur
.
g
,
couleur
.
b
,
couleur
.
a
);
for
(
int
i
=
0
;
i
<
rectangle
.
y
;
i
++
){
for
(
int
j
=
0
;
j
<
rectangle
.
x
;
j
++
){
SDL_RenderDrawPoint
(
renderer
,
j
,
i
);
}
}
}
SDL_Rect
create_SDL_rect_from_texture
(
SDL_Texture
*
texture
,
int
x
,
int
y
,
int
h
,
int
w
){
//Permet de créer un SDL_rect retournant la texture de la taille de la texture (SOURCE)
int
largeur
;
...
...
graphisme.h
View file @
ea049db7
...
...
@@ -18,11 +18,11 @@ struct textures_s{
SDL_Texture
*
fond
;
/*!< Texture liée à l'image du fond de l'écran. */
SDL_Texture
*
joueur
;
/* Texture du joueur*/
SDL_Texture
*
comptoire
;
/*< Texture des comptoires */
SDL_Texture
*
envoi
[
1
]
;
/*< Tableau de texture de la zone d'envoi */
SDL_Texture
*
four
[
1
]
;
/*< Tableau de texture du four */
SDL_Texture
*
lavabo
[
1
]
;
/*< Tableau de texture du frigo */
SDL_Texture
*
envoi
;
/*< Tableau de texture de la zone d'envoi */
SDL_Texture
*
four
;
/*< Tableau de texture du four */
SDL_Texture
*
lavabo
;
/*< Tableau de texture du frigo */
SDL_Texture
*
poubelle
;
/*< Texture de la poubelle */
SDL_Texture
*
frigo
[
1
]
;
/*< Tableau de texture du frigo */
SDL_Texture
*
frigo
;
/*< Tableau de texture du frigo */
SDL_Texture
*
ingredient
;
/*< textures des ingredients */
TTF_Font
*
police
;
/*Texture de la police d'écriture*/
};
...
...
@@ -82,6 +82,33 @@ void apply_sprite (SDL_Renderer *renderer, SDL_Texture *tex, sprite_t sprite);
*/
void
apply_graphics
(
SDL_Renderer
*
renderer
,
textures_t
*
textures
,
world_t
*
world
);
/**
* @brief Applique tous les éléments du mobilier sur le renderer
*
* @param renderer
* @param textures
* @param world Donne accès aux sprite du mobilier
*/
void
apply_mobilier
(
SDL_Renderer
*
renderer
,
textures_t
*
textures
,
world_t
*
world
);
/**
* @brief Applique tous les éléments textuels sur le renderer
*
* @param renderer
* @param stock état des stocks et score
* @param textures
*/
void
apply_texte
(
SDL_Renderer
*
renderer
,
stock_t
*
stock
,
textures_t
*
textures
);
/**
* @brief Applique les ingrédients en jeu sur le renderer
*
* @param renderer
* @param textures textures du jeu
* @param ingredients données concernant les ingrédients en jeu
*/
void
apply_ingredients
(
SDL_Renderer
*
renderer
,
textures_t
*
textures
,
sprite_t
*
ingredients
);
/**
* @brief Créer un objet SDL_rect
*
...
...
@@ -112,15 +139,6 @@ SDL_Rect create_SDL_rect_from_texture (SDL_Texture * texture, int x, int y, int
*/
SDL_Rect
create_SDL_rect_from_sprite
(
sprite_t
*
sprite
);
/**
* @brief Colorie un rectangle d'une couleur donnée
*
* @param renderer surface correspondant à la fenetre
* @param rectangle rectangle
* @param couleur couleur sélectionnée
*/
void
colorier_rect
(
SDL_Renderer
*
renderer
,
const
SDL_Rect
rectangle
,
const
SDL_Color
couleur
);
/**
* @brief mets à jour les éléments graphique de la fenêtre de jeu
...
...
logique.c
View file @
ea049db7
...
...
@@ -42,6 +42,7 @@ void init_data(world_t * world){
void
init_ingre
(
sprite_t
*
ingre
,
char
nom
,
int
x
,
int
y
,
int
w
,
int
h
,
int
v
,
int
state
){
init_sprite
(
ingre
,
nom
,
x
,
y
,
w
,
h
,
v
,
state
);
set_cuisson
(
ingre
,
FRIGO
);
set_invisible
(
ingre
);
}
void
init_stocks
(
stock_t
*
stocks
,
sprite_t
*
zone_stockage
){
...
...
@@ -325,7 +326,7 @@ void set_bas (sprite_t *sprite){
void
set_haut
(
sprite_t
*
sprite
){
// Sprite va vers le haut
sprite
->
etat
=
HAUT
;
sprite
->
interaction
.
y
=
sprite
->
rect
.
y
-
5
;
sprite
->
interaction
.
y
=
sprite
->
rect
.
y
-
1
5
;
sprite
->
interaction
.
x
=
sprite
->
rect
.
x
;
sprite
->
interaction
.
h
=
5
;
sprite
->
interaction
.
w
=
sprite
->
rect
.
w
;
...
...
@@ -482,11 +483,13 @@ void gestion_events(SDL_Event *event, world_t *world){
case
SDLK_SPACE
:
//Récupération des ingrédients du frigo
for
(
int
i
=
0
;
i
<
INGREDIENT_DISPO
;
i
++
){
//Interaction avec le frigo (récupérer les éléments un par un)
sprite_t
*
ingredient
=
&
world
->
en_cuisine
[
i
];
sprite_t
*
joueur
=
&
world
->
joueur
;
//Interaction avec le frigo (récupérer les éléments un par un)
if
(
has_interaction
(
joueur
,
&
world
->
frigo
)
&&
has_collided
(
&
world
->
frigo
,
ingredient
)
&&
return_state
(
ingredient
)
==
POSE
){
set_portable
(
ingredient
);
set_visible
(
ingredient
);
init_cuisson
(
ingredient
);
handle_deplacement_ingredient
(
joueur
,
ingredient
);
break
;
...
...
@@ -513,7 +516,6 @@ void gestion_events(SDL_Event *event, world_t *world){
handle_deplacement_ingredient
(
joueur
,
ingredient
);
break
;
}
if
(
has_interaction
(
joueur
,
&
world
->
lavabo
)
&&
has_collided
(
joueur
,
ingredient
)
&&
return_state
(
ingredient
)
==
PORTE
&&
get_cuisson
(
ingredient
)
==
SALE
){
//On pose un ingrédient pour le laver
...
...
@@ -521,12 +523,82 @@ void gestion_events(SDL_Event *event, world_t *world){
set_cuisson
(
ingredient
,
PROPRE
);
break
;
}
//Interaction avec la poubelle
if
(
has_interaction
(
joueur
,
&
world
->
poubelle
)
&&
has_collided
(
joueur
,
ingredient
)
&&
return_state
(
ingredient
)
==
PORTE
){
//On pose un ingrédient pour le jeter et le replacer dans le frigo
SDL_Rect
temp
=
get_rect
(
&
world
->
frigo
);
char
copy
=
ingredient
->
nom
;
init_ingre
(
ingredient
,
copy
,
temp
.
x
,
temp
.
y
,
PLAT_SIZE
,
PLAT_SIZE
,
0
,
POSE
);
break
;
}
//Interaction avec les comptoirs
for
(
int
i
=
0
;
i
<
NB_COMPT_1
;
i
++
){
if
(
has_interaction
(
joueur
,
&
world
->
comptoire
[
i
])
&&
has_collided
(
joueur
,
ingredient
)
&&
return_state
(
ingredient
)
==
POSE
){
//On retire un ingrédient
set_portable
(
ingredient
);
handle_deplacement_ingredient
(
joueur
,
ingredient
);
break
;
}
if
(
has_interaction
(
joueur
,
&
world
->
comptoire
[
i
])
&&
has_collided
(
joueur
,
ingredient
)
&&
return_state
(
ingredient
)
==
PORTE
){
//On pose un ingrédient
set_posee
(
ingredient
);
break
;
}
}
//Interaction avec la zone d'envoi et génération du score
if
(
has_interaction
(
joueur
,
&
world
->
envoi
)
&&
has_collided
(
joueur
,
ingredient
)
&&
return_state
(
ingredient
)
==
PORTE
){
//On pose un ingrédient sur la zone d'envoi, calcul du score ET on réinitialise
if
(
burger_est_complet
(
world
->
en_cuisine
)){
//On pose le burger entièrement et on calcul le score
for
(
int
i
=
0
;
i
<
INGREDIENT_DISPO
;
i
++
){
set_posee
(
&
world
->
en_cuisine
[
i
]);
calcul_score
(
&
world
->
etat_stocks
,
&
world
->
en_cuisine
[
i
]);
//Réinitialisation du sprite
SDL_Rect
temp
=
get_rect
(
&
world
->
frigo
);
char
copy
=
world
->
en_cuisine
[
i
].
nom
;
init_ingre
(
&
world
->
en_cuisine
[
i
],
copy
,
temp
.
x
,
temp
.
y
,
PLAT_SIZE
,
PLAT_SIZE
,
0
,
POSE
);
}
}
break
;
}
}
break
;
}
}
}
void
calcul_score
(
stock_t
*
stock
,
sprite_t
*
ingredient
){
if
(
get_cuisson
(
ingredient
)
==
SALE
||
get_cuisson
(
ingredient
)
==
CRU
){
stock
->
score
-=
5
;
}
else
if
(
get_cuisson
(
ingredient
)
==
PROPRE
||
get_cuisson
(
ingredient
)
==
CUIT
){
stock
->
score
+=
5
;
}
}
//INCONCERNE, FRIGO, SALE, PROPRE, CUIT, CRU, JETE}
SDL_bool
burger_est_complet
(
sprite_t
*
ingredients
){
int
compt
=
0
;
SDL_Rect
temp1
;
SDL_Rect
temp2
;
for
(
int
i
=
0
;
i
<
INGREDIENT_DISPO
;
i
++
){
temp1
=
get_rect
(
&
ingredients
[
i
]);
temp2
=
get_rect
(
&
ingredients
[
i
+
1
]);
if
(
return_state
(
&
ingredients
[
i
])
!=
FRIGO
&&
temp1
.
x
==
temp2
.
x
&&
temp1
.
y
==
temp2
.
y
)
{
compt
++
;
}
}
printf
(
"
\n
Compteur de sprite ingredients les uns sur les autres = %d"
,
compt
);
if
(
compt
==
4
){
return
SDL_TRUE
;
}
return
SDL_FALSE
;
}
char
**
init_map
(){
const
char
*
nomFichier
=
"Ressources/map.txt"
;
int
hauteur
=
SCREEN_HEIGHT
;
...
...
logique.h
View file @
ea049db7
...
...
@@ -229,6 +229,15 @@ SDL_bool has_collided (sprite_t* spr1, sprite_t* spr2);
*/
SDL_bool
has_interaction
(
sprite_t
*
spr_interact
,
sprite_t
*
spr2
);
/**
* @brief Vérifie que le burger est complet (selon sa position)
*
* @param ingredients tous les ingrédients disponible en cours
* @return SDL_bool
*/
SDL_bool
burger_est_complet
(
sprite_t
*
ingredients
);
/**
* \brief Vérifie si deux sprites sont en collisions
* \param spr_move Sprite capable de se déplacer
...
...
@@ -252,6 +261,14 @@ void handle_deplacement_ingredient (sprite_t* joueur, sprite_t* ingredient);
*/
int
get_score
(
stock_t
*
stocks
);
/**
* @brief Calcul le score de la partie
*
* @param stock données de stocks / de score
* @param ingredient données du sprite
*/
void
calcul_score
(
stock_t
*
stock
,
sprite_t
*
ingredient
);
/**
* \brief Gère les collisions du jeu
* \param world Données du monde
...
...
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