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

ajout affichage de la balle

parent a54b00db
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -29,6 +29,7 @@ typedef struct player{
extern player_t player;
extern player_t ennemy;
extern player_t ball;
void initPlayer();
void managePlayer();
......
......@@ -427,6 +427,33 @@ void drawEnnemy(){
}
}
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);
}
}
void drawSkyAndGround(){
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderFillRect(renderer, NULL);
......@@ -503,6 +530,7 @@ void drawGame(){
drawHorizentalRays();
drawEnnemy();
drawVerticalRays();
drawBall();
drawMap2D(map);
drawFPS();
SDL_RenderPresent(renderer);
......
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