diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/ball.c b/travail_de_groupe/jeu_appren_par_renfo/src/ball.c index e6ea79eae9534ab61f1e3eb183735f88dd78c30c..19c7ff3ece1dc8f57e4d2b7e96589c61b2650275 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/ball.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ball.c @@ -93,3 +93,22 @@ void calculTrajectoireAntoine2(int xd, int yd, int xf, int yf, int xt, int yt) trajectoireAntoine[NUMBERPOINT_TRAJEC - 1][0] = xt; trajectoireAntoine[NUMBERPOINT_TRAJEC - 1][1] = yt; } + +void updateBall() +{ + ball.x = ball.x + ball.speed * cos(ball.angle); + ball.y = ball.y + ball.speed * sin(ball.angle); + if (ball.isHit) + { + // landingPoint est déjà / BLOCK_SIZE de base + ball.z = lagrangeInterpolation(ball.x / BLOCK_SIZE, lastHitPoint[0] / BLOCK_SIZE, lastHitPoint[1] / BLOCK_SIZE, 15, 2 * player.h / BLOCK_SIZE, landingPoint[0], 0); + } + + if ((int)ball.z == 0) + { + ball.x = 0; + ball.y = 0; + ball.z = 0; + ball.speed = 0; + } +} diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/ball.h b/travail_de_groupe/jeu_appren_par_renfo/src/ball.h index 2f22f9a567d89511f581ef1eba2db832f0666554..61f10d9fdcb323f697e3f84fc375ffc3f35dd892 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/ball.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ball.h @@ -33,6 +33,7 @@ extern int trajectoireAntoine[NUMBERPOINT_TRAJEC][2]; void initBall(); float defineAngle(int, int, int, int); +void updateBall(); float lagrangeInterpolation(float, int, int, int, int, int, int); void calculTrajectoireAntoine2(int, int, int, int, int, int); diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c b/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c new file mode 100644 index 0000000000000000000000000000000000000000..83953a7730086d3165fb71cdb48596e93647dd63 --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c @@ -0,0 +1,15 @@ +#include "player.h" + +void initEnnemy() +{ + ennemy.h = 2 * BLOCK_SIZE; + ennemy.w = 2 * BLOCK_SIZE; + ennemy.x = 25 * BLOCK_SIZE; + ennemy.y = 5 * BLOCK_SIZE; + ennemy.angle = -pi; +} + +void manageEnnemy() +{ + +} \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.h b/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.h new file mode 100644 index 0000000000000000000000000000000000000000..f97c46069b5247bf7ead6f4a510be2db3fb78d68 --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.h @@ -0,0 +1,15 @@ +#ifndef ENNEMY_H +#define ENNEMY_H + +#include "player.h" +#include "map.h" +#include "render.h" +#include "ball.h" + + + + +void initEnnemy(); +void manageEnnemy(); + +#endif \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/main.c b/travail_de_groupe/jeu_appren_par_renfo/src/main.c index 494f09cabbfe82ce3e68d0dddb902dd3e18dbb25..f8adb80f0f4020dc95969b76434c363ff8eacaa9 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/main.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/main.c @@ -10,6 +10,7 @@ int main() readMapFromFile("map.txt"); initPlayer(); + initEnnemy(); initKeys(); initBall(); diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/main.h b/travail_de_groupe/jeu_appren_par_renfo/src/main.h index 79000c0c4c8b73790de9ea6bd46d81a028aae568..98ff609a9d732bc8e391d0b4d6568218e83e4ede 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/main.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/main.h @@ -13,10 +13,12 @@ #include <pthread.h> -#include "render.h" #include "gest_event.h" +#include "player.h" +#include "ennemy.h" #include "map.h" #include "qlearn.h" +#include "render.h" #define MENU 0 #define GAME 1 diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/map.h b/travail_de_groupe/jeu_appren_par_renfo/src/map.h index 2e1bb0c956565fabd5049a4d334f69815aee177d..e291f869f9b2356f715534295bc6374dc8ba51ca 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/map.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/map.h @@ -1,7 +1,11 @@ #ifndef MAP_HEADER_ #define MAP_HEADER_ -#include "main.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +//#include "main.h" #define MAP_WIDTH 31 #define MAP_HEIGHT 10 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 3d5357e1d0a59a5243274af83a19d53c19e27b9c..ee061278a371646b4c07ff2758ae3a89ead63c0c 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.c @@ -99,24 +99,6 @@ void hitBall() } } -void updateBall() -{ - ball.x = ball.x + ball.speed * cos(ball.angle); - ball.y = ball.y + ball.speed * sin(ball.angle); - if (ball.isHit) - { - // landingPoint est déjà / BLOCK_SIZE de base - ball.z = lagrangeInterpolation(ball.x / BLOCK_SIZE, lastHitPoint[0] / BLOCK_SIZE, lastHitPoint[1] / BLOCK_SIZE, 15, 2 * player.h / BLOCK_SIZE, landingPoint[0], 0); - } - - if ((int)ball.z == 0) - { - ball.x = 0; - ball.y = 0; - ball.z = 0; - ball.speed = 0; - } -} void manageMovement() { 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 84e92bf7594fc34d45f9ef4f778eed641fd5ab98..af0ca971a4fb605ec00e9cf372f9232ed12df0d7 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.h @@ -38,6 +38,7 @@ typedef struct player extern player_t player; extern player_t ennemy; extern int *landingPoint; +extern int *lastHitPoint; extern int landingPointIsFind; void initPlayer(); 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 561c72988684a80a5086617c6f20e4e32d883888..82133de31e4e62f212d8749841afff63ada03137 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.c @@ -262,6 +262,202 @@ void drawHorizentalWalls() } } +void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *returnXWall, int *returnYWall, int *returnXNet, int *returnYNet) +{ + // ray casting variables + int mx, my, dof; + double rx, ry, rx2, ry2, xo, yo, distT2; + double ra; + mx = 0; + my = 0; + raysListHead.next = NULL; + ra = angle; + if (ra < 0) + ra -= 2 * pi; + if (ra > 2 * pi) + ra -= 2 * pi; + // check horizontal rays + int foundSolidWallH = 0; + dof = 0; + float disH, hx = player.x, hy = player.y, hx2 = player.x, hy2 = player.y; + float aTan = -1 / tan(ra); + if (ra > pi) + { // looking up + ry = (((int)player.y >> 6) << 6) - 0.0001; + rx = (player.y - ry) * aTan + player.x; + yo = -BLOCK_SIZE; + xo = -yo * aTan; + } + if (ra < pi) + { // looking down + ry = (((int)player.y >> 6) << 6) + BLOCK_SIZE; + rx = (player.y - ry) * aTan + player.x; + yo = BLOCK_SIZE; + xo = -yo * aTan; + } + if (ra == pi) + { + ry = player.y; + rx = player.x; + dof = DOF; + } + while (dof < DOF) + { + mx = (int)rx >> 6; + my = (int)ry >> 6; + if (mx >= 0 && mx < MAP_WIDTH && my >= 0 && my < MAP_HEIGHT) + { + if (map[my][mx] == 1) + { + hx = rx; + hy = ry; + disH = sqrt((rx - player.x) * (rx - player.x) + (ry - player.y) * (ry - player.y)); + dof = DOF; + foundSolidWallH = 1; + } + else + { + hx2 = rx; + hy2 = ry; + dof++; + rx += xo; + ry += yo; + } + } + else + { + rx += xo; + ry += yo; + dof++; + } + } + + // check vertical rays + dof = 0; + float disV = 100000, disV2 = 100000, vx = player.x, vy = player.y, vx2, vy2; + float nTan = -tan(ra); + if (ra > pi / 2 && ra < 3 * pi / 2) + { // looking left + rx = (((int)player.x >> 6) << 6) - 0.0001; + ry = player.y + (player.x - rx) * nTan; + xo = -BLOCK_SIZE; + yo = -xo * nTan; + } + if (ra < pi / 2 || ra > 3 * pi / 2) + { // looking right + rx = (((int)player.x >> 6) << 6) + BLOCK_SIZE; + ry = player.y + (player.x - rx) * nTan; + xo = BLOCK_SIZE; + yo = -xo * nTan; + } + if (ra == pi || ra == 0) + { + ry = player.y; + rx = player.x; + dof = DOF; + } + int foundSolidWallV = 0; + int foundTransparentWallV = 0; + while (dof < DOF) + { + mx = (int)rx >> 6; + my = (int)ry >> 6; + if (mx >= 0 && mx < MAP_WIDTH && my >= 0 && my < MAP_HEIGHT && map[my][mx]) + { + if (map[my][mx] == 1) + { + vx = rx; + vy = ry; + disV = sqrt((rx - player.x) * (rx - player.x) + (ry - player.y) * (ry - player.y)); + foundSolidWallV = 1; + dof = DOF; + } + else + { + vx2 = rx; + vy2 = ry; + disV2 = sqrt((rx - player.x) * (rx - player.x) + (ry - player.y) * (ry - player.y)); + foundTransparentWallV = 1; + dof++; + rx += xo; + ry += yo; + } + } + else + { + rx += xo; + ry += yo; + dof++; + } + } + + if (foundTransparentWallV) + { + if (disH < disV2) + { + rx = hx2; + ry = hy2; + distT2 = disV2; + } + else + { + rx = vx2; + ry = vy2; + } + if (foundSolidWallV) + { + if (disH < disV) + { + rx2 = hx; + ry2 = hy; + distT2 = disH; + } + else + { + rx2 = vx; + ry2 = vy; + distT2 = disV; + } + } + if (foundSolidWallH) + { + if (disH < disV) + { + rx2 = hx; + ry2 = hy; + distT2 = disH; + } + else + { + rx2 = vx; + ry2 = vy; + distT2 = disV; + } + } + } + else + { + if (disH < disV) + { + rx = hx; + ry = hy; + } + else + { + rx = vx; + ry = vy; + } + } + + *returnXWall = (int)rx2; + *returnYWall = (int)ry2; + *distanceWall = distT2; + + *returnXNet = (int)rx; + *returnYNet = (int)ry2; + *distanceNet = (int)distT2; +} + void castRays(int map[][MAP_WIDTH]) { // ray casting variables @@ -564,201 +760,6 @@ void drawEnnemy() } } -void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *returnXWall, int *returnYWall, int *returnXNet, int *returnYNet) -{ - // ray casting variables - int mx, my, dof; - double rx, ry, rx2, ry2, xo, yo, distT2; - double ra; - mx = 0; - my = 0; - raysListHead.next = NULL; - ra = angle; - if (ra < 0) - ra -= 2 * pi; - if (ra > 2 * pi) - ra -= 2 * pi; - // check horizontal rays - int foundSolidWallH = 0; - dof = 0; - float disH, hx = player.x, hy = player.y, hx2 = player.x, hy2 = player.y; - float aTan = -1 / tan(ra); - if (ra > pi) - { // looking up - ry = (((int)player.y >> 6) << 6) - 0.0001; - rx = (player.y - ry) * aTan + player.x; - yo = -BLOCK_SIZE; - xo = -yo * aTan; - } - if (ra < pi) - { // looking down - ry = (((int)player.y >> 6) << 6) + BLOCK_SIZE; - rx = (player.y - ry) * aTan + player.x; - yo = BLOCK_SIZE; - xo = -yo * aTan; - } - if (ra == pi) - { - ry = player.y; - rx = player.x; - dof = DOF; - } - while (dof < DOF) - { - mx = (int)rx >> 6; - my = (int)ry >> 6; - if (mx >= 0 && mx < MAP_WIDTH && my >= 0 && my < MAP_HEIGHT) - { - if (map[my][mx] == 1) - { - hx = rx; - hy = ry; - disH = sqrt((rx - player.x) * (rx - player.x) + (ry - player.y) * (ry - player.y)); - dof = DOF; - foundSolidWallH = 1; - } - else - { - hx2 = rx; - hy2 = ry; - dof++; - rx += xo; - ry += yo; - } - } - else - { - rx += xo; - ry += yo; - dof++; - } - } - - // check vertical rays - dof = 0; - float disV = 100000, disV2 = 100000, vx = player.x, vy = player.y, vx2, vy2; - float nTan = -tan(ra); - if (ra > pi / 2 && ra < 3 * pi / 2) - { // looking left - rx = (((int)player.x >> 6) << 6) - 0.0001; - ry = player.y + (player.x - rx) * nTan; - xo = -BLOCK_SIZE; - yo = -xo * nTan; - } - if (ra < pi / 2 || ra > 3 * pi / 2) - { // looking right - rx = (((int)player.x >> 6) << 6) + BLOCK_SIZE; - ry = player.y + (player.x - rx) * nTan; - xo = BLOCK_SIZE; - yo = -xo * nTan; - } - if (ra == pi || ra == 0) - { - ry = player.y; - rx = player.x; - dof = DOF; - } - int foundSolidWallV = 0; - int foundTransparentWallV = 0; - while (dof < DOF) - { - mx = (int)rx >> 6; - my = (int)ry >> 6; - if (mx >= 0 && mx < MAP_WIDTH && my >= 0 && my < MAP_HEIGHT && map[my][mx]) - { - if (map[my][mx] == 1) - { - vx = rx; - vy = ry; - disV = sqrt((rx - player.x) * (rx - player.x) + (ry - player.y) * (ry - player.y)); - foundSolidWallV = 1; - dof = DOF; - } - else - { - vx2 = rx; - vy2 = ry; - disV2 = sqrt((rx - player.x) * (rx - player.x) + (ry - player.y) * (ry - player.y)); - foundTransparentWallV = 1; - dof++; - rx += xo; - ry += yo; - } - } - else - { - rx += xo; - ry += yo; - dof++; - } - } - - if (foundTransparentWallV) - { - if (disH < disV2) - { - rx = hx2; - ry = hy2; - distT2 = disV2; - } - else - { - rx = vx2; - ry = vy2; - } - if (foundSolidWallV) - { - if (disH < disV) - { - rx2 = hx; - ry2 = hy; - distT2 = disH; - } - else - { - rx2 = vx; - ry2 = vy; - distT2 = disV; - } - } - if (foundSolidWallH) - { - if (disH < disV) - { - rx2 = hx; - ry2 = hy; - distT2 = disH; - } - else - { - rx2 = vx; - ry2 = vy; - distT2 = disV; - } - } - } - else - { - if (disH < disV) - { - rx = hx; - ry = hy; - } - else - { - rx = vx; - ry = vy; - } - } - - *returnXWall = (int)rx2; - *returnYWall = (int)ry2; - *distanceWall = distT2; - - *returnXNet = (int)rx; - *returnYNet = (int)ry2; - *distanceNet = (int)distT2; -} int isAngleInRange(float angle, float min, float max) { @@ -769,7 +770,6 @@ void drawBall() { float ballAngle = atan2(ball.y - player.y, ball.x - player.x); 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); float ballViewAngle = atan2(ball.z * BLOCK_SIZE, ballDistanceX); int ballWidth = 25;