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

gameplay un peu mieux

parent aece77d2
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
}
......@@ -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
......@@ -114,11 +114,12 @@ void gestGame()
{
showHub = 0;
}
break;
case SDLK_b:
initBall();
landingPointIsFind = 0;
continue;
break;
default:
break;
......
......@@ -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");
}
......
......@@ -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
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment