Skip to content
Snippets Groups Projects
Commit 1527c1a9 authored by Taha Belkhiri's avatar Taha Belkhiri
Browse files

ajout des supporters et des filets

parent c6631086
No related branches found
No related tags found
No related merge requests found
travail_de_groupe/jeu_appren_par_renfo/Res/crowd.png

514 B

travail_de_groupe/jeu_appren_par_renfo/Res/net.png

250 B

...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
......
...@@ -6,13 +6,24 @@ SDL_Renderer *renderer; ...@@ -6,13 +6,24 @@ SDL_Renderer *renderer;
TTF_Font *RobotoFont; TTF_Font *RobotoFont;
SDL_DisplayMode screenDimension; SDL_DisplayMode screenDimension;
SDL_Rect destRect;
SDL_Rect rect; SDL_Rect rect;
SDL_Rect sky; SDL_Rect sky;
SDL_Rect ground; SDL_Rect ground;
SDL_Texture * netTexture;
SDL_Texture * crowdTexture;
int ** rays; int ** rays;
int raysListLength = 0; int raysListLength = 0;
SDL_Texture * loadTexture(char * path) {
SDL_Surface * surface = IMG_Load(path);
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
return texture;
}
void initRays(){ void initRays(){
int i; int i;
rays = malloc(sizeof(int*) * 2 * NB_RAYS); rays = malloc(sizeof(int*) * 2 * NB_RAYS);
...@@ -80,7 +91,7 @@ void endSDL(){ ...@@ -80,7 +91,7 @@ void endSDL(){
SDL_Quit(); SDL_Quit();
} }
void drawRayColumn(float ra, float distT, int r, int isTransparent, int direction){ void drawRayColumn(float ra, float distT, int r, int isTransparent, int direction, float htexture){
float ca = player.angle - ra; float ca = player.angle - ra;
if (ca < 0) ca += 2*pi; if (ca < 0) ca += 2*pi;
if (ca > 2*pi) ca -= 2*pi; if (ca > 2*pi) ca -= 2*pi;
...@@ -92,24 +103,35 @@ void drawRayColumn(float ra, float distT, int r, int isTransparent, int directio ...@@ -92,24 +103,35 @@ void drawRayColumn(float ra, float distT, int r, int isTransparent, int directio
rect.w = 1; rect.w = 1;
rect.h = (2 * screenDimension.w * lineH/20); rect.h = (2 * screenDimension.w * lineH/20);
destRect.x = htexture;
destRect.y = 0;
destRect.w = 1;
destRect.h = 64;
if (isTransparent){ if (isTransparent){
rect.h *= 0.75; rect.h *= 1.75;
rect.y -= rect.h/3; rect.y -= rect.h/3;
} SDL_RenderCopy(renderer, netTexture, &destRect, &rect);
if (direction){
SDL_SetRenderDrawColor(renderer, 255 * (1 - isTransparent), 255, 0, 255 * (1 - isTransparent));
} }
else { else {
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255 * (1 - isTransparent)); if (direction){
SDL_RenderCopy(renderer, crowdTexture, &destRect, &rect);
//SDL_SetRenderDrawColor(renderer, 255 * (1 - isTransparent), 255, 0, 255 * (1 - isTransparent));
}
else {
SDL_RenderCopy(renderer, crowdTexture, &destRect, &rect);
//SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255 * (1 - isTransparent));
}
} }
SDL_RenderFillRect(renderer, &rect); //SDL_RenderFillRect(renderer, &rect);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); //SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
} }
void drawRays(int map[][MAP_WIDTH]){ void drawRays(int map[][MAP_WIDTH]){
// ray casting variables // ray casting variables
float htexture; float htexture, htexture2;
int r, mx, my, dof; int r, mx, my, dof;
double rx, ry, rx2, ry2, xo, yo, distT, distT2; double rx, ry, rx2, ry2, xo, yo, distT, distT2;
double ra; double ra;
...@@ -230,12 +252,14 @@ void drawRays(int map[][MAP_WIDTH]){ ...@@ -230,12 +252,14 @@ void drawRays(int map[][MAP_WIDTH]){
ry = hy2; ry = hy2;
distT = disH2; distT = disH2;
direction = 0; direction = 0;
htexture = (int)(rx)%BLOCK_SIZE;
} }
else { else {
rx = vx2; rx = vx2;
ry = vy2; ry = vy2;
distT = disV2; distT = disV2;
direction = 1; direction = 1;
htexture = (int)(ry)%BLOCK_SIZE;
} }
if (foundSolidWallV){ if (foundSolidWallV){
if (disH < disV){ if (disH < disV){
...@@ -243,12 +267,14 @@ void drawRays(int map[][MAP_WIDTH]){ ...@@ -243,12 +267,14 @@ void drawRays(int map[][MAP_WIDTH]){
ry2 = hy; ry2 = hy;
distT2 = disH; distT2 = disH;
direction2 = 0; direction2 = 0;
htexture2 = (int)(rx2)%BLOCK_SIZE;
} }
else { else {
rx2 = vx; rx2 = vx;
ry2 = vy; ry2 = vy;
distT2 = disV; distT2 = disV;
direction2 = 1; direction2 = 1;
htexture2 = (int)(ry2)%BLOCK_SIZE;
} }
} }
if (foundSolidWallH){ if (foundSolidWallH){
...@@ -257,12 +283,14 @@ void drawRays(int map[][MAP_WIDTH]){ ...@@ -257,12 +283,14 @@ void drawRays(int map[][MAP_WIDTH]){
ry2 = hy; ry2 = hy;
distT2 = disH; distT2 = disH;
direction2 = 0; direction2 = 0;
htexture2 = (int)(rx2)%BLOCK_SIZE;
} }
else { else {
rx2 = vx; rx2 = vx;
ry2 = vy; ry2 = vy;
distT2 = disV; distT2 = disV;
direction2 = 1; direction2 = 1;
htexture2 = (int)(ry2)%BLOCK_SIZE;
} }
} }
} }
...@@ -273,12 +301,14 @@ void drawRays(int map[][MAP_WIDTH]){ ...@@ -273,12 +301,14 @@ void drawRays(int map[][MAP_WIDTH]){
ry = hy; ry = hy;
distT = disH; distT = disH;
direction = 0; direction = 0;
htexture = (int)(rx)%BLOCK_SIZE;
} }
else { else {
rx = vx; rx = vx;
ry = vy; ry = vy;
distT = disV; distT = disV;
direction = 1; direction = 1;
htexture = (int)(ry)%BLOCK_SIZE;
} }
} }
...@@ -288,15 +318,15 @@ void drawRays(int map[][MAP_WIDTH]){ ...@@ -288,15 +318,15 @@ void drawRays(int map[][MAP_WIDTH]){
if (ra < 0) ra += 2*pi; if (ra < 0) ra += 2*pi;
// draw ray // draw ray
drawRayColumn(ra, distT, r, foundTransparentWallV, direction);
if (foundTransparentWallV){ if (foundTransparentWallV){
if (foundSolidWallV){ if (foundSolidWallV){
drawRayColumn(ra, distT2, r, 0, direction2); drawRayColumn(ra, distT2, r, 0, direction2 , htexture2);
} }
else { else {
drawRayColumn(ra, distT2, r, 0, direction); drawRayColumn(ra, distT2, r, 0, direction, htexture2);
} }
} }
drawRayColumn(ra, distT, r, foundTransparentWallV, direction, htexture);
// draw the ray in the minimap // draw the ray in the minimap
addRayToList(rx, ry); addRayToList(rx, ry);
...@@ -365,6 +395,9 @@ void mainLoop(){ ...@@ -365,6 +395,9 @@ void mainLoop(){
createWindow(); createWindow();
initRays(); initRays();
netTexture = loadTexture("Res/net.png");
crowdTexture = loadTexture("Res/crowd.png");
unsigned int a = SDL_GetTicks(); unsigned int a = SDL_GetTicks();
unsigned int b = SDL_GetTicks(); unsigned int b = SDL_GetTicks();
double delta = 0; double delta = 0;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#define DOF 100 #define DOF 100
#define BLOCK_SIZE 64 #define BLOCK_SIZE 64
#define DR 0.0174533 #define DR 0.0174533
#define FOV_ANGLE 60 #define FOV_ANGLE 80
#define pi 3.14159265358979323846 #define pi 3.14159265358979323846
#define NB_RAYS (screenDimension.w) #define NB_RAYS (screenDimension.w)
#define ANGLE_INC ((DR * FOV_ANGLE) / NB_RAYS) #define ANGLE_INC ((DR * FOV_ANGLE) / NB_RAYS)
......
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