fix probleme zone de jeu
This commit is contained in:
4
Makefile
4
Makefile
@@ -1,7 +1,7 @@
|
|||||||
# Variable
|
# Variable
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -Wall -Wextra $(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)
|
LIBFLAGS = $(shell pkg-config --cflags --libs sdl2 SDL2_image SDL2_ttf)
|
||||||
OBJ = main.o function.o display.o read.o
|
OBJ = main.o function.o display.o read.o
|
||||||
TARGET = sokoban
|
TARGET = sokoban
|
||||||
|
|
||||||
|
|||||||
25
display.c
25
display.c
@@ -6,6 +6,7 @@
|
|||||||
#include <SDL2/SDL_rect.h>
|
#include <SDL2/SDL_rect.h>
|
||||||
#include <SDL2/SDL_render.h>
|
#include <SDL2/SDL_render.h>
|
||||||
#include <SDL2/SDL_surface.h>
|
#include <SDL2/SDL_surface.h>
|
||||||
|
#include <SDL2/SDL_ttf.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
void screenDisplay (unsigned short int **tab, int size)
|
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;
|
unsigned int display_game = display_user->size_window - display_user->size_menu;
|
||||||
int size = display_game / display_user->size_box;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,15 @@
|
|||||||
|
|
||||||
#include "function.h"
|
#include "function.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include <SDL2/SDL_ttf.h>
|
||||||
|
|
||||||
void screenDisplay (unsigned short int **tab, int size);
|
void screenDisplay (unsigned short int **tab, int size);
|
||||||
int getMaxSize (dis display_user);
|
int getMaxSize (dis display_user);
|
||||||
void displayImage (SDL_Renderer *renderer, SDL_Texture *texture, vect pos,
|
void displayImage (SDL_Renderer *renderer, SDL_Texture *texture, vect pos,
|
||||||
int size);
|
int size);
|
||||||
void initSDL (dis *display_user);
|
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
|
#endif // !DISPLAY_H
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ unsigned short int **creatArea2D (const unsigned int N)
|
|||||||
void free2D (unsigned short int **tab, int N)
|
void free2D (unsigned short int **tab, int N)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < N; ++i)
|
for (i = 0; i < N ; ++i)
|
||||||
{
|
{
|
||||||
free (tab[i]);
|
free (tab[i]);
|
||||||
}
|
}
|
||||||
@@ -238,7 +238,7 @@ void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos,
|
|||||||
puts ("lose!");
|
puts ("lose!");
|
||||||
finish = true;
|
finish = true;
|
||||||
}
|
}
|
||||||
screenDisplaySDL (tab2d, display_user);
|
screenDisplayGameSDL (tab2d, display_user);
|
||||||
}
|
}
|
||||||
last = SDL_SCANCODE_F21;
|
last = SDL_SCANCODE_F21;
|
||||||
}
|
}
|
||||||
|
|||||||
9
main.c
9
main.c
@@ -7,7 +7,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define SIZE_PLAY 26
|
#define SIZE_PLAY 5
|
||||||
#define SIZE_MENU 200;
|
#define SIZE_MENU 200;
|
||||||
|
|
||||||
int main ()
|
int main ()
|
||||||
@@ -27,8 +27,11 @@ int main ()
|
|||||||
playerScore.before = time (NULL);
|
playerScore.before = time (NULL);
|
||||||
|
|
||||||
targets
|
targets
|
||||||
= fileToTab2D ("test.txt", tab2d, SIZE_PLAY, playerPos, &nbr_targets);
|
= fileToTab2D ("test3.txt", tab2d, SIZE_PLAY, playerPos, &nbr_targets);
|
||||||
screenDisplaySDL (tab2d, &display_user);
|
screenDisplayGameSDL (tab2d, &display_user);
|
||||||
|
vect size = {100, 100};
|
||||||
|
vect pos = {900, 0};
|
||||||
|
displayTextSDL(&display_user, "213", pos, size, 24);
|
||||||
screenDisplay (tab2d, SIZE_PLAY);
|
screenDisplay (tab2d, SIZE_PLAY);
|
||||||
inGameLoop (tab2d, SIZE_PLAY, playerPos, targets, nbr_targets,
|
inGameLoop (tab2d, SIZE_PLAY, playerPos, targets, nbr_targets,
|
||||||
&display_user);
|
&display_user);
|
||||||
|
|||||||
11
read.c
11
read.c
@@ -8,10 +8,15 @@ vect *fileToTab2D (const char *name_file, unsigned short int **tab,
|
|||||||
vect *targets = malloc (sizeof (vect));
|
vect *targets = malloc (sizeof (vect));
|
||||||
(*nbr_targets) = 0;
|
(*nbr_targets) = 0;
|
||||||
FILE *file = fopen (name_file, "r");
|
FILE *file = fopen (name_file, "r");
|
||||||
unsigned int x = 0, y = 1;
|
unsigned int x = 0, y = 0;
|
||||||
while (!feof (file))
|
while (!feof (file))
|
||||||
{
|
{
|
||||||
char current = fgetc (file);
|
char current = fgetc (file);
|
||||||
|
|
||||||
|
if (current == EOF)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
switch (current)
|
switch (current)
|
||||||
{
|
{
|
||||||
case '#':
|
case '#':
|
||||||
@@ -32,7 +37,7 @@ vect *fileToTab2D (const char *name_file, unsigned short int **tab,
|
|||||||
tab[x][y] = PLAYER;
|
tab[x][y] = PLAYER;
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
y = 0;
|
y = -1;
|
||||||
++x;
|
++x;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -41,7 +46,7 @@ vect *fileToTab2D (const char *name_file, unsigned short int **tab,
|
|||||||
}
|
}
|
||||||
++y;
|
++y;
|
||||||
|
|
||||||
if (x >= N || y >= N)
|
if (x > N || y > N)
|
||||||
{
|
{
|
||||||
perror ("Level out of range !");
|
perror ("Level out of range !");
|
||||||
exit (-1);
|
exit (-1);
|
||||||
|
|||||||
Reference in New Issue
Block a user