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

ennemy peut renvoyer la balle

parent 55dbb8e6
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,8 @@ int trajectoireAntoine[NUMBERPOINT_TRAJEC][2];
void initBall()
{
ball.x = (rand()%(MAP_WIDTH/2)) * BLOCK_SIZE + BLOCK_SIZE;
ball.y = (rand()% (MAP_HEIGHT - 2)) * BLOCK_SIZE + BLOCK_SIZE;
ball.x = player.x + player.w / 2;
ball.y = player.y;
ball.z = player.h / BLOCK_SIZE;
ball.h = 0.5 * BLOCK_SIZE;
ball.w = 0.5 * BLOCK_SIZE;
......@@ -137,11 +137,4 @@ void updateBall()
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;
}
}
......@@ -29,19 +29,19 @@ void manageEnnemyMovement()
switch (action)
{
case BACK:
ennemy.x += MOVEMENT_SPEED;
ennemy.x += BLOCK_SIZE;
break;
case FOWARD:
ennemy.x -= MOVEMENT_SPEED;
ennemy.x -= BLOCK_SIZE;
break;
case UP:
ennemy.y -= MOVEMENT_SPEED;
ennemy.y -= BLOCK_SIZE;
break;
case DOWN:
ennemy.y += MOVEMENT_SPEED;
ennemy.y += BLOCK_SIZE;
break;
default:
......@@ -50,6 +50,31 @@ void manageEnnemyMovement()
}
}
void generateLandingPointEnnemy(){
landingPoint[0] = rand() % ((MAP_WIDTH/2));
landingPoint[1] = rand() % (MAP_HEIGHT);
}
void ennemyHitBall(){
if (sqrt(pow(ennemy.x - ball.x, 2) + pow(ennemy.y - ball.y, 2)) / BLOCK_SIZE < HIT_RANGE)
{
if (ball.isTravelingTo == AI)
{
ball.isTravelingTo = PLAYER;
ball.angle = ennemy.angle;
ball.speed = HIT_FORCE;
ball.isHit = 1;
lastHitPoint[0] = ball.x;
lastHitPoint[1] = player.h;
printf("new lastHitPoint : %d %d\n", lastHitPoint[0], lastHitPoint[1]);
generateLandingPointEnnemy();
}
}
}
void manageEnnemy(){
manageEnnemyMovement();
ennemyHitBall();
}
\ No newline at end of file
......@@ -33,11 +33,12 @@ 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 randomPointX = MAP_WIDTH/2 + 1 + rand()%(rxWall/BLOCK_SIZE - (MAP_WIDTH/2));
int randomPointY = -1;
landingPoint[0] = randomPointX;
landingPoint[0] = randomPointX ;
landingPoint[1] = randomPointY / BLOCK_SIZE;
landingPointIsFind = 1;
......@@ -71,16 +72,16 @@ void hitBall()
float distanceNet;
if (player.isHitting)
{
castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet);
if (rxWall > MAP_WIDTH / 2)
castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet);
// printf("hit\n");
if (rxWall > MAP_WIDTH/2)
{
freeIntList(lastHitPoint);
lastHitPoint = allocLastHitPoint();
// cherche et trouve point de chute, UNE SEULE FOIS!
if (landingPointIsFind == 0)
{
//cherche et trouve point de chute, UNE SEULE FOIS!
if(landingPointIsFind == 0){
freeIntList(landingPoint);
landingPoint = generateLandingPoint(rxWall);
printf("landing point: x=%d; y=%d\n", landingPoint[0], landingPoint[1]);
......@@ -90,16 +91,21 @@ void hitBall()
lastHitPoint[1] = player.h;
ball.angle = player.angle;
ball.speed = 2 * HIT_FORCE;
ball.speed = HIT_FORCE;
ball.z = player.h;
ball.isHit = 1;
ball.isTravelingTo = AI;
}
// printf("valid hit\n");
}
else
{
// printf("unvalid hit\n");
}
}
//}
}
void manageMovement()
{
// z : keys[2] : avance
......@@ -110,8 +116,7 @@ void manageMovement()
float y_increment = (Keys[0] - Keys[2]) * player.deltay + (Keys[1] - Keys[3]) * cos(player.angle);
float newpos_x = (player.x + x_increment * MOVEMENT_SPEED) / BLOCK_SIZE;
float newpos_y = (player.y + y_increment * MOVEMENT_SPEED) / BLOCK_SIZE;
int widthColli = player.w / (3 * BLOCK_SIZE);
if (newpos_x > widthColli && newpos_x < MAP_WIDTH - widthColli && newpos_y > widthColli && newpos_y < MAP_HEIGHT - widthColli)
if (newpos_x >= 0 && newpos_x < MAP_WIDTH && newpos_y >= 0 && newpos_y < MAP_HEIGHT)
{
if (map[(int)newpos_y][(int)newpos_x] != 1)
{
......@@ -125,4 +130,5 @@ void managePlayer()
{
manageMovement();
hitBall();
updateBall();
}
\ No newline at end of file
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