diff --git a/travail_de_groupe/jeu_appren_par_renfo/Res/player_sprite.png b/travail_de_groupe/jeu_appren_par_renfo/Res/player_sprite.png new file mode 100755 index 0000000000000000000000000000000000000000..8447510ba0888073e187f8a1859a2b325b00c0d4 Binary files /dev/null and b/travail_de_groupe/jeu_appren_par_renfo/Res/player_sprite.png differ diff --git a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/ball.c b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/ball.c index 23f23768fd658c6eabedd27a2ee8ceadddd96762..0be83169cf086c36035b8877815bcbbfd5a772d1 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/ball.c +++ b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/ball.c @@ -9,6 +9,12 @@ void initBall (){ } + +double f(int x, float xc, float yc, float xf, float yf, float xt, float yt){ + double returnValue = yf * ((x - xc)/(xf - xc)) * ((x - xt)/(xf - xt)) + yc * ((x - xf)/(xc - xf)) * ((x - xt)/(xc - xt)) + yt * ((x - xc)/(xt - xc)) * ((x - xf)/(xt - xf)); + return returnValue; +} + void laGrange (float beta[3],float Z[3]){ // y , x printf("x canon : %f, x chute : %f, x filet : %f\n", Z[0], Z[1], Z[2]); printf("y canon : %f, y chute : %f, y filet : %f\n", beta[0], beta[1], beta[2]); @@ -40,6 +46,9 @@ void calculationTrajectory(canon_t canon, int xDropPoint, int yDropPoint){ float setUp[2][3]; float distance= (float)(yDropPoint-canon.y); + + printf("test : %f\n", y); + trajectory[0][0]=canon.y; trajectory[0][1]=canon.x; @@ -65,7 +74,7 @@ void calculationTrajectory(canon_t canon, int xDropPoint, int yDropPoint){ laGrange(setUp[1],setUp[0]); //laGrange(y, x); - printf("coef a:%f; coef b:%f; coef c:%f\n", coefLagrange.a, coefLagrange.b, coefLagrange.c); + //printf("coef a:%f; coef b:%f; coef c:%f\n", coefLagrange.a, coefLagrange.b, coefLagrange.c); float step= distance / (NUMBERPOINT-1); diff --git a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.c b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.c index 8bfa93109bd4c951d2b412b6fecbad2ee5833b24..0a682387ac387f6f0700f95a44fbee409cee7740 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.c @@ -251,7 +251,7 @@ void drawTrajectoireSideView(){ ); for(int i=0; i<NUMBERPOINT-1; i++){ - printf("point %d (%d, %d)\n", i, trajectory[i][0], trajectory[i][1]); + //printf("point %d (%d, %d)\n", i, trajectory[i][0], trajectory[i][1]); SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); SDL_RenderDrawLine(renderer, trajectory[i][0], trajectory[i][1], trajectory[i+1][0], trajectory[i+1][1]); } 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 0a719e01aca3fd5f7659f2ecc6ab08b2ffbd8318..af7310fc1b5fbd5a6f330984103aeee4bcf8c3a7 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.c @@ -13,6 +13,7 @@ SDL_Rect ground; SDL_Texture * netTexture; SDL_Texture * crowdTexture; +SDL_Texture * playerTexture; int ** rays; int raysListLength = 0; @@ -162,12 +163,24 @@ void drawRayColumn(rayInfo_t * rayInfo){ } } -void drawRays(){ +void drawVerticalRays(){ rayInfo_t * current = raysListHead.next; while (current != NULL){ //printf("%p\n", current); - fflush(stdout); - drawRayColumn(current); + if (current->direction){ + drawRayColumn(current); + } + current = current->next; + } +} + +void drawHorizentalRays(){ + rayInfo_t * current = raysListHead.next; + while (current != NULL){ + //printf("%p\n", current); + if (!current->direction){ + drawRayColumn(current); + } current = current->next; } } @@ -401,14 +414,43 @@ void drawEnnemy(){ if (ennemyAngle >= player.angle - (FOV_ANGLE)/2 * DR && ennemyAngle <= player.angle + (FOV_ANGLE)/2 * DR){ rect.x = screenDimension.w/2 + (screenDimension.w * tan(ennemyAngle - player.angle)) * sqrt(3) * 0.5; - rect.y = (screenDimension.h/2 + player.angle) - MAP_WIDTH * ennemyDistance/200000; rect.w = (ennemyWidth * screenDimension.w) / (ennemyDistance/BLOCK_SIZE); 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; + printf("%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h); + SDL_RenderCopy(renderer, playerTexture, &destRect, &rect); + } +} - //printf("%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h); - SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); - SDL_RenderFillRect(renderer, &rect); - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); +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); } } @@ -485,8 +527,10 @@ void drawGame(){ SDL_RenderClear(renderer); drawSkyAndGround(); castRays(map); + drawHorizentalRays(); drawEnnemy(); - drawRays(); + drawVerticalRays(); + drawBall(); drawMap2D(map); drawFPS(); SDL_RenderPresent(renderer); @@ -500,6 +544,7 @@ void mainLoop(){ netTexture = loadTexture("Res/net.png"); crowdTexture = loadTexture("Res/crowd.png"); + playerTexture = loadTexture("Res/player_sprite.png"); unsigned int a = SDL_GetTicks(); unsigned int b = SDL_GetTicks();