ajout de affichage de texte
This commit is contained in:
BIN
Roboto-Regular.ttf
Executable file
BIN
Roboto-Regular.ttf
Executable file
Binary file not shown.
21
display.c
21
display.c
@@ -8,6 +8,7 @@
|
|||||||
#include <SDL2/SDL_surface.h>
|
#include <SDL2/SDL_surface.h>
|
||||||
#include <SDL2/SDL_ttf.h>
|
#include <SDL2/SDL_ttf.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
void screenDisplay (unsigned short int **tab, int size)
|
void screenDisplay (unsigned short int **tab, int size)
|
||||||
{
|
{
|
||||||
@@ -95,6 +96,7 @@ int getMaxSize (dis display_user)
|
|||||||
void initSDL (dis *display_user)
|
void initSDL (dis *display_user)
|
||||||
{
|
{
|
||||||
SDL_Init (SDL_INIT_VIDEO);
|
SDL_Init (SDL_INIT_VIDEO);
|
||||||
|
TTF_Init();
|
||||||
display_user->window
|
display_user->window
|
||||||
= SDL_CreateWindow ("Sokoman", SDL_WINDOWPOS_CENTERED,
|
= SDL_CreateWindow ("Sokoman", SDL_WINDOWPOS_CENTERED,
|
||||||
SDL_WINDOWPOS_CENTERED, display_user->size_window,
|
SDL_WINDOWPOS_CENTERED, display_user->size_window,
|
||||||
@@ -126,20 +128,31 @@ void displayImage (SDL_Renderer *renderer, SDL_Texture *texture, vect pos,
|
|||||||
|
|
||||||
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("Sans.ttf", 24);
|
TTF_Font* Sans = TTF_OpenFont("Roboto-Regular.ttf", font_size);
|
||||||
SDL_Color white = {255,255,255};
|
system("pwd");
|
||||||
|
printf("%p\n", Sans);
|
||||||
|
SDL_Color white = {255,0,0,255};
|
||||||
|
int text_width, text_height;
|
||||||
|
|
||||||
|
|
||||||
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);
|
SDL_Texture* message = SDL_CreateTextureFromSurface(display_user->renderer, surface_text);
|
||||||
|
|
||||||
|
TTF_SizeText(Sans, text, &text_height, &text_width);
|
||||||
SDL_Rect message_rect ;
|
SDL_Rect message_rect ;
|
||||||
message_rect.x = coor.x;
|
message_rect.x = coor.x;
|
||||||
message_rect.y = coor.y;
|
message_rect.y = coor.y;
|
||||||
message_rect.w = size.x;
|
message_rect.w = text_height;
|
||||||
message_rect.h = size.y;
|
message_rect.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;
|
||||||
|
|
||||||
|
printf("%d, %d", message_rect.w, message_rect.h);
|
||||||
SDL_RenderCopy(display_user-> renderer, message, NULL, &message_rect);
|
SDL_RenderCopy(display_user-> renderer, message, NULL, &message_rect);
|
||||||
|
SDL_RenderPresent(display_user->renderer);
|
||||||
|
puts("Fa it");
|
||||||
|
|
||||||
SDL_FreeSurface(surface_text);
|
SDL_FreeSurface(surface_text);
|
||||||
SDL_DestroyTexture(message);
|
SDL_DestroyTexture(message);
|
||||||
|
|||||||
10
main.c
10
main.c
@@ -7,7 +7,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define SIZE_PLAY 5
|
#define SIZE_PLAY 19
|
||||||
#define SIZE_MENU 200;
|
#define SIZE_MENU 200;
|
||||||
|
|
||||||
int main ()
|
int main ()
|
||||||
@@ -27,11 +27,11 @@ int main ()
|
|||||||
playerScore.before = time (NULL);
|
playerScore.before = time (NULL);
|
||||||
|
|
||||||
targets
|
targets
|
||||||
= fileToTab2D ("test3.txt", tab2d, SIZE_PLAY, playerPos, &nbr_targets);
|
= fileToTab2D ("test.txt", tab2d, SIZE_PLAY, playerPos, &nbr_targets);
|
||||||
screenDisplayGameSDL (tab2d, &display_user);
|
screenDisplayGameSDL (tab2d, &display_user);
|
||||||
vect size = {100, 100};
|
vect size = {display_user.size_menu , display_user.size_window / 3};
|
||||||
vect pos = {900, 0};
|
vect pos = {0, display_user.size_window - display_user.size_menu};
|
||||||
displayTextSDL(&display_user, "213", pos, size, 24);
|
displayTextSDL(&display_user, "Time 20:4345999", pos, size, 69);
|
||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user