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 21981dac9e00bf87b480e46e9ede141c49a8ab0b..9c3acb03b507c92c84055610aa8d69ea262de04f 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/ball.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ball.c @@ -136,5 +136,9 @@ void updateBall() // 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 (ball.z < 0) + { + initBall(); + } } diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c b/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c index 97c02fc21c4af20d271555bd970f7383d7929f92..1a1d3f95912b4db1d902266807ea79a8afd82602 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c @@ -90,9 +90,16 @@ void manageEnnemyMovement() } } -void generateLandingPointEnnemy(){ - landingPoint[0] = rand() % ((MAP_WIDTH/2)); - landingPoint[1] = rand() % (MAP_HEIGHT); +int * generateLandingPointEnnemy(){ + int *landingPoint = malloc(sizeof(int) * 2); + + int randomPointX = rand() % ((MAP_WIDTH/2)); + + landingPoint[0] = randomPointX ; + landingPoint[1] = 0; + landingPointIsFind = 1; + + return landingPoint; } void ennemyHitBall(){ @@ -101,6 +108,10 @@ void ennemyHitBall(){ if (ball.isTravelingTo == AI) { + if(landingPointIsFind == 0){ + freeIntList(landingPoint); + landingPoint = generateLandingPointEnnemy(); + } ball.isTravelingTo = PLAYER; ball.angle = ennemy.angle; ball.speed = HIT_FORCE; @@ -108,13 +119,17 @@ void ennemyHitBall(){ lastHitPoint[0] = ball.x; lastHitPoint[1] = player.h; - printf("new lastHitPoint : %d %d\n", lastHitPoint[0], lastHitPoint[1]); - generateLandingPointEnnemy(); + printf("ennemy new lastHitPoint : %d %d\n", lastHitPoint[0]/BLOCK_SIZE, lastHitPoint[1]/BLOCK_SIZE); + + printf("ennemy new landingPoint : %d %d\n", landingPoint[0]/BLOCK_SIZE, landingPoint[1]/BLOCK_SIZE); } } } void manageEnnemy(){ - manageEnnemyMovement(); + if (SDL_GetTicks() % 1000 < 100) + { + manageEnnemyMovement(); + } ennemyHitBall(); } \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c b/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c index abe4bb24cb8d7a997907400f60c10a86c26f6f46..7e2656a61fe2fc93d978cfd4d068f2585fd52c76 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c @@ -114,11 +114,12 @@ void gestGame() { showHub = 0; } + break; case SDLK_b: initBall(); landingPointIsFind = 0; - continue; + break; default: break; 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 6523e57de6ed670d9f1c2d12b823fcc58df11c08..b6d289bad2bcb17d39bbb2ed928b1ea74d144ad2 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.c @@ -33,13 +33,11 @@ void initPlayer() int *generateLandingPoint(int rxWall) { int *landingPoint = malloc(sizeof(int) * 2); - srand(time(NULL)); int randomPointX = MAP_WIDTH/2 + 1 + rand()%(rxWall/BLOCK_SIZE - (MAP_WIDTH/2)); - int randomPointY = -1; landingPoint[0] = randomPointX ; - landingPoint[1] = randomPointY / BLOCK_SIZE; + landingPoint[1] = 0; landingPointIsFind = 1; return landingPoint; @@ -94,6 +92,10 @@ void hitBall() ball.z = player.h; ball.isHit = 1; ball.isTravelingTo = AI; + + printf("ennemy new lastHitPoint : %d %d\n", lastHitPoint[0]/BLOCK_SIZE, lastHitPoint[1]/BLOCK_SIZE); + + printf("ennemy new landingPoint : %d %d\n", landingPoint[0]/BLOCK_SIZE, landingPoint[1]/BLOCK_SIZE); } // printf("valid hit\n"); } 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 af0ca971a4fb605ec00e9cf372f9232ed12df0d7..ca036f8f246d56c3d93046d0c21c4ffead7b7cc7 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.h @@ -11,7 +11,7 @@ #define ENTITIES_RIGHT 3 #define HIT_RANGE 2 -#define HIT_FORCE 10 +#define HIT_FORCE 2 #define MOVEMENT_SPEED 10 typedef struct player @@ -43,5 +43,6 @@ extern int landingPointIsFind; void initPlayer(); void managePlayer(); +void freeIntList(int *list); #endif \ No newline at end of file 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 0f71a7a840f624857b66013e7401da3cc2bcf13f..02a5f7c08cc96b0ae1696de6f1e1fe14d7728993 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.c @@ -12,7 +12,7 @@ SDL_Rect sky; SDL_Rect ground; SDL_Rect racket; -int showHub = 0; +int showHub = 1; SDL_Texture *netTexture; SDL_Texture *netEdgeLeftTexture;