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 Binary files a/travail_de_groupe/jeu_appren_par_renfo/Res/net.png and b/travail_de_groupe/jeu_appren_par_renfo/Res/net.png differ 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 Binary files /dev/null and b/travail_de_groupe/jeu_appren_par_renfo/Res/netLeft.png differ 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 Binary files /dev/null and b/travail_de_groupe/jeu_appren_par_renfo/Res/netRight.png differ diff --git a/travail_de_groupe/jeu_appren_par_renfo/map.txt b/travail_de_groupe/jeu_appren_par_renfo/map.txt index 9fe61816ae2fd2cd72041823d5474538c6e2600a..2d1975477a1540ff441a10e09e4740c2171bf65b 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 5b450d2d845676e089bd6cd7064d062f745f5b49..d28bfe93a2da64826f476cfeed41933b7ac3bf64 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 c7a89a7870a35f2307024ae782c0d0b496fc9b5c..045b7918d3005ad3d85ec894ffef76b46f0a806e 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 dddaadab9f73e03ace1b9ecc7e0c5d99055cc170..0cad8e4b7ddbb53e0948b57d1f59d679aaac9eed 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