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/gest_event.c b/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c index 34ff2193e15ddc35b3ff8fca0b2003783e02d0cb..b014b4c107a7abe2e10af291b4b57ef39ba727c1 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c @@ -134,7 +134,12 @@ void gestGame() case SDL_MOUSEBUTTONDOWN: if (event.button.button == SDL_BUTTON_LEFT) { - player.isHitting = 1; + if (player.isHitting){ + player.isHitting = 0; + } + else { + player.isHitting = 1; + } } break; @@ -149,7 +154,6 @@ void gestGame() break; } } - managePlayer(); SDL_Delay(5); } 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 70a6d0bea9aebfceb1ae841537a90ca0c31ff0ee..b3e67a513001e758061fd172d597204c02960593 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.c @@ -19,7 +19,7 @@ void initPlayer() ennemy.x = 25 * BLOCK_SIZE; ennemy.y = 5 * BLOCK_SIZE; ennemy.angle = -pi; - player.speed = 1; + player.speed = 100; player.isMoving = 0; player.HPMax = 3; player.currentHP = player.HPMax; @@ -67,6 +67,22 @@ void freeIntList(int *list) void hitBall() { +<<<<<<< HEAD +======= + // printf("map edges: %d %d\n", BLOCK_SIZE * MAP_WIDTH/2, BLOCK_SIZE *MAP_HEIGHT/2); + // 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 = 90 + 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("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); +>>>>>>> 0383eb7e8ec1fcd92d8fd2c6846d5e9ab2d08f17 if (sqrt(pow(player.x - ball.x, 2) + pow(player.y - ball.y, 2)) / BLOCK_SIZE < HIT_RANGE) { int rxWall, ryWall; @@ -74,16 +90,25 @@ void hitBall() int rxNet, ryNet; float distanceNet; + if (player.isHitting) + { castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet); //printf("rayWall: %d %d\n", rxWall/BLOCK_SIZE, ryWall/BLOCK_SIZE); //printf("distanceWall: %f\n", distanceWall); +<<<<<<< HEAD //printf("rayNet: %d %d\n", rxNet/BLOCK_SIZE, ryNet/BLOCK_SIZE); //printf("distanceNet: %f\n", distanceNet); if (rxWall > MAP_WIDTH/2) { if (player.isHitting) +======= + printf("rayNet: %d %d\n", rxNet/BLOCK_SIZE, ryNet/BLOCK_SIZE); + printf("distanceNet: %f\n", distanceNet); + // printf("hit\n"); + if (rxWall > MAP_WIDTH/2) +>>>>>>> 0383eb7e8ec1fcd92d8fd2c6846d5e9ab2d08f17 { freeIntList(lastHitPoint); diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/player.h b/travail_de_groupe/jeu_appren_par_renfo/src/player.h index 6e59c1a489cadfaab490e8b1259479c42048ec11..ebe9a2dbf350d550cbf6316a206180b2c86ce997 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.h @@ -11,9 +11,9 @@ #define ENTITIES_RIGHT 3 #define HIT_RANGE 2 -#define HIT_FORCE 1 +#define HIT_FORCE 20 -#define MOVEMENT_SPEED 2 +#define MOVEMENT_SPEED 20 typedef struct player{ float x; float y; 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..9b1ffdb4bc62f8b964a36dc59b1616020576d94d 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); } } @@ -979,10 +993,18 @@ void drawGame() SDL_RenderClear(renderer); drawSkyAndGround(); castRays(map); - drawHorizentalRays(); - drawEnnemy(); - drawVerticalRays(); - drawBall(); + if (ball.x < MAP_WIDTH * BLOCK_SIZE/2){ + drawHorizentalRays(); + drawEnnemy(); + drawVerticalRays(); + drawBall(); + } + else { + drawHorizentalRays(); + drawBall(); + drawVerticalRays(); + drawEnnemy(); + } drawMap2D(map); drawFPS(); drawInfosPlayer(); @@ -999,6 +1021,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); @@ -1030,6 +1054,7 @@ void mainLoop() break; case GAME: drawGame(); + managePlayer(); break; } } 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