delay add for update and time add in game
This commit is contained in:
68
display.c
68
display.c
@@ -26,9 +26,10 @@ void screenDisplay (unsigned short int **tab, int size)
|
||||
|
||||
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;
|
||||
unsigned int marge = display_user->size_menu /2;
|
||||
unsigned int marge = display_user->size_menu / 2;
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0; i < display_user->size_box; ++i)
|
||||
@@ -37,7 +38,7 @@ void screenDisplayGameSDL (unsigned short int **tab, dis *display_user)
|
||||
{
|
||||
SDL_Surface *img;
|
||||
SDL_Texture *texture;
|
||||
vect pos = { i * size + marge, j * size};
|
||||
vect pos = { i * size + marge, j * size };
|
||||
switch (tab[j][i])
|
||||
{
|
||||
case EMPTY:
|
||||
@@ -88,15 +89,15 @@ int getMaxSize (dis display_user)
|
||||
result = display.h;
|
||||
}
|
||||
SDL_Quit ();
|
||||
int minus_mod = (result-50) % display_user.size_box;
|
||||
//printf("DIS :%d, size : %d ,mod : %d\n",result, size_box,minus_mod);
|
||||
return (result - 50 - minus_mod); // margin
|
||||
int minus_mod = (result - 50) % display_user.size_box;
|
||||
// printf("DIS :%d, size : %d ,mod : %d\n",result, size_box,minus_mod);
|
||||
return (result - 50 - minus_mod); // margin
|
||||
}
|
||||
|
||||
void initSDL (dis *display_user)
|
||||
{
|
||||
SDL_Init (SDL_INIT_VIDEO);
|
||||
TTF_Init();
|
||||
TTF_Init ();
|
||||
display_user->window
|
||||
= SDL_CreateWindow ("Sokoman", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, display_user->size_window,
|
||||
@@ -125,37 +126,46 @@ void displayImage (SDL_Renderer *renderer, SDL_Texture *texture, vect pos,
|
||||
SDL_RenderCopy (renderer, texture, NULL, &rect);
|
||||
}
|
||||
|
||||
|
||||
void displayTextSDL(dis *display_user,char *text, vect coor, vect size, int font_size)
|
||||
void displayTextSDL (dis *display_user, char *text, vect coor, vect size,
|
||||
int font_size)
|
||||
{
|
||||
TTF_Font* Sans = TTF_OpenFont("Roboto-Regular.ttf", font_size);
|
||||
system("pwd");
|
||||
printf("%p\n", Sans);
|
||||
SDL_Color white = {255,0,0,255};
|
||||
TTF_Font *Sans = TTF_OpenFont ("Roboto-Regular.ttf", font_size);
|
||||
SDL_Color white = { 255, 255, 255, 255 };
|
||||
int text_width, text_height;
|
||||
|
||||
SDL_Rect background;
|
||||
SDL_Surface *surface_text = TTF_RenderText_Solid (Sans, text, white);
|
||||
|
||||
SDL_Surface* surface_text = TTF_RenderText_Solid(Sans, text, white);
|
||||
|
||||
SDL_Texture* message = SDL_CreateTextureFromSurface(display_user->renderer, surface_text);
|
||||
|
||||
TTF_SizeText(Sans, text, &text_height, &text_width);
|
||||
SDL_Rect message_rect ;
|
||||
TTF_SizeText (Sans, text, &text_height, &text_width);
|
||||
SDL_Rect message_rect;
|
||||
message_rect.x = coor.x;
|
||||
message_rect.y = coor.y;
|
||||
message_rect.w = text_height;
|
||||
message_rect.h = text_width;
|
||||
background.x = coor.x;
|
||||
background.y = coor.y;
|
||||
background.w = text_height;
|
||||
background.h = text_width;
|
||||
|
||||
if (message_rect.w > size.y) message_rect.w = size.y;
|
||||
if (message_rect.h > size.x) message_rect.h = size.x;
|
||||
if (message_rect.w > size.y)
|
||||
{
|
||||
message_rect.w = size.y;
|
||||
background.w = size.y;
|
||||
}
|
||||
if (message_rect.h > size.x)
|
||||
{
|
||||
message_rect.h = size.x;
|
||||
background.h = size.x;
|
||||
}
|
||||
|
||||
printf("%d, %d", message_rect.w, message_rect.h);
|
||||
SDL_RenderCopy(display_user-> renderer, message, NULL, &message_rect);
|
||||
SDL_RenderPresent(display_user->renderer);
|
||||
puts("Fa it");
|
||||
SDL_Texture *message
|
||||
= SDL_CreateTextureFromSurface (display_user->renderer, surface_text);
|
||||
SDL_SetRenderDrawColor(display_user->renderer, 0, 0, 0, 255);
|
||||
SDL_RenderFillRect(display_user->renderer, &background);
|
||||
|
||||
SDL_FreeSurface(surface_text);
|
||||
SDL_DestroyTexture(message);
|
||||
SDL_RenderCopy (display_user->renderer, message, NULL, &message_rect);
|
||||
SDL_RenderPresent (display_user->renderer);
|
||||
|
||||
SDL_FreeSurface (surface_text);
|
||||
SDL_DestroyTexture (message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user