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 5fbbe3784a063338193695e377c638dd3657777a..02c0f05f28dc08eeefc11054e8e4a1fa1ef672ac 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.c @@ -14,10 +14,12 @@ void initPlayer(){ player.y= 6*BLOCK_SIZE; player.h = 2 * BLOCK_SIZE; player.w = 2 * BLOCK_SIZE; + player.angle = 0; ennemy.h = 2 * BLOCK_SIZE; ennemy.w = 2 * BLOCK_SIZE; ennemy.x = 20 * BLOCK_SIZE; - ennemy.y = 15 * BLOCK_SIZE; + ennemy.y = 10 * BLOCK_SIZE; + ennemy.angle = -pi; ball.h = 0.5 * BLOCK_SIZE; ball.w = 0.5 * BLOCK_SIZE; ball.x = 10 * BLOCK_SIZE; @@ -43,7 +45,7 @@ int * generateLandingPoint(){ int randomPointY = randomLength * sin(player.angle) + player.y; landingPoint[0] = randomPointX/BLOCK_SIZE; landingPoint[1] = randomPointY/BLOCK_SIZE; - printf("landing point: %d %d\n", landingPoint[0], landingPoint[1]); + //printf("landing point: %d %d\n", landingPoint[0], landingPoint[1]); return landingPoint; } @@ -67,7 +69,7 @@ void hitBall(){ int angleMax = 90 + RD * atan2((MAP_WIDTH/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("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){ printf("hit\n"); @@ -100,7 +102,7 @@ void updateBall(){ if (ball.isHit){ ball.z = lagrangeInterpolation(ball.x, lastHitPoint[0], lastHitPoint[1], 15 , 2*player.h, landingPoint[0], 0); } - printf("ball position: %f %f %f\n", ball.x/BLOCK_SIZE, ball.y/BLOCK_SIZE, ball.z/BLOCK_SIZE); + //printf("ball position: %f %f %f\n", ball.x/BLOCK_SIZE, ball.y/BLOCK_SIZE, ball.z/BLOCK_SIZE); } 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 69ef960536fac797274864b98bb56b7a5ba62d21..a2b9da9a4bb6b00fdb5e582e26cb708e4cdf3c2f 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.c @@ -14,6 +14,7 @@ SDL_Rect ground; SDL_Texture * netTexture; SDL_Texture * crowdTexture; SDL_Texture * playerTexture; +SDL_Texture * ballTexture; int ** rays; int raysListLength = 0; @@ -439,10 +440,31 @@ void drawEnnemy(){ rect.h = (ennemyHeight * screenDimension.h)/(ennemyDistance/BLOCK_SIZE); rect.y = (screenDimension.h/2 + player.viewAngle) - rect.h/5; + destRect.x = 0; destRect.y = 0; destRect.w = 64; destRect.h = 64; + float angleSum = ennemyAngle + player.angle; + printf("player angle %f\n", player.angle * RD); + printf("ennemy angle %f\n", ennemyAngle * RD); + if (angleSum > 2*pi) angleSum -= 2*pi; + if (angleSum < 0) angleSum += 2*pi; + + printf("sum: %f\n", angleSum * RD); + + if (angleSum > 5*pi/3 && angleSum <= pi/3){ + destRect.x = 2 * destRect.w; + } + else if (angleSum > pi/3 && angleSum <= 2*pi/3){ + destRect.x = 3 * destRect.w; + } + else if (angleSum > 2*pi/3 && angleSum <= 4*pi/3){ + destRect.x = 0 * destRect.w; + } + else if (angleSum > 4*pi/3 && angleSum <= 5*pi/3){ + destRect.x = 1 * destRect.w; + } //printf("%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h); SDL_RenderCopy(renderer, playerTexture, &destRect, &rect); }