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 83c93a2f6317b414f05cc2e96ee927a6498b8dee..ac6ae73c79707739665d2a4f3023a9c64d188ced 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.c @@ -4,6 +4,8 @@ player_t player; player_t ennemy; +player_t ball; + void initPlayer(){ player.x= 6*BLOCK_SIZE; player.y= 6*BLOCK_SIZE; @@ -13,6 +15,10 @@ void initPlayer(){ ennemy.w = 2 * BLOCK_SIZE; ennemy.x = 20 * BLOCK_SIZE; ennemy.y = 15 * BLOCK_SIZE; + ball.h = 0.5 * BLOCK_SIZE; + ball.w = 0.5 * BLOCK_SIZE; + ball.x = 10 * BLOCK_SIZE; + ball.y = 10 * BLOCK_SIZE; player.speed = 1; player.isMoving = 0; player.HPMax = 3; 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 2fbe0dc80363cb300f830491ca25ce2092cc8b11..947f3bccced758a487bd020200baf68c3c884a8e 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.h @@ -29,6 +29,7 @@ typedef struct player{ extern player_t player; extern player_t ennemy; +extern player_t ball; void initPlayer(); void managePlayer(); 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 eada6fada05bb5215adf2ffdf063b5d41d80d666..af7310fc1b5fbd5a6f330984103aeee4bcf8c3a7 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.c @@ -427,6 +427,33 @@ void drawEnnemy(){ } } +void drawBall(){ + float ballAngle = atan2((ball.y + ball.w/2) - (player.y + player.w/2) , (ball.x + ball.w/2) - (player.x + player.w/2)); + if (ballAngle < 0) ballAngle += 2*pi; + if (ballAngle > 2*pi) ballAngle -= 2*pi; + float ballDistance = sqrt((ball.x - player.x)*(ball.x - player.x) + (ball.y - player.y)*(ball.y - player.y)) * BLOCK_SIZE; + float ballBaseWidth = BLOCK_SIZE/2; + float ballDistanceX = ballDistance * cos(ballAngle - player.angle) * BLOCK_SIZE; + float ballDistanceY = ballDistance * fabs(sin(ballAngle - player.angle)) * BLOCK_SIZE; + float scaledBallWidth = ballBaseWidth / sqrt(3); + int ballWidth = 25; + int ballHeight = 25; + + if (ballAngle >= player.angle - (FOV_ANGLE)/2 * DR && ballAngle <= player.angle + (FOV_ANGLE)/2 * DR){ + rect.x = screenDimension.w/2 + (screenDimension.w * tan(ballAngle - player.angle)) * sqrt(3) * 0.5; + rect.w = (ballWidth * screenDimension.w) / (ballDistance/BLOCK_SIZE); + rect.h = (ballHeight * screenDimension.h)/(ballDistance/BLOCK_SIZE); + rect.y = (screenDimension.h/2 + player.viewAngle) - rect.h/5; + + destRect.x = 0; + destRect.y = 0; + destRect.w = 64; + destRect.h = 64; + printf("%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h); + SDL_RenderCopy(renderer, playerTexture, &destRect, &rect); + } +} + void drawSkyAndGround(){ SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); SDL_RenderFillRect(renderer, NULL); @@ -503,6 +530,7 @@ void drawGame(){ drawHorizentalRays(); drawEnnemy(); drawVerticalRays(); + drawBall(); drawMap2D(map); drawFPS(); SDL_RenderPresent(renderer);