Skip to content
Snippets Groups Projects
Commit a7824c52 authored by Kaan.Korucan's avatar Kaan.Korucan
Browse files

add timer

parent e3604279
No related branches found
No related tags found
4 merge requests!9Modele,!8Modele,!7Modele,!6Modele
/*
// Created by Kaan on 9.04.2021.
*/
#ifndef INSAGAME_TIMER_H
#define INSAGAME_TIMER_H
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <time.h>
#include <SDL2/SDL_ttf.h>
void init_timer();
SDL_Texture * query_timer(SDL_Renderer *renderer, TTF_Font* Sans, SDL_Rect* timer_rect, int* close_request, SDL_Window * window);
#endif /*INSAGAME_TIMER_H*/
File added
/*
// Created by Kaan on 9.04.2021.
*/
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <time.h>
#include <SDL2/SDL_ttf.h>
#include "timer.h"
clock_t begin;
int time_spent;
int seconde=30;
int time_remaining;
char timerString[10];
void init_timer(){
TTF_Init();
begin=clock();
}
SDL_Texture * query_timer(SDL_Renderer *renderer, TTF_Font* Sans, SDL_Rect* timer_rect, int* close_request, SDL_Window * window){
SDL_Color white = {255, 255, 255}; // text's color
time_spent = (clock() - begin) / CLOCKS_PER_SEC;
time_remaining=seconde-time_spent;
itoa(time_remaining, timerString, 10);
Sans = TTF_OpenFont("../ressource/OpenSans-Semibold.ttf", 8); //font style and sets a size
TTF_SetFontStyle(Sans, 2);
SDL_Surface* tim = TTF_RenderText_Solid(Sans, timerString , white);
SDL_Texture* texture_timer = SDL_CreateTextureFromSurface(renderer, tim);
SDL_FreeSurface(tim);
// draw the image to the window
if (!texture_timer)
{
printf("error creating texture: %s\n", SDL_GetError());
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return NULL;
}
timer_rect->x = 20; //controls the rect's x coordinate
timer_rect->y = 20; // controls the rect's y coordinte
timer_rect->w = 50; // controls the width of the rect
timer_rect->h = 50; // controls the height of the rect
if(time_remaining==0){
*close_request=1;
}
return texture_timer;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment