Skip to content
Snippets Groups Projects
Commit b9fab8c3 authored by belkhiritaha's avatar belkhiritaha
Browse files

rotation du joueur par rapport à l'angle

parent bdd6c11e
Branches
No related tags found
No related merge requests found
...@@ -14,10 +14,12 @@ void initPlayer(){ ...@@ -14,10 +14,12 @@ void initPlayer(){
player.y= 6*BLOCK_SIZE; player.y= 6*BLOCK_SIZE;
player.h = 2 * BLOCK_SIZE; player.h = 2 * BLOCK_SIZE;
player.w = 2 * BLOCK_SIZE; player.w = 2 * BLOCK_SIZE;
player.angle = 0;
ennemy.h = 2 * BLOCK_SIZE; ennemy.h = 2 * BLOCK_SIZE;
ennemy.w = 2 * BLOCK_SIZE; ennemy.w = 2 * BLOCK_SIZE;
ennemy.x = 20 * 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.h = 0.5 * BLOCK_SIZE;
ball.w = 0.5 * BLOCK_SIZE; ball.w = 0.5 * BLOCK_SIZE;
ball.x = 10 * BLOCK_SIZE; ball.x = 10 * BLOCK_SIZE;
...@@ -43,7 +45,7 @@ int * generateLandingPoint(){ ...@@ -43,7 +45,7 @@ int * generateLandingPoint(){
int randomPointY = randomLength * sin(player.angle) + player.y; int randomPointY = randomLength * sin(player.angle) + player.y;
landingPoint[0] = randomPointX/BLOCK_SIZE; landingPoint[0] = randomPointX/BLOCK_SIZE;
landingPoint[1] = randomPointY/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; return landingPoint;
} }
...@@ -67,7 +69,7 @@ void hitBall(){ ...@@ -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 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; int currAngle = (int) ((player.angle) * RD +90) %360;
//printf("player angle: %d\n",(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 (sqrt(pow(player.x - ball.x, 2) + pow(player.y - ball.y, 2))/BLOCK_SIZE < HIT_RANGE){
if (currAngle < angleMax && currAngle > angleMin){ if (currAngle < angleMax && currAngle > angleMin){
printf("hit\n"); printf("hit\n");
...@@ -100,7 +102,7 @@ void updateBall(){ ...@@ -100,7 +102,7 @@ void updateBall(){
if (ball.isHit){ if (ball.isHit){
ball.z = lagrangeInterpolation(ball.x, lastHitPoint[0], lastHitPoint[1], 15 , 2*player.h, landingPoint[0], 0); 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);
} }
......
...@@ -14,6 +14,7 @@ SDL_Rect ground; ...@@ -14,6 +14,7 @@ SDL_Rect ground;
SDL_Texture * netTexture; SDL_Texture * netTexture;
SDL_Texture * crowdTexture; SDL_Texture * crowdTexture;
SDL_Texture * playerTexture; SDL_Texture * playerTexture;
SDL_Texture * ballTexture;
int ** rays; int ** rays;
int raysListLength = 0; int raysListLength = 0;
...@@ -439,10 +440,31 @@ void drawEnnemy(){ ...@@ -439,10 +440,31 @@ void drawEnnemy(){
rect.h = (ennemyHeight * screenDimension.h)/(ennemyDistance/BLOCK_SIZE); rect.h = (ennemyHeight * screenDimension.h)/(ennemyDistance/BLOCK_SIZE);
rect.y = (screenDimension.h/2 + player.viewAngle) - rect.h/5; rect.y = (screenDimension.h/2 + player.viewAngle) - rect.h/5;
destRect.x = 0; destRect.x = 0;
destRect.y = 0; destRect.y = 0;
destRect.w = 64; destRect.w = 64;
destRect.h = 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); //printf("%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h);
SDL_RenderCopy(renderer, playerTexture, &destRect, &rect); SDL_RenderCopy(renderer, playerTexture, &destRect, &rect);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment