Skip to content
Snippets Groups Projects
Commit 62705a29 authored by vautrin33u's avatar vautrin33u
Browse files

Constantes: tailles décidés / pb de limites externes (bas surtout)

parent 0d3ddc4f
No related branches found
No related tags found
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -39,4 +39,71 @@ ...@@ -39,4 +39,71 @@
* */ * */
#define SIZE_JOUEUR 50 #define SIZE_JOUEUR 50
/**
* \brief Taille des plats
*/
#define PLAT_SIZE 25
// TAILLES ELEMENT CUISINES:
/**
* \brief taille des murs
* */
#define SIZE_MUR 50
/**
* \brief Largeur du frigo
* */
#define FRIGO_LARGEUR 150
/**
* \brief Hauteur du frigo
* */
#define FRIGO_HAUTEUR 100
/**
* \brief Largeur du lavabo
* */
#define LAVABO_LARGEUR 150
/**
* \brief Hauteur du lavabo
* */
#define LAVABO_HAUTEUR 100
/**
* \brief Largeur du four
* */
#define FOUR_LARGEUR 150
/**
* \brief Hauteur du four
* */
#define FOUR_HAUTEUR 100
/**
* \brief taille comptoir
* */
#define BLOC_COMPT_SIZE 100
/**
* \brief Largeur de la zone d'envoi
* */
#define ZONE_ENVOI_LARGEUR 100
/**
* \brief Hauteur de la zone d'envoi
* */
#define ZONE_ENVOI_HAUTEUR 50
/**
* \brief Largeur de la poubelle
* */
#define POUBELLE_LARGEUR 100
/**
* \brief Hauteur de la poubelle
* */
#define POUBELLE_HAUTEUR 100
#endif #endif
\ No newline at end of file
...@@ -25,6 +25,13 @@ void apply_background (SDL_Renderer *renderer, textures_t *textures){ ...@@ -25,6 +25,13 @@ void apply_background (SDL_Renderer *renderer, textures_t *textures){
} }
} }
void apply_player (SDL_Renderer *renderer, textures_t *textures){
// applique la texture du joueur
if (textures->joueur !=NULL){
SDL_RenderCopy(renderer, textures->fond, create_SDL_rect_from_texture(textures->joueur), NULL); // faux
}
}
void colorier_rect (SDL_Renderer *renderer, SDL_Rect rectangle, SDL_Color couleur){ void colorier_rect (SDL_Renderer *renderer, SDL_Rect rectangle, SDL_Color couleur){
SDL_SetRenderDrawColor(renderer, couleur.r, couleur.g, couleur.b, couleur.a); SDL_SetRenderDrawColor(renderer, couleur.r, couleur.g, couleur.b, couleur.a);
for (int i=0; i<rectangle.y; i++){ for (int i=0; i<rectangle.y; i++){
...@@ -34,14 +41,22 @@ void colorier_rect (SDL_Renderer *renderer, SDL_Rect rectangle, SDL_Color couleu ...@@ -34,14 +41,22 @@ void colorier_rect (SDL_Renderer *renderer, SDL_Rect rectangle, SDL_Color couleu
} }
} }
const SDL_Rect * create_SDL_rect_from_texture (SDL_Texture * texture){
//Permet de créer un SDL_rect retournant la texture de la taille de la texture (SOURCE)
SDL_Rect* rectangle;
int w;
int h;
SDL_QueryTexture(texture, NULL, NULL, &w, &h);
return create_SDL_rect (0, 0, w, h);
}
SDL_Rect create_SDL_rect (int x, int y, int w, int h){ const SDL_Rect* create_SDL_rect (int x, int y, int w, int h){
//revoir le type, potentiellement faux //permet de créer un SDL_rect en connaissant déjà les coordonnées
SDL_Rect rectangle; SDL_Rect* rectangle;
rectangle.x = x; rectangle->x = x;
rectangle.y = y; rectangle->y = y;
rectangle.w = w; rectangle->w = w;
rectangle.h = h; rectangle->h = h;
return rectangle; return rectangle;
} }
......
...@@ -55,7 +55,15 @@ void apply_background (SDL_Renderer *renderer, textures_t *textures); ...@@ -55,7 +55,15 @@ void apply_background (SDL_Renderer *renderer, textures_t *textures);
* @param h hauteur * @param h hauteur
* @return SDL_Rect * @return SDL_Rect
*/ */
SDL_Rect create_SDL_rect (int x, int y, int w, int h); const SDL_Rect * create_SDL_rect (int x, int y, int w, int h);
/**
* @brief Créer un SDL_rect retournant la texture de la taille de la texture (SOURCE)
*
* @param texture
* @return SDL_Rect représentant l'image source tel quel
*/
const SDL_Rect * create_SDL_rect_from_texture (SDL_Texture * texture);
/** /**
* @brief Colorie un rectangle d'une couleur donnée * @brief Colorie un rectangle d'une couleur donnée
......
...@@ -17,12 +17,11 @@ void init_data(world_t * world){ //faux ...@@ -17,12 +17,11 @@ void init_data(world_t * world){ //faux
world->attente = 0; world->attente = 0;
//Initialise le sprite du joueur en haut à gauche de l'écran, en état 0 //Initialise le sprite du joueur en haut à gauche de l'écran, en état 0
init_sprite(&world->joueur, 'J', 200, 200, SIZE_JOUEUR, SIZE_JOUEUR, SIZE_JOUEUR/2, 0); init_sprite(&world->joueur, 'J', 200, 200, SIZE_JOUEUR, SIZE_JOUEUR, 10, 0);
//Charge la carte //Charge la carte
world->map = init_map(); world->map = init_map();
/* /*
init_sprite(&world->ship, SCREEN_WIDTH/2, SCREEN_HEIGHT-SHIP_SIZE, SHIP_SIZE, SHIP_SIZE, MOVING_STEP); init_sprite(&world->ship, SCREEN_WIDTH/2, SCREEN_HEIGHT-SHIP_SIZE, SHIP_SIZE, SHIP_SIZE, MOVING_STEP);
...@@ -105,7 +104,7 @@ void limites_externes (sprite_t *sprite, world_t *world){ ...@@ -105,7 +104,7 @@ void limites_externes (sprite_t *sprite, world_t *world){
if (sprite->y > (SCREEN_HEIGHT*0.9)){ if (sprite->y > (SCREEN_HEIGHT*0.9)){
//mur bas //mur bas
sprite->y = (SCREEN_HEIGHT*0.9) - sprite->w/2; sprite->y = (SCREEN_HEIGHT*0.9) - sprite->w;
} }
if (sprite->y < (SCREEN_HEIGHT*0.1)){ if (sprite->y < (SCREEN_HEIGHT*0.1)){
...@@ -192,13 +191,13 @@ void deplace_droite (sprite_t *sprite, world_t *world){ ...@@ -192,13 +191,13 @@ void deplace_droite (sprite_t *sprite, world_t *world){
void deplace_gauche (sprite_t *sprite, world_t *world){ void deplace_gauche (sprite_t *sprite, world_t *world){
int compteur =0; int compteur =0;
set_gauche(&world->joueur); set_gauche(sprite);
world->joueur.x -= world->joueur.v; sprite->x -= sprite->v;
reset_sprite_on_map(sprite, world); reset_sprite_on_map(sprite, world);
//déplace vers la gauche //déplace vers la gauche
if (world->map[sprite->y][sprite->x] != ' ' || world->map[sprite->y + SIZE_JOUEUR][sprite->x] != ' '){ if (world->map[sprite->y][sprite->x] != ' ' || world->map[sprite->y + sprite->h][sprite->x] != ' '){
//Compter le nombre d'espace avant d'arriver au bloc, et placer le joueur contre le bloc interdit //Compter le nombre d'espace avant d'arriver au bloc, et placer le joueur contre le bloc interdit
for (int x= sprite->x; x<SIZE_JOUEUR; x++){ for (int x= sprite->x; x<sprite->w; x++){
if (world->map[sprite->y][x] != ' '){ if (world->map[sprite->y][x] != ' '){
compteur++; compteur++;
} }
...@@ -206,12 +205,12 @@ void deplace_gauche (sprite_t *sprite, world_t *world){ ...@@ -206,12 +205,12 @@ void deplace_gauche (sprite_t *sprite, world_t *world){
sprite->x += compteur; sprite->x += compteur;
} }
} }
void gestion_events(SDL_Event *event, world_t *world){ void gestion_events(SDL_Event *event, world_t *world){
Uint8 *keystates;
while (SDL_PollEvent(event)){ SDL_PollEvent(event);
switch(event->type){ switch(event->type){
case SDL_QUIT: case SDL_QUIT:
world->gameover = 1; break; world->gameover = 1; break;
...@@ -222,7 +221,6 @@ void gestion_events(SDL_Event *event, world_t *world){ ...@@ -222,7 +221,6 @@ void gestion_events(SDL_Event *event, world_t *world){
//Déplacement du joueur //Déplacement du joueur
case SDLK_UP: case SDLK_UP:
deplace_haut(&world->joueur, world); deplace_haut(&world->joueur, world);
printf("BOUUUUUUUUH \n");
break; break;
case SDLK_DOWN: case SDLK_DOWN:
...@@ -231,7 +229,6 @@ void gestion_events(SDL_Event *event, world_t *world){ ...@@ -231,7 +229,6 @@ void gestion_events(SDL_Event *event, world_t *world){
case SDLK_RIGHT: case SDLK_RIGHT:
deplace_droite(&world->joueur, world); deplace_droite(&world->joueur, world);
break; break;
case SDLK_LEFT: case SDLK_LEFT:
...@@ -241,7 +238,7 @@ void gestion_events(SDL_Event *event, world_t *world){ ...@@ -241,7 +238,7 @@ void gestion_events(SDL_Event *event, world_t *world){
} }
} }
} printf("Sprite joueur : x : %d | y: %d \n", world->joueur.x, world->joueur.y);
} }
......
...@@ -37,7 +37,7 @@ if (windows == NULL) { ...@@ -37,7 +37,7 @@ if (windows == NULL) {
} }
//Chargement de l'état initial du jeu //Chargement de l'état initial du jeu
//init_data(&world); init_data(&world);
//Chargement des textures sur le renderer //Chargement des textures sur le renderer
ecran = SDL_CreateRenderer(windows, -1, SDL_RENDERER_ACCELERATED); ecran = SDL_CreateRenderer(windows, -1, SDL_RENDERER_ACCELERATED);
...@@ -51,10 +51,8 @@ while (estFini(&world)==0){ ...@@ -51,10 +51,8 @@ while (estFini(&world)==0){
//Gestion des évenements (entrées joueurs) //Gestion des évenements (entrées joueurs)
gestion_events(&evenements, &world); gestion_events(&evenements, &world);
update_data(&world); update_data(&world);
//update_graphics(ecran, &world, &textures); update_graphics(ecran, &world, &textures);
SDL_Delay(10);
SDL_RenderPresent(ecran); // Récupère les infos actualisés de render et les affiches SDL_RenderPresent(ecran); // Récupère les infos actualisés de render et les affiches
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment