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

Merge branch 'render'

parents 32149ad5 bbc523a8
No related branches found
No related tags found
No related merge requests found
travail_de_groupe/jeu_appren_par_renfo/Res/player_sprite.png

1.03 KiB

......@@ -9,6 +9,12 @@ void initBall (){
}
double f(int x, float xc, float yc, float xf, float yf, float xt, float yt){
double returnValue = yf * ((x - xc)/(xf - xc)) * ((x - xt)/(xf - xt)) + yc * ((x - xf)/(xc - xf)) * ((x - xt)/(xc - xt)) + yt * ((x - xc)/(xt - xc)) * ((x - xf)/(xt - xf));
return returnValue;
}
void laGrange (float beta[3],float Z[3]){ // y , x
printf("x canon : %f, x chute : %f, x filet : %f\n", Z[0], Z[1], Z[2]);
printf("y canon : %f, y chute : %f, y filet : %f\n", beta[0], beta[1], beta[2]);
......@@ -40,6 +46,9 @@ void calculationTrajectory(canon_t canon, int xDropPoint, int yDropPoint){
float setUp[2][3];
float distance= (float)(yDropPoint-canon.y);
printf("test : %f\n", y);
trajectory[0][0]=canon.y;
trajectory[0][1]=canon.x;
......@@ -65,7 +74,7 @@ void calculationTrajectory(canon_t canon, int xDropPoint, int yDropPoint){
laGrange(setUp[1],setUp[0]); //laGrange(y, x);
printf("coef a:%f; coef b:%f; coef c:%f\n", coefLagrange.a, coefLagrange.b, coefLagrange.c);
//printf("coef a:%f; coef b:%f; coef c:%f\n", coefLagrange.a, coefLagrange.b, coefLagrange.c);
float step= distance / (NUMBERPOINT-1);
......
......@@ -251,7 +251,7 @@ void drawTrajectoireSideView(){
);
for(int i=0; i<NUMBERPOINT-1; i++){
printf("point %d (%d, %d)\n", i, trajectory[i][0], trajectory[i][1]);
//printf("point %d (%d, %d)\n", i, trajectory[i][0], trajectory[i][1]);
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderDrawLine(renderer, trajectory[i][0], trajectory[i][1], trajectory[i+1][0], trajectory[i+1][1]);
}
......
......@@ -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();
......
......@@ -13,6 +13,7 @@ SDL_Rect ground;
SDL_Texture * netTexture;
SDL_Texture * crowdTexture;
SDL_Texture * playerTexture;
int ** rays;
int raysListLength = 0;
......@@ -162,12 +163,24 @@ void drawRayColumn(rayInfo_t * rayInfo){
}
}
void drawRays(){
void drawVerticalRays(){
rayInfo_t * current = raysListHead.next;
while (current != NULL){
//printf("%p\n", current);
fflush(stdout);
drawRayColumn(current);
if (current->direction){
drawRayColumn(current);
}
current = current->next;
}
}
void drawHorizentalRays(){
rayInfo_t * current = raysListHead.next;
while (current != NULL){
//printf("%p\n", current);
if (!current->direction){
drawRayColumn(current);
}
current = current->next;
}
}
......@@ -401,14 +414,43 @@ void drawEnnemy(){
if (ennemyAngle >= player.angle - (FOV_ANGLE)/2 * DR && ennemyAngle <= player.angle + (FOV_ANGLE)/2 * DR){
rect.x = screenDimension.w/2 + (screenDimension.w * tan(ennemyAngle - player.angle)) * sqrt(3) * 0.5;
rect.y = (screenDimension.h/2 + player.angle) - MAP_WIDTH * ennemyDistance/200000;
rect.w = (ennemyWidth * screenDimension.w) / (ennemyDistance/BLOCK_SIZE);
rect.h = (ennemyHeight * screenDimension.h)/(ennemyDistance/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);
}
}
//printf("%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h);
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, &rect);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
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);
}
}
......@@ -485,8 +527,10 @@ void drawGame(){
SDL_RenderClear(renderer);
drawSkyAndGround();
castRays(map);
drawHorizentalRays();
drawEnnemy();
drawRays();
drawVerticalRays();
drawBall();
drawMap2D(map);
drawFPS();
SDL_RenderPresent(renderer);
......@@ -500,6 +544,7 @@ void mainLoop(){
netTexture = loadTexture("Res/net.png");
crowdTexture = loadTexture("Res/crowd.png");
playerTexture = loadTexture("Res/player_sprite.png");
unsigned int a = SDL_GetTicks();
unsigned int b = SDL_GetTicks();
......
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