fix probleme zone de jeu

This commit is contained in:
2024-12-15 18:56:12 +01:00
parent c5c2949538
commit ce2acefbc5
7 changed files with 52 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
# Variable
CC = gcc
CFLAGS = -Wall -Wextra $(shell pkg-config --cflags --libs sdl2 SDL2_image)
LIBFLAGS = $(shell pkg-config --cflags --libs sdl2 SDL2_image)
CFLAGS = -Wall -Wextra $(shell pkg-config --cflags --libs sdl2 SDL2_image SDL2_ttf)
LIBFLAGS = $(shell pkg-config --cflags --libs sdl2 SDL2_image SDL2_ttf)
OBJ = main.o function.o display.o read.o
TARGET = sokoban

View File

@@ -6,6 +6,7 @@
#include <SDL2/SDL_rect.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_surface.h>
#include <SDL2/SDL_ttf.h>
#include <stdio.h>
void screenDisplay (unsigned short int **tab, int size)
@@ -22,7 +23,7 @@ void screenDisplay (unsigned short int **tab, int size)
}
}
void screenDisplaySDL (unsigned short int **tab, dis *display_user)
void screenDisplayGameSDL (unsigned short int **tab, dis *display_user)
{
unsigned int display_game = display_user->size_window - display_user->size_menu;
int size = display_game / display_user->size_box;
@@ -123,3 +124,25 @@ void displayImage (SDL_Renderer *renderer, SDL_Texture *texture, vect pos,
}
void displayTextSDL(dis *display_user,char *text, vect coor, vect size, int font_size)
{
TTF_Font* Sans = TTF_OpenFont("Sans.ttf", 24);
SDL_Color white = {255,255,255};
SDL_Surface* surface_text = TTF_RenderText_Solid(Sans, text, white);
SDL_Texture* message = SDL_CreateTextureFromSurface(display_user->renderer, surface_text);
SDL_Rect message_rect ;
message_rect.x = coor.x;
message_rect.y = coor.y;
message_rect.w = size.x;
message_rect.h = size.y;
SDL_RenderCopy(display_user-> renderer, message, NULL, &message_rect);
SDL_FreeSurface(surface_text);
SDL_DestroyTexture(message);
}

View File

@@ -3,12 +3,15 @@
#include "function.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
void screenDisplay (unsigned short int **tab, int size);
int getMaxSize (dis display_user);
void displayImage (SDL_Renderer *renderer, SDL_Texture *texture, vect pos,
int size);
void initSDL (dis *display_user);
void screenDisplaySDL (unsigned short int **tab, dis *display_user);
void screenDisplayGameSDL (unsigned short int **tab, dis *display_user);
void displayTextSDL(dis *display_user,char *text, vect coor, vect size, int font_size);
#endif // !DISPLAY_H

View File

@@ -238,7 +238,7 @@ void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos,
puts ("lose!");
finish = true;
}
screenDisplaySDL (tab2d, display_user);
screenDisplayGameSDL (tab2d, display_user);
}
last = SDL_SCANCODE_F21;
}

9
main.c
View File

@@ -7,7 +7,7 @@
#include <stdio.h>
#include <time.h>
#define SIZE_PLAY 26
#define SIZE_PLAY 5
#define SIZE_MENU 200;
int main ()
@@ -27,8 +27,11 @@ int main ()
playerScore.before = time (NULL);
targets
= fileToTab2D ("test.txt", tab2d, SIZE_PLAY, playerPos, &nbr_targets);
screenDisplaySDL (tab2d, &display_user);
= fileToTab2D ("test3.txt", tab2d, SIZE_PLAY, playerPos, &nbr_targets);
screenDisplayGameSDL (tab2d, &display_user);
vect size = {100, 100};
vect pos = {900, 0};
displayTextSDL(&display_user, "213", pos, size, 24);
screenDisplay (tab2d, SIZE_PLAY);
inGameLoop (tab2d, SIZE_PLAY, playerPos, targets, nbr_targets,
&display_user);

11
read.c
View File

@@ -8,10 +8,15 @@ vect *fileToTab2D (const char *name_file, unsigned short int **tab,
vect *targets = malloc (sizeof (vect));
(*nbr_targets) = 0;
FILE *file = fopen (name_file, "r");
unsigned int x = 0, y = 1;
unsigned int x = 0, y = 0;
while (!feof (file))
{
char current = fgetc (file);
if (current == EOF)
{
break;
}
switch (current)
{
case '#':
@@ -32,7 +37,7 @@ vect *fileToTab2D (const char *name_file, unsigned short int **tab,
tab[x][y] = PLAYER;
break;
case '\n':
y = 0;
y = -1;
++x;
break;
default:
@@ -41,7 +46,7 @@ vect *fileToTab2D (const char *name_file, unsigned short int **tab,
}
++y;
if (x >= N || y >= N)
if (x > N || y > N)
{
perror ("Level out of range !");
exit (-1);

5
test3.txt Normal file
View File

@@ -0,0 +1,5 @@
#####
#PCI#
#####
#####
#####