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

fixed includes and function/file placements

parent 858b46e5
No related branches found
No related tags found
No related merge requests found
......@@ -93,3 +93,22 @@ void calculTrajectoireAntoine2(int xd, int yd, int xf, int yf, int xt, int yt)
trajectoireAntoine[NUMBERPOINT_TRAJEC - 1][0] = xt;
trajectoireAntoine[NUMBERPOINT_TRAJEC - 1][1] = yt;
}
void updateBall()
{
ball.x = ball.x + ball.speed * cos(ball.angle);
ball.y = ball.y + ball.speed * sin(ball.angle);
if (ball.isHit)
{
// 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 ((int)ball.z == 0)
{
ball.x = 0;
ball.y = 0;
ball.z = 0;
ball.speed = 0;
}
}
......@@ -33,6 +33,7 @@ extern int trajectoireAntoine[NUMBERPOINT_TRAJEC][2];
void initBall();
float defineAngle(int, int, int, int);
void updateBall();
float lagrangeInterpolation(float, int, int, int, int, int, int);
void calculTrajectoireAntoine2(int, int, int, int, int, int);
......
#include "player.h"
void initEnnemy()
{
ennemy.h = 2 * BLOCK_SIZE;
ennemy.w = 2 * BLOCK_SIZE;
ennemy.x = 25 * BLOCK_SIZE;
ennemy.y = 5 * BLOCK_SIZE;
ennemy.angle = -pi;
}
void manageEnnemy()
{
}
\ No newline at end of file
#ifndef ENNEMY_H
#define ENNEMY_H
#include "player.h"
#include "map.h"
#include "render.h"
#include "ball.h"
void initEnnemy();
void manageEnnemy();
#endif
\ No newline at end of file
......@@ -10,6 +10,7 @@ int main()
readMapFromFile("map.txt");
initPlayer();
initEnnemy();
initKeys();
initBall();
......
......@@ -13,10 +13,12 @@
#include <pthread.h>
#include "render.h"
#include "gest_event.h"
#include "player.h"
#include "ennemy.h"
#include "map.h"
#include "qlearn.h"
#include "render.h"
#define MENU 0
#define GAME 1
......
#ifndef MAP_HEADER_
#define MAP_HEADER_
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include "main.h"
#define MAP_WIDTH 31
#define MAP_HEIGHT 10
......
......@@ -99,24 +99,6 @@ void hitBall()
}
}
void updateBall()
{
ball.x = ball.x + ball.speed * cos(ball.angle);
ball.y = ball.y + ball.speed * sin(ball.angle);
if (ball.isHit)
{
// 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 ((int)ball.z == 0)
{
ball.x = 0;
ball.y = 0;
ball.z = 0;
ball.speed = 0;
}
}
void manageMovement()
{
......
......@@ -38,6 +38,7 @@ typedef struct player
extern player_t player;
extern player_t ennemy;
extern int *landingPoint;
extern int *lastHitPoint;
extern int landingPointIsFind;
void initPlayer();
......
......@@ -262,6 +262,202 @@ void drawHorizentalWalls()
}
}
void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *returnXWall, int *returnYWall, int *returnXNet, int *returnYNet)
{
// ray casting variables
int mx, my, dof;
double rx, ry, rx2, ry2, xo, yo, distT2;
double ra;
mx = 0;
my = 0;
raysListHead.next = NULL;
ra = angle;
if (ra < 0)
ra -= 2 * pi;
if (ra > 2 * pi)
ra -= 2 * pi;
// check horizontal rays
int foundSolidWallH = 0;
dof = 0;
float disH, hx = player.x, hy = player.y, hx2 = player.x, hy2 = player.y;
float aTan = -1 / tan(ra);
if (ra > pi)
{ // looking up
ry = (((int)player.y >> 6) << 6) - 0.0001;
rx = (player.y - ry) * aTan + player.x;
yo = -BLOCK_SIZE;
xo = -yo * aTan;
}
if (ra < pi)
{ // looking down
ry = (((int)player.y >> 6) << 6) + BLOCK_SIZE;
rx = (player.y - ry) * aTan + player.x;
yo = BLOCK_SIZE;
xo = -yo * aTan;
}
if (ra == pi)
{
ry = player.y;
rx = player.x;
dof = DOF;
}
while (dof < DOF)
{
mx = (int)rx >> 6;
my = (int)ry >> 6;
if (mx >= 0 && mx < MAP_WIDTH && my >= 0 && my < MAP_HEIGHT)
{
if (map[my][mx] == 1)
{
hx = rx;
hy = ry;
disH = sqrt((rx - player.x) * (rx - player.x) + (ry - player.y) * (ry - player.y));
dof = DOF;
foundSolidWallH = 1;
}
else
{
hx2 = rx;
hy2 = ry;
dof++;
rx += xo;
ry += yo;
}
}
else
{
rx += xo;
ry += yo;
dof++;
}
}
// check vertical rays
dof = 0;
float disV = 100000, disV2 = 100000, vx = player.x, vy = player.y, vx2, vy2;
float nTan = -tan(ra);
if (ra > pi / 2 && ra < 3 * pi / 2)
{ // looking left
rx = (((int)player.x >> 6) << 6) - 0.0001;
ry = player.y + (player.x - rx) * nTan;
xo = -BLOCK_SIZE;
yo = -xo * nTan;
}
if (ra < pi / 2 || ra > 3 * pi / 2)
{ // looking right
rx = (((int)player.x >> 6) << 6) + BLOCK_SIZE;
ry = player.y + (player.x - rx) * nTan;
xo = BLOCK_SIZE;
yo = -xo * nTan;
}
if (ra == pi || ra == 0)
{
ry = player.y;
rx = player.x;
dof = DOF;
}
int foundSolidWallV = 0;
int foundTransparentWallV = 0;
while (dof < DOF)
{
mx = (int)rx >> 6;
my = (int)ry >> 6;
if (mx >= 0 && mx < MAP_WIDTH && my >= 0 && my < MAP_HEIGHT && map[my][mx])
{
if (map[my][mx] == 1)
{
vx = rx;
vy = ry;
disV = sqrt((rx - player.x) * (rx - player.x) + (ry - player.y) * (ry - player.y));
foundSolidWallV = 1;
dof = DOF;
}
else
{
vx2 = rx;
vy2 = ry;
disV2 = sqrt((rx - player.x) * (rx - player.x) + (ry - player.y) * (ry - player.y));
foundTransparentWallV = 1;
dof++;
rx += xo;
ry += yo;
}
}
else
{
rx += xo;
ry += yo;
dof++;
}
}
if (foundTransparentWallV)
{
if (disH < disV2)
{
rx = hx2;
ry = hy2;
distT2 = disV2;
}
else
{
rx = vx2;
ry = vy2;
}
if (foundSolidWallV)
{
if (disH < disV)
{
rx2 = hx;
ry2 = hy;
distT2 = disH;
}
else
{
rx2 = vx;
ry2 = vy;
distT2 = disV;
}
}
if (foundSolidWallH)
{
if (disH < disV)
{
rx2 = hx;
ry2 = hy;
distT2 = disH;
}
else
{
rx2 = vx;
ry2 = vy;
distT2 = disV;
}
}
}
else
{
if (disH < disV)
{
rx = hx;
ry = hy;
}
else
{
rx = vx;
ry = vy;
}
}
*returnXWall = (int)rx2;
*returnYWall = (int)ry2;
*distanceWall = distT2;
*returnXNet = (int)rx;
*returnYNet = (int)ry2;
*distanceNet = (int)distT2;
}
void castRays(int map[][MAP_WIDTH])
{
// ray casting variables
......@@ -564,201 +760,6 @@ void drawEnnemy()
}
}
void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *returnXWall, int *returnYWall, int *returnXNet, int *returnYNet)
{
// ray casting variables
int mx, my, dof;
double rx, ry, rx2, ry2, xo, yo, distT2;
double ra;
mx = 0;
my = 0;
raysListHead.next = NULL;
ra = angle;
if (ra < 0)
ra -= 2 * pi;
if (ra > 2 * pi)
ra -= 2 * pi;
// check horizontal rays
int foundSolidWallH = 0;
dof = 0;
float disH, hx = player.x, hy = player.y, hx2 = player.x, hy2 = player.y;
float aTan = -1 / tan(ra);
if (ra > pi)
{ // looking up
ry = (((int)player.y >> 6) << 6) - 0.0001;
rx = (player.y - ry) * aTan + player.x;
yo = -BLOCK_SIZE;
xo = -yo * aTan;
}
if (ra < pi)
{ // looking down
ry = (((int)player.y >> 6) << 6) + BLOCK_SIZE;
rx = (player.y - ry) * aTan + player.x;
yo = BLOCK_SIZE;
xo = -yo * aTan;
}
if (ra == pi)
{
ry = player.y;
rx = player.x;
dof = DOF;
}
while (dof < DOF)
{
mx = (int)rx >> 6;
my = (int)ry >> 6;
if (mx >= 0 && mx < MAP_WIDTH && my >= 0 && my < MAP_HEIGHT)
{
if (map[my][mx] == 1)
{
hx = rx;
hy = ry;
disH = sqrt((rx - player.x) * (rx - player.x) + (ry - player.y) * (ry - player.y));
dof = DOF;
foundSolidWallH = 1;
}
else
{
hx2 = rx;
hy2 = ry;
dof++;
rx += xo;
ry += yo;
}
}
else
{
rx += xo;
ry += yo;
dof++;
}
}
// check vertical rays
dof = 0;
float disV = 100000, disV2 = 100000, vx = player.x, vy = player.y, vx2, vy2;
float nTan = -tan(ra);
if (ra > pi / 2 && ra < 3 * pi / 2)
{ // looking left
rx = (((int)player.x >> 6) << 6) - 0.0001;
ry = player.y + (player.x - rx) * nTan;
xo = -BLOCK_SIZE;
yo = -xo * nTan;
}
if (ra < pi / 2 || ra > 3 * pi / 2)
{ // looking right
rx = (((int)player.x >> 6) << 6) + BLOCK_SIZE;
ry = player.y + (player.x - rx) * nTan;
xo = BLOCK_SIZE;
yo = -xo * nTan;
}
if (ra == pi || ra == 0)
{
ry = player.y;
rx = player.x;
dof = DOF;
}
int foundSolidWallV = 0;
int foundTransparentWallV = 0;
while (dof < DOF)
{
mx = (int)rx >> 6;
my = (int)ry >> 6;
if (mx >= 0 && mx < MAP_WIDTH && my >= 0 && my < MAP_HEIGHT && map[my][mx])
{
if (map[my][mx] == 1)
{
vx = rx;
vy = ry;
disV = sqrt((rx - player.x) * (rx - player.x) + (ry - player.y) * (ry - player.y));
foundSolidWallV = 1;
dof = DOF;
}
else
{
vx2 = rx;
vy2 = ry;
disV2 = sqrt((rx - player.x) * (rx - player.x) + (ry - player.y) * (ry - player.y));
foundTransparentWallV = 1;
dof++;
rx += xo;
ry += yo;
}
}
else
{
rx += xo;
ry += yo;
dof++;
}
}
if (foundTransparentWallV)
{
if (disH < disV2)
{
rx = hx2;
ry = hy2;
distT2 = disV2;
}
else
{
rx = vx2;
ry = vy2;
}
if (foundSolidWallV)
{
if (disH < disV)
{
rx2 = hx;
ry2 = hy;
distT2 = disH;
}
else
{
rx2 = vx;
ry2 = vy;
distT2 = disV;
}
}
if (foundSolidWallH)
{
if (disH < disV)
{
rx2 = hx;
ry2 = hy;
distT2 = disH;
}
else
{
rx2 = vx;
ry2 = vy;
distT2 = disV;
}
}
}
else
{
if (disH < disV)
{
rx = hx;
ry = hy;
}
else
{
rx = vx;
ry = vy;
}
}
*returnXWall = (int)rx2;
*returnYWall = (int)ry2;
*distanceWall = distT2;
*returnXNet = (int)rx;
*returnYNet = (int)ry2;
*distanceNet = (int)distT2;
}
int isAngleInRange(float angle, float min, float max)
{
......@@ -769,7 +770,6 @@ void drawBall()
{
float ballAngle = atan2(ball.y - player.y, ball.x - player.x);
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);
float ballViewAngle = atan2(ball.z * BLOCK_SIZE, ballDistanceX);
int ballWidth = 25;
......
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