From b9fab8c37885485240bf26b2fc6a1e5253a54262 Mon Sep 17 00:00:00 2001
From: belkhiritaha <belkhiri.taha53@gmail.com>
Date: Wed, 29 Jun 2022 00:27:17 +0200
Subject: [PATCH] =?UTF-8?q?rotation=20du=20joueur=20par=20rapport=20=C3=A0?=
 =?UTF-8?q?=20l'angle?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../jeu_appren_par_renfo/src/player.c         | 10 +++++----
 .../jeu_appren_par_renfo/src/render.c         | 22 +++++++++++++++++++
 2 files changed, 28 insertions(+), 4 deletions(-)

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 5fbbe37..02c0f05 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 69ef960..a2b9da9 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);
     }
-- 
GitLab