From 1527c1a9c11dafc9624e4aa470e852e3b3df2fd5 Mon Sep 17 00:00:00 2001 From: Taha Belkhiri <belkhiri.taha53@gmail.com> Date: Mon, 27 Jun 2022 20:57:06 +0200 Subject: [PATCH] ajout des supporters et des filets --- .../jeu_appren_par_renfo/Res/crowd.png | Bin 0 -> 514 bytes .../jeu_appren_par_renfo/Res/net.png | Bin 0 -> 250 bytes .../jeu_appren_par_renfo/map.txt | 6 +- .../jeu_appren_par_renfo/src/render.c | 57 ++++++++++++++---- .../jeu_appren_par_renfo/src/render.h | 2 +- 5 files changed, 49 insertions(+), 16 deletions(-) create mode 100755 travail_de_groupe/jeu_appren_par_renfo/Res/crowd.png create mode 100755 travail_de_groupe/jeu_appren_par_renfo/Res/net.png diff --git a/travail_de_groupe/jeu_appren_par_renfo/Res/crowd.png b/travail_de_groupe/jeu_appren_par_renfo/Res/crowd.png new file mode 100755 index 0000000000000000000000000000000000000000..0a65f3fa2194d6f63ca97cb05b610d8c6f66ebaf GIT binary patch literal 514 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!7>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0(2Ka=y0_pz;Cwnmb2ZC}S&<6@IoW9b26G*X_1o;JnB>w+rkn(1B0}62# zctjR6Fz_7)VaDV6D^h@#Bzw9zhD5l(4SSn+$bd&j`paMW%6<Imewim#F0@$rtxEoV zuD$cu;?uuW?AV$QZfd+OJm>fUW9B1g3gntk^Bp<!A*eZG_HtoE<2h#%m<^3<c;eDO zYy~pr+<s90{RbP{eg8+iJnNJ%6j$}zUYg!fE-&uRyT0JLt-{Ma4{g}y{k+a*-YoSz ziAzpWM{d!v))`Ih(iI-kD+Gc+w6mE{J83E-5pe9KgA~KZr>>iR%1CZ`ztJK%ILcF> zo$b-(_E{c#BR;1^-Bn$#CoFc&#lNY-MOpOa#T>1`jvKrRDaI$$7>)(93m>s4_BP;9 zU0u$=w0Tx`6UUVu=?j$Rzm^p0T*|B1?6HY)lHoj)7oQj|-^;MSWOXMbgKe&^Q{tUV zH>6zJby<JAy9DugbeMQliB+A864aEG{9?cIa;mDK!!1^&b9Wl%@@e`Mh1v6a`HN*b vd~t2~eSM0Kv4|I2^A(Q6)e|<q{>5BA*+cKeX1)Yq958sg`njxgN@xNAi$Tet literal 0 HcmV?d00001 diff --git a/travail_de_groupe/jeu_appren_par_renfo/Res/net.png b/travail_de_groupe/jeu_appren_par_renfo/Res/net.png new file mode 100755 index 0000000000000000000000000000000000000000..0ad6f1a4d89bebd7bf9d8f398880c898297d4080 GIT binary patch literal 250 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!7>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h2Ka=yrlq9;nLrTq;~+1PVlD~t3;zF~;rc0Fpjrmb0*}aI1_r*vAk26? ze?<yVFx%6`F(ktM?F2`z0}cX*tp5IAe7ZtBQ9Gh*X9f4c*W7m=<k&XZXb7z&i8A>t s)Xp$pCdiT1n^jatG-Sgc2ZPTHvsVaTG+sYr8_-$?Pgg&ebxsLQ0IkGK-T(jq literal 0 HcmV?d00001 diff --git a/travail_de_groupe/jeu_appren_par_renfo/map.txt b/travail_de_groupe/jeu_appren_par_renfo/map.txt index 14ac17f..d5439ec 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/map.txt +++ b/travail_de_groupe/jeu_appren_par_renfo/map.txt @@ -5,9 +5,9 @@ 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 +1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 +1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 +1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/render.c b/travail_de_groupe/jeu_appren_par_renfo/src/render.c index dea8b38..90bd7dd 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.c @@ -6,13 +6,24 @@ SDL_Renderer *renderer; TTF_Font *RobotoFont; SDL_DisplayMode screenDimension; +SDL_Rect destRect; SDL_Rect rect; SDL_Rect sky; SDL_Rect ground; +SDL_Texture * netTexture; +SDL_Texture * crowdTexture; + int ** rays; int raysListLength = 0; +SDL_Texture * loadTexture(char * path) { + SDL_Surface * surface = IMG_Load(path); + SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface); + SDL_FreeSurface(surface); + return texture; +} + void initRays(){ int i; rays = malloc(sizeof(int*) * 2 * NB_RAYS); @@ -80,7 +91,7 @@ void endSDL(){ SDL_Quit(); } -void drawRayColumn(float ra, float distT, int r, int isTransparent, int direction){ +void drawRayColumn(float ra, float distT, int r, int isTransparent, int direction, float htexture){ float ca = player.angle - ra; if (ca < 0) ca += 2*pi; if (ca > 2*pi) ca -= 2*pi; @@ -92,24 +103,35 @@ void drawRayColumn(float ra, float distT, int r, int isTransparent, int directio rect.w = 1; rect.h = (2 * screenDimension.w * lineH/20); + destRect.x = htexture; + destRect.y = 0; + destRect.w = 1; + destRect.h = 64; + if (isTransparent){ - rect.h *= 0.75; + rect.h *= 1.75; rect.y -= rect.h/3; - } - if (direction){ - SDL_SetRenderDrawColor(renderer, 255 * (1 - isTransparent), 255, 0, 255 * (1 - isTransparent)); + SDL_RenderCopy(renderer, netTexture, &destRect, &rect); + } else { - SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255 * (1 - isTransparent)); + if (direction){ + SDL_RenderCopy(renderer, crowdTexture, &destRect, &rect); + //SDL_SetRenderDrawColor(renderer, 255 * (1 - isTransparent), 255, 0, 255 * (1 - isTransparent)); + } + else { + SDL_RenderCopy(renderer, crowdTexture, &destRect, &rect); + //SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255 * (1 - isTransparent)); + } } - SDL_RenderFillRect(renderer, &rect); - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + //SDL_RenderFillRect(renderer, &rect); + //SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); } void drawRays(int map[][MAP_WIDTH]){ // ray casting variables - float htexture; + float htexture, htexture2; int r, mx, my, dof; double rx, ry, rx2, ry2, xo, yo, distT, distT2; double ra; @@ -230,12 +252,14 @@ void drawRays(int map[][MAP_WIDTH]){ ry = hy2; distT = disH2; direction = 0; + htexture = (int)(rx)%BLOCK_SIZE; } else { rx = vx2; ry = vy2; distT = disV2; direction = 1; + htexture = (int)(ry)%BLOCK_SIZE; } if (foundSolidWallV){ if (disH < disV){ @@ -243,12 +267,14 @@ void drawRays(int map[][MAP_WIDTH]){ ry2 = hy; distT2 = disH; direction2 = 0; + htexture2 = (int)(rx2)%BLOCK_SIZE; } else { rx2 = vx; ry2 = vy; distT2 = disV; direction2 = 1; + htexture2 = (int)(ry2)%BLOCK_SIZE; } } if (foundSolidWallH){ @@ -257,12 +283,14 @@ void drawRays(int map[][MAP_WIDTH]){ ry2 = hy; distT2 = disH; direction2 = 0; + htexture2 = (int)(rx2)%BLOCK_SIZE; } else { rx2 = vx; ry2 = vy; distT2 = disV; direction2 = 1; + htexture2 = (int)(ry2)%BLOCK_SIZE; } } } @@ -273,12 +301,14 @@ void drawRays(int map[][MAP_WIDTH]){ ry = hy; distT = disH; direction = 0; + htexture = (int)(rx)%BLOCK_SIZE; } else { rx = vx; ry = vy; distT = disV; direction = 1; + htexture = (int)(ry)%BLOCK_SIZE; } } @@ -288,15 +318,15 @@ void drawRays(int map[][MAP_WIDTH]){ if (ra < 0) ra += 2*pi; // draw ray - drawRayColumn(ra, distT, r, foundTransparentWallV, direction); if (foundTransparentWallV){ if (foundSolidWallV){ - drawRayColumn(ra, distT2, r, 0, direction2); + drawRayColumn(ra, distT2, r, 0, direction2 , htexture2); } else { - drawRayColumn(ra, distT2, r, 0, direction); + drawRayColumn(ra, distT2, r, 0, direction, htexture2); } } + drawRayColumn(ra, distT, r, foundTransparentWallV, direction, htexture); // draw the ray in the minimap addRayToList(rx, ry); @@ -365,6 +395,9 @@ void mainLoop(){ createWindow(); initRays(); + netTexture = loadTexture("Res/net.png"); + crowdTexture = loadTexture("Res/crowd.png"); + unsigned int a = SDL_GetTicks(); unsigned int b = SDL_GetTicks(); double delta = 0; diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/render.h b/travail_de_groupe/jeu_appren_par_renfo/src/render.h index 32b9ce0..e88b3cc 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.h @@ -12,7 +12,7 @@ #define DOF 100 #define BLOCK_SIZE 64 #define DR 0.0174533 -#define FOV_ANGLE 60 +#define FOV_ANGLE 80 #define pi 3.14159265358979323846 #define NB_RAYS (screenDimension.w) #define ANGLE_INC ((DR * FOV_ANGLE) / NB_RAYS) -- GitLab