delay add for update and time add in game
This commit is contained in:
25
function.c
25
function.c
@@ -5,9 +5,11 @@
|
||||
#include <SDL2/SDL_keycode.h>
|
||||
#include <SDL2/SDL_render.h>
|
||||
#include <SDL2/SDL_scancode.h>
|
||||
#include <SDL2/SDL_timer.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
unsigned short int **creatArea2D (const unsigned int N)
|
||||
{
|
||||
@@ -186,6 +188,11 @@ void move (unsigned short int **tab, vect *playerPos, vect direction)
|
||||
void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos,
|
||||
vect *targets, int nbr_targets, dis *display_user)
|
||||
{
|
||||
vect size_time = {display_user->size_menu , display_user->size_window / 3};
|
||||
vect coor_time = {0, display_user->size_window - display_user->size_menu};
|
||||
time_t time_start = time(NULL) ;
|
||||
time_t current_time = time(NULL);
|
||||
time_t delay = 0;
|
||||
char last = SDL_SCANCODE_1;
|
||||
vect direction = { 0, 0 };
|
||||
char input;
|
||||
@@ -241,6 +248,14 @@ void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos,
|
||||
screenDisplayGameSDL (tab2d, display_user);
|
||||
}
|
||||
last = SDL_SCANCODE_F21;
|
||||
current_time = time(NULL);
|
||||
if (current_time > delay)
|
||||
{
|
||||
delay = current_time;
|
||||
displayTextSDL(display_user, timeToText(time(NULL) - time_start), coor_time, size_time, 50);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,3 +408,13 @@ bool blockBox (unsigned short int **tab2d, vect box_coor)
|
||||
perror ("error in blockBox");
|
||||
exit (0);
|
||||
}
|
||||
|
||||
char *timeToText(time_t time)
|
||||
{
|
||||
char* result = calloc(20, sizeof(char));
|
||||
result[0] = '\0';
|
||||
unsigned int min = time / 60;
|
||||
unsigned int sec = time % 60;
|
||||
snprintf(result, 20,"Time : %02d:%02d",min, sec);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user