Skip to content
Snippets Groups Projects
Commit 519d3166 authored by Taha Belkhiri's avatar Taha Belkhiri
Browse files

ajout animation crowd.png et affichage des fps

parent 83c3852a
No related branches found
No related tags found
No related merge requests found
File added
travail_de_groupe/jeu_appren_par_renfo/Res/crowd.png

572 B | W: | H:

travail_de_groupe/jeu_appren_par_renfo/Res/crowd.png

1.19 KiB | W: | H:

travail_de_groupe/jeu_appren_par_renfo/Res/crowd.png
travail_de_groupe/jeu_appren_par_renfo/Res/crowd.png
travail_de_groupe/jeu_appren_par_renfo/Res/crowd.png
travail_de_groupe/jeu_appren_par_renfo/Res/crowd.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -17,6 +17,8 @@ SDL_Texture * crowdTexture; ...@@ -17,6 +17,8 @@ SDL_Texture * crowdTexture;
int ** rays; int ** rays;
int raysListLength = 0; int raysListLength = 0;
float fps;
SDL_Texture * loadTexture(char * path) { SDL_Texture * loadTexture(char * path) {
SDL_Surface * surface = IMG_Load(path); SDL_Surface * surface = IMG_Load(path);
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface); SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
...@@ -115,6 +117,7 @@ void drawRayColumn(float ra, float distT, int r, int isTransparent, int directio ...@@ -115,6 +117,7 @@ void drawRayColumn(float ra, float distT, int r, int isTransparent, int directio
} }
else { else {
destRect.x += + 64 * (SDL_GetTicks()/400 % 4);
if (direction){ if (direction){
SDL_RenderCopy(renderer, crowdTexture, &destRect, &rect); SDL_RenderCopy(renderer, crowdTexture, &destRect, &rect);
//SDL_SetRenderDrawColor(renderer, 255 * (1 - isTransparent), 255, 0, 255 * (1 - isTransparent)); //SDL_SetRenderDrawColor(renderer, 255 * (1 - isTransparent), 255, 0, 255 * (1 - isTransparent));
...@@ -381,11 +384,31 @@ void drawMap2D(int map[][MAP_WIDTH]){ ...@@ -381,11 +384,31 @@ void drawMap2D(int map[][MAP_WIDTH]){
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
} }
void drawString(char *str, int x, int y, int w, int h, int r, int g, int b, int a){
SDL_Color color = {r, g, b, a};
SDL_Surface *text = TTF_RenderText_Solid(RobotoFont, str, color);
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, text);
rect.x = x;
rect.y = y;
rect.w = w;
rect.h = h;
SDL_RenderCopy(renderer, texture, NULL, &rect);
SDL_FreeSurface(text);
SDL_DestroyTexture(texture);
}
void drawFPS(){
char str[10];
sprintf(str, "%d", (int)fps);
drawString(str, screenDimension.w - 50, 0, 50, 50, 255, 255, 255, 255);
}
void drawGame(){ void drawGame(){
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
drawSkyAndGround(); drawSkyAndGround();
drawRays(map); drawRays(map);
drawMap2D(map); drawMap2D(map);
drawFPS();
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
...@@ -413,6 +436,7 @@ void mainLoop(){ ...@@ -413,6 +436,7 @@ void mainLoop(){
delta = (a - b); delta = (a - b);
if (delta > 1000/FPS_TO_GET){ if (delta > 1000/FPS_TO_GET){
//printf("fps: %f\n", 1000/delta); //printf("fps: %f\n", 1000/delta);
fps = 1000/delta;
b = a; b = a;
switch (game_state){ switch (game_state){
case MENU: case MENU:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment