From f1eb5050d5079c8435a07016ee91631933ec82ef Mon Sep 17 00:00:00 2001 From: Taha Belkhiri <belkhiri.taha53@gmail.com> Date: Wed, 29 Jun 2022 13:48:40 +0200 Subject: [PATCH] ajout de nouvelles textures --- .../jeu_appren_par_renfo/Res/net.png | Bin 294 -> 222 bytes .../jeu_appren_par_renfo/Res/netLeft.png | Bin 0 -> 249 bytes .../jeu_appren_par_renfo/Res/netRight.png | Bin 0 -> 251 bytes .../jeu_appren_par_renfo/map.txt | 4 +-- .../jeu_appren_par_renfo/src/player.c | 8 ++++-- .../jeu_appren_par_renfo/src/render.c | 26 ++++++++++++++---- .../jeu_appren_par_renfo/src/render.h | 3 ++ 7 files changed, 31 insertions(+), 10 deletions(-) mode change 100755 => 100644 travail_de_groupe/jeu_appren_par_renfo/Res/net.png create mode 100644 travail_de_groupe/jeu_appren_par_renfo/Res/netLeft.png create mode 100644 travail_de_groupe/jeu_appren_par_renfo/Res/netRight.png diff --git a/travail_de_groupe/jeu_appren_par_renfo/Res/net.png b/travail_de_groupe/jeu_appren_par_renfo/Res/net.png old mode 100755 new mode 100644 index f9394652290e8804fda47da8902c7fb4e1cea98e..77352f60655890ad11bc7d958b59dd7dd8d6ea7e GIT binary patch delta 165 zcmZ3+bdPa@V?9rRPl)UP|NqO&%NfAnvB<4jAcLhO$S)Wu&fuW6@(Ym9S>O>_%)r2R z2!t6$HM|;tg5I7kjv*25Zzpc#Wl-Qb-0<(eaYP6EEyk5aY}%9CQ(O$WL<CsfFDPuD zVg2Y7W0}C3B$<oi3zWY}e4NU&K;J^?3#(jwL*EPT58D-zn2mpE=Em^PvjCdQ;OXk; Jvd$@?2>^?3IjsNy delta 237 zcmcb|xQuCnV?BR>Pl)TTUAwZgv;Y79UtV6$z`!u$(CdRhinS!jFBmBJpW*j5zF?pL zXMsm#F#`kNVGw3Kp1&dmDA@1m;usR){&u1v-vI}X!&TS+{Xc6uGs085kXcSh&0Fv~ zr_I4lvszU5Oj|I2%gS3S8A8i13w@bv7CM{7_fbh&R8!rhWm%IKc+T<jzTkf=Bv;6! z^KvHVFVESle4Eq?t#lpjGlRE!UQqE{uKGefca<6EtRpYCu-tvq|3`6$y+Y%?M}|#; kEXop&20)6P<69l0k+70go#vchK({e?y85}Sb4q9e026dz_y7O^ diff --git a/travail_de_groupe/jeu_appren_par_renfo/Res/netLeft.png b/travail_de_groupe/jeu_appren_par_renfo/Res/netLeft.png new file mode 100644 index 0000000000000000000000000000000000000000..161c67ec325ded80efba40675e2795f190e5a960 GIT binary patch literal 249 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!7>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`211o(uw{{R2Kyu2L91A@mQw`zeDOG%JlFi@PqL2Km~AfL0qBeIx*f$uN~ zGak=hkpdJ<^K@|xiEw{=QBmlC1Bdg)X?OmgyKUgX!g|F|X<rSK9FMvKgZcwzy_?oE zm<{GVuD=n@AbqBBihhge0{sov4tExtvIp%G2y57P;2lF@|1}wppH2~sznFG2AF+)p jR(Q&t$ohiY-~mJALG{oJYo<p4ZDjCt^>bP0l+XkK#Kuy3 literal 0 HcmV?d00001 diff --git a/travail_de_groupe/jeu_appren_par_renfo/Res/netRight.png b/travail_de_groupe/jeu_appren_par_renfo/Res/netRight.png new file mode 100644 index 0000000000000000000000000000000000000000..bfa4fa8037dd8cf677a4cd3caa8ddbcdca81944a GIT binary patch literal 251 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!7>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`211o(uw{{R2Kyu2L91A@mQw`zeDOG%JlFi@PqL2Km~AfL0qBeIx*f$uN~ zGak=hkpdLV@N{tuiEw{=QBmlC1BY|qt~>wF>CUv^VZGv~w6BKgOuMjxg4zRSy&J|7 z4BwlR7uXkb7qBrq=zVVGxFD`%&G7!B6hqNWeV2xP0yh~e`mZreI9;R2^riI#-+}5a jYz;BbxCIyJyPP=_cR5=<bYYbQ$O8<Xu6{1-oD!M<1j<s1 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 9fe6181..2d19754 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/map.txt +++ b/travail_de_groupe/jeu_appren_par_renfo/map.txt @@ -1,10 +1,10 @@ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 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 -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 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/player.c b/travail_de_groupe/jeu_appren_par_renfo/src/player.c index 5b450d2..d28bfe9 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.c @@ -63,10 +63,12 @@ void hitBall() // printf("ray1: %d %d\n", ray1[0], ray1[1]); int fermetureAngle = 2; int angleMin = RD * atan2((MAP_WIDTH+fermetureAngle / 2) * BLOCK_SIZE - player.x, player.y); - int angleMax = RD * atan2((MAP_WIDTH+fermetureAngle / 2) * BLOCK_SIZE - player.x, MAP_HEIGHT * BLOCK_SIZE - player.y); + int angleMax = 25 + RD * atan2((MAP_WIDTH+fermetureAngle / 2) * BLOCK_SIZE - player.x, MAP_HEIGHT * BLOCK_SIZE - player.y); int currAngle = (int)((player.angle) * RD + 90) % 360; - // printf("player angle: %d\n",(int) ((player.angle) * RD +90) %360); - // printf("distance to ball: %f\n", sqrt(pow(ball.x - player.x, 2) + pow(ball.y - player.y, 2))/BLOCK_SIZE); + printf("player angle: %d\n",(int) ((player.angle) * RD +90) %360); + printf("angle min: %d\n", angleMin); + printf("angle max: %d\n", angleMax); + //printf("distance to ball: %f\n", sqrt(pow(ball.x - player.x, 2) + pow(ball.y - player.y, 2))/BLOCK_SIZE); if (sqrt(pow(player.x - ball.x, 2) + pow(player.y - ball.y, 2)) / BLOCK_SIZE < HIT_RANGE) { if (currAngle < angleMax && currAngle > angleMin) 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 c7a89a7..045b791 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.c @@ -12,6 +12,8 @@ SDL_Rect sky; SDL_Rect ground; SDL_Texture *netTexture; +SDL_Texture *netEdgeLeftTexture; +SDL_Texture *netEdgeRightTexture; SDL_Texture *crowdTexture; SDL_Texture *playerTexture; SDL_Texture *ballTexture; @@ -52,7 +54,7 @@ void freeRayInfoList(rayInfo_t *rayInfoHead) } } -rayInfo_t *allocRayInfo(float ra, float distT, int r, int isTransparent, int direction, float htexture) +rayInfo_t *allocRayInfo(float ra, float distT, int r, int isTransparent, int direction, float htexture, int rx, int ry) { rayInfo_t *rayInfo = malloc(sizeof(rayInfo_t)); if (rayInfo == NULL) @@ -66,6 +68,8 @@ rayInfo_t *allocRayInfo(float ra, float distT, int r, int isTransparent, int dir rayInfo->isTransparent = isTransparent; rayInfo->direction = direction; rayInfo->htexture = htexture; + rayInfo->rx = rx; + rayInfo->ry = ry; rayInfo->next = NULL; return rayInfo; } @@ -176,7 +180,17 @@ void drawRayColumn(rayInfo_t *rayInfo) { rect.h *= 1.2; // rect.y -= rect.h/3; - SDL_RenderCopy(renderer, netTexture, &destRect, &rect); + if (map[rayInfo->ry/BLOCK_SIZE][rayInfo->rx/BLOCK_SIZE] == 3){ + SDL_RenderCopy(renderer, netEdgeLeftTexture, &destRect, &rect); + } + + if (map[rayInfo->ry/BLOCK_SIZE][rayInfo->rx/BLOCK_SIZE] == 4){ + SDL_RenderCopy(renderer, netEdgeRightTexture, &destRect, &rect); + } + + else { + SDL_RenderCopy(renderer, netTexture, &destRect, &rect); + } } else { @@ -446,18 +460,18 @@ void castRays(int map[][MAP_WIDTH]) ra += 2 * pi; // draw ray - rayInfo_t *column = allocRayInfo(ra, distT, r, foundTransparentWallV, direction, htexture); + rayInfo_t *column = allocRayInfo(ra, distT, r, foundTransparentWallV, direction, htexture, rx, ry); addRayInfoToList(&raysListHead, column); if (foundTransparentWallV) { if (foundSolidWallV) { - rayInfo_t *column = allocRayInfo(ra, distT2, r, 0, direction2, htexture2); + rayInfo_t *column = allocRayInfo(ra, distT2, r, 0, direction2, htexture2, rx2, ry2); addRayInfoToList(&raysListHead, column); } else { - rayInfo_t *column = allocRayInfo(ra, distT2, r, 0, direction, htexture2); + rayInfo_t *column = allocRayInfo(ra, distT2, r, 0, direction, htexture2, rx2, ry2); addRayInfoToList(&raysListHead, column); } } @@ -999,6 +1013,8 @@ void mainLoop() crowdTexture = loadTexture("Res/crowd.png"); playerTexture = loadTexture("Res/player_sprite.png"); ballTexture = loadTexture("Res/ball_sprite.png"); + netEdgeLeftTexture = loadTexture("Res/netLeft.png"); + netEdgeRightTexture = loadTexture("Res/netRight.png"); ray1 = malloc(sizeof(int) * 2); ray2 = malloc(sizeof(int) * 2); 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 dddaada..0cad8e4 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.h @@ -25,6 +25,8 @@ typedef struct rayInfo{ int isTransparent; int direction; float htexture; + int rx; + int ry; struct rayInfo * next; } rayInfo_t; @@ -36,6 +38,7 @@ extern int * ray1; extern int * ray2; void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *returnXWall, int *returnYWall, int *returnXNet, int *returnYNet); +void drawString(char *str, int x, int y, int w, int h, int r, int g, int b, int a); void mainLoop(); #endif \ No newline at end of file -- GitLab