plr orientation at begining
This commit is contained in:
2
Makefile
2
Makefile
@@ -79,7 +79,7 @@ RM_OBJS = rm -rf $(D_OBJS)
|
|||||||
|
|
||||||
# flags
|
# flags
|
||||||
CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
|
CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
|
||||||
CFLAGS += -g3
|
CFLAGS += -g3 -Wno-unused
|
||||||
LFLAGS = -L$(D_LFT) -lft
|
LFLAGS = -L$(D_LFT) -lft
|
||||||
LFLAGS += -L$(D_LMLX) -lm -lmlx -lXext -lX11
|
LFLAGS += -L$(D_LMLX) -lm -lmlx -lXext -lX11
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
/* screen focal (in degree) */
|
/* screen focal (in degree) */
|
||||||
# define SCREEN_FOCAL 70
|
# define SCREEN_FOCAL 70
|
||||||
/* size of a cell on the map */
|
/* size of a cell on the map */
|
||||||
# define CELL 40
|
# define CELL 100
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* keys macro
|
* keys macro
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ void plr_posy_increment(t_game *game, t_plr *plr);
|
|||||||
// player_rotates.c
|
// player_rotates.c
|
||||||
void rotate(t_plr *plr, t_coord *coord);
|
void rotate(t_plr *plr, t_coord *coord);
|
||||||
void rotate_double(t_plr *plr, t_d_coord *coord);
|
void rotate_double(t_plr *plr, t_d_coord *coord);
|
||||||
|
void plr_turn(t_plr *plr, int deg);
|
||||||
void plr_turn_right(t_plr *plr);
|
void plr_turn_right(t_plr *plr);
|
||||||
void plr_turn_left(t_plr *plr);
|
void plr_turn_left(t_plr *plr);
|
||||||
// player_limits.c
|
// player_limits.c
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ typedef struct s_map
|
|||||||
int cell;
|
int cell;
|
||||||
int plr_x;
|
int plr_x;
|
||||||
int plr_y;
|
int plr_y;
|
||||||
|
int plr_dir;
|
||||||
} t_map;
|
} t_map;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -165,13 +166,13 @@ typedef struct s_game
|
|||||||
t_map map;
|
t_map map;
|
||||||
|
|
||||||
//tmp draw map
|
//tmp draw map
|
||||||
// map window
|
// // map window
|
||||||
t_win map_win;
|
// t_win map_win;
|
||||||
t_img map_img;
|
// t_img map_img;
|
||||||
// rays
|
// // rays
|
||||||
int ray_highlight;
|
// int ray_highlight;
|
||||||
int ray_activ;
|
// int ray_activ;
|
||||||
t_vec ray;
|
// t_vec ray;
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
// key hook
|
// key hook
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
NO textures/door.xpm
|
NO textures/coin.xpm
|
||||||
SO textures/chalice.xpm
|
SO textures/chalice.xpm
|
||||||
EA textures/brick.xpm
|
EA textures/brick.xpm
|
||||||
WE textures/wood.xpm
|
WE textures/wood.xpm
|
||||||
@@ -8,12 +8,12 @@ F 220 , 100, 30
|
|||||||
C 225 , 30 , 0
|
C 225 , 30 , 0
|
||||||
|
|
||||||
1111111111111111111111111111
|
1111111111111111111111111111
|
||||||
1000000000000000011100000001
|
10000000000000000111N0000001
|
||||||
1111000000000000100000110001
|
1111000000000000100000110001
|
||||||
1111001000000000000110000111
|
1111001000000000000110000111
|
||||||
1000000000000000010101000001
|
1000000000000000010101000001
|
||||||
1111110000000000000000001111
|
1111110000000000000000001111
|
||||||
10000000000000000N0000000001
|
1000000000000000000000000001
|
||||||
1000000000000000000000000001
|
1000000000000000000000000001
|
||||||
1000000000000000000000000001
|
1000000000000000000000000001
|
||||||
1000000000000000000000000001
|
1000000000000000000000000001
|
||||||
|
|||||||
@@ -32,13 +32,19 @@ int main(int ac, char **av)
|
|||||||
{
|
{
|
||||||
t_game *game;
|
t_game *game;
|
||||||
|
|
||||||
|
/*
|
||||||
if ((ac != 2 || check_extension(av[1], ".cub")) && \
|
if ((ac != 2 || check_extension(av[1], ".cub")) && \
|
||||||
write(2, "Error\nPlease use a valid .cub file as single argument.\n", 53))
|
write(2, "Error\nPlease use a valid .cub file as single argument.\n", 53))
|
||||||
return (EXIT_FAILURE);
|
return (EXIT_FAILURE);
|
||||||
|
*/
|
||||||
game = init_struct();
|
game = init_struct();
|
||||||
mb_init(destroy_mlx, game);
|
mb_init(destroy_mlx, game);
|
||||||
if (init_parsing(game, av[1]) && write(2, "The .cub file is invalid.\n", 26))
|
|
||||||
|
if (init_parsing(game, "maps/map_valid_14.cub") && write(2, "The .cub file is invalid.\n", 26))
|
||||||
return (EXIT_FAILURE);
|
return (EXIT_FAILURE);
|
||||||
|
// if (init_parsing(game, av[1]) && write(2, "The .cub file is invalid.\n", 26))
|
||||||
|
// return (EXIT_FAILURE);
|
||||||
|
|
||||||
if (check_map(&(game->map)) && write(2, "The map is invalid.\n", 20))
|
if (check_map(&(game->map)) && write(2, "The map is invalid.\n", 20))
|
||||||
return (EXIT_FAILURE);
|
return (EXIT_FAILURE);
|
||||||
init_game(game);
|
init_game(game);
|
||||||
|
|||||||
145
srcs/draw/draw.c
145
srcs/draw/draw.c
@@ -1,87 +1,64 @@
|
|||||||
#include "cube3d.h"
|
#include "cube3d.h"
|
||||||
|
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
static void draw_square(t_game *game, t_coord pos, int border, int fill, int size, int rotation)
|
// static void draw_square(t_game *game, t_coord pos, int border, int fill, int size, int rotation)
|
||||||
{
|
// {
|
||||||
int i;
|
// int i;
|
||||||
int j;
|
// int j;
|
||||||
t_coord new;
|
// t_coord new;
|
||||||
|
//
|
||||||
i = 0;
|
// i = 0;
|
||||||
while (i < size)
|
// while (i < size)
|
||||||
{
|
// {
|
||||||
j = 0;
|
// j = 0;
|
||||||
while (j < size)
|
// while (j < size)
|
||||||
{
|
// {
|
||||||
new.x = pos.x + j;
|
// new.x = pos.x + j;
|
||||||
new.y = pos.y + i;
|
// new.y = pos.y + i;
|
||||||
if (rotation)
|
// if (rotation)
|
||||||
rotate(&(game->plr), &(new));
|
// rotate(&(game->plr), &(new));
|
||||||
if (!i || i == size - 1)
|
// if (!i || i == size - 1)
|
||||||
draw_pixel(&game->map_img, new.x, new.y, border);
|
// draw_pixel(&game->map_img, new.x, new.y, border);
|
||||||
else if (!j || j == size - 1)
|
// else if (!j || j == size - 1)
|
||||||
draw_pixel(&game->map_img, new.x, new.y, border);
|
// draw_pixel(&game->map_img, new.x, new.y, border);
|
||||||
else
|
// else
|
||||||
draw_pixel(&game->map_img, new.x, new.y, fill);
|
// draw_pixel(&game->map_img, new.x, new.y, fill);
|
||||||
j++;
|
// j++;
|
||||||
}
|
// }
|
||||||
i++;
|
// i++;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
static void draw_map(t_game *game)
|
// static void draw_map(t_game *game)
|
||||||
{
|
// {
|
||||||
t_coord incr;
|
// t_coord incr;
|
||||||
t_coord pos;
|
// t_coord pos;
|
||||||
int cell;
|
// int cell;
|
||||||
|
//
|
||||||
cell = game->map.cell;
|
// cell = game->map.cell;
|
||||||
incr.x = 0;
|
// incr.x = 0;
|
||||||
pos.x = 0;
|
// pos.x = 0;
|
||||||
pos.y = 0;
|
// pos.y = 0;
|
||||||
while ((game->map.content)[incr.x])
|
// while ((game->map.content)[incr.x])
|
||||||
{
|
// {
|
||||||
incr.y = 0;
|
// incr.y = 0;
|
||||||
while ((game->map.content)[incr.x][incr.y])
|
// while ((game->map.content)[incr.x][incr.y])
|
||||||
{
|
// {
|
||||||
if ((game->map.content)[incr.x][incr.y] == '1' )
|
// if ((game->map.content)[incr.x][incr.y] == '1' )
|
||||||
draw_square(game, pos, 0x00999999, 0x00000000, cell, 0);
|
// draw_square(game, pos, 0x00999999, 0x00000000, cell, 0);
|
||||||
else
|
// else
|
||||||
draw_square(game, pos, 0x00555555, 0x00333333, cell, 0);
|
// draw_square(game, pos, 0x00555555, 0x00333333, cell, 0);
|
||||||
(incr.y)++;
|
// (incr.y)++;
|
||||||
pos.x += cell;
|
// pos.x += cell;
|
||||||
}
|
// }
|
||||||
(incr.x)++;
|
// (incr.x)++;
|
||||||
pos.x = 0;
|
// pos.x = 0;
|
||||||
pos.y += cell;
|
// pos.y += cell;
|
||||||
}
|
// }
|
||||||
pos.x = game->plr.pos.x - cell / 2;
|
// pos.x = game->plr.pos.x - cell / 2;
|
||||||
pos.y = game->plr.pos.y - cell / 2;
|
// pos.y = game->plr.pos.y - cell / 2;
|
||||||
draw_square(game, pos, 0x00999900, 0x00330033, cell, 1);
|
// draw_square(game, pos, 0x00999900, 0x00330033, cell, 1);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/*
|
|
||||||
static void draw_screen(t_game *game, t_rcast *rcast)
|
|
||||||
{
|
|
||||||
t_vec screen;
|
|
||||||
|
|
||||||
// draw screen size
|
|
||||||
screen.start.x = rcast->screen_size.start.x + game->plr.pos.x;
|
|
||||||
screen.start.y = rcast->screen_size.start.y + game->plr.pos.y;
|
|
||||||
rotate(&(game->plr), &(screen.start));
|
|
||||||
screen.end.x = rcast->screen_size.end.x + game->plr.pos.x;
|
|
||||||
screen.end.y = rcast->screen_size.end.y + game->plr.pos.y;
|
|
||||||
rotate(&(game->plr), &(screen.end));
|
|
||||||
draw_line(&game->map_img, &screen, 0x00FFFFFF);
|
|
||||||
// draw screen dist
|
|
||||||
screen.start.x = rcast->screen_dist.start.x + game->plr.pos.x;
|
|
||||||
screen.start.y = rcast->screen_dist.start.y + game->plr.pos.y;
|
|
||||||
screen.end.x = rcast->screen_dist.end.x + game->plr.pos.x;
|
|
||||||
screen.end.y = rcast->screen_dist.end.y + game->plr.pos.y;
|
|
||||||
rotate(&(game->plr), &(screen.end));
|
|
||||||
draw_line(&game->map_img, &screen, 0x00FFFFFF);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
static int pxl_out_limits(t_img *img, int x, int y)
|
static int pxl_out_limits(t_img *img, int x, int y)
|
||||||
@@ -129,14 +106,14 @@ void draw_line(t_img *img, t_vec *vec, int color)
|
|||||||
void draw(t_game *game)
|
void draw(t_game *game)
|
||||||
{
|
{
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
draw_map(game);
|
// draw_map(game);
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
raycast(game, &(game->rcast));
|
raycast(game, &(game->rcast));
|
||||||
|
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
// draw_screen(game, &(game->rcast));
|
// draw_screen(game, &(game->rcast));
|
||||||
mlx_put_image_to_window(game->mlx_ptr, game->map_win.ptr, game->map_img.ptr, 0, SCREEN_HEIGHT);
|
// mlx_put_image_to_window(game->mlx_ptr, game->map_win.ptr, game->map_img.ptr, 0, SCREEN_HEIGHT);
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
mlx_put_image_to_window(game->mlx_ptr, game->win.ptr, game->img.ptr, 0, 0);
|
mlx_put_image_to_window(game->mlx_ptr, game->win.ptr, game->img.ptr, 0, 0);
|
||||||
|
|||||||
@@ -42,13 +42,12 @@ static void draw_txt_column(t_game *game, t_wall *wall, t_img *txt_img)
|
|||||||
img_x = (wall->posx * txt_img->width) / game->rcast.cell;
|
img_x = (wall->posx * txt_img->width) / game->rcast.cell;
|
||||||
|
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
if (game->ray_activ)
|
// if (game->ray_activ)
|
||||||
{
|
// {
|
||||||
printf("img_x:%i ", img_x);
|
// printf("img_x:%i ", img_x);
|
||||||
draw_line(&game->img, &wall->vec, 0x00FF00FF);
|
// draw_line(&game->img, &wall->vec, 0x00FF00FF);
|
||||||
return ;
|
// return ;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
j = wall->limit;
|
j = wall->limit;
|
||||||
|
|||||||
@@ -1,33 +1,33 @@
|
|||||||
#include "cube3d.h"
|
#include "cube3d.h"
|
||||||
|
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
static void calcul_ray_end(t_rcast *rcast, t_vec *ray)
|
// static void calcul_ray_end(t_rcast *rcast, t_vec *ray)
|
||||||
{
|
// {
|
||||||
if (rcast->is_x)
|
// if (rcast->is_x)
|
||||||
{
|
// {
|
||||||
ray->end.x = rcast->cell_x * rcast->cell;
|
// ray->end.x = rcast->cell_x * rcast->cell;
|
||||||
if (rcast->ray_sign_x == 1)
|
// if (rcast->ray_sign_x == 1)
|
||||||
ray->end.x += rcast->cell;
|
// ray->end.x += rcast->cell;
|
||||||
if (rcast->slope_x)
|
// if (rcast->slope_x)
|
||||||
{
|
// {
|
||||||
rcast->ratio = (double)(ray->end.x - ray->start.x);
|
// rcast->ratio = (double)(ray->end.x - ray->start.x);
|
||||||
rcast->ratio /= (double)rcast->slope_x;
|
// rcast->ratio /= (double)rcast->slope_x;
|
||||||
ray->end.y = ray->start.y + (double)rcast->slope_y * rcast->ratio;
|
// ray->end.y = ray->start.y + (double)rcast->slope_y * rcast->ratio;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
ray->end.y = rcast->cell_y * rcast->cell;
|
// ray->end.y = rcast->cell_y * rcast->cell;
|
||||||
if (rcast->ray_sign_y == 1)
|
// if (rcast->ray_sign_y == 1)
|
||||||
ray->end.y += rcast->cell;
|
// ray->end.y += rcast->cell;
|
||||||
if (rcast->slope_y)
|
// if (rcast->slope_y)
|
||||||
{
|
// {
|
||||||
rcast->ratio = (double)(ray->end.y - ray->start.y);
|
// rcast->ratio = (double)(ray->end.y - ray->start.y);
|
||||||
rcast->ratio /= (double)rcast->slope_y;
|
// rcast->ratio /= (double)rcast->slope_y;
|
||||||
ray->end.x = ray->start.x + (double)rcast->slope_x * rcast->ratio;
|
// ray->end.x = ray->start.x + (double)rcast->slope_x * rcast->ratio;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
static void calcul_img_column(t_game *game, t_rcast *rcast, t_wall *wall)
|
static void calcul_img_column(t_game *game, t_rcast *rcast, t_wall *wall)
|
||||||
@@ -43,8 +43,8 @@ static void calcul_img_column(t_game *game, t_rcast *rcast, t_wall *wall)
|
|||||||
tmp += game->plr.pos.y;
|
tmp += game->plr.pos.y;
|
||||||
|
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
if (game->ray_activ)
|
// if (game->ray_activ)
|
||||||
printf("tmp:%i ", tmp);
|
// printf("tmp:%i ", tmp);
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
wall->posx = tmp % rcast->cell;
|
wall->posx = tmp % rcast->cell;
|
||||||
@@ -58,16 +58,16 @@ static void calcul_img_column(t_game *game, t_rcast *rcast, t_wall *wall)
|
|||||||
tmp += game->plr.pos.x;
|
tmp += game->plr.pos.x;
|
||||||
|
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
if (game->ray_activ)
|
// if (game->ray_activ)
|
||||||
printf("tmp:%i ", tmp);
|
// printf("tmp:%i ", tmp);
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
wall->posx = tmp % rcast->cell;
|
wall->posx = tmp % rcast->cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
if (game->ray_activ)
|
// if (game->ray_activ)
|
||||||
printf("wall->posx:%i ", wall->posx);
|
// printf("wall->posx:%i ", wall->posx);
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -119,23 +119,23 @@ void raycast(t_game *game, t_rcast *rcast)
|
|||||||
{
|
{
|
||||||
|
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
// rays
|
// // rays
|
||||||
game->ray_activ = 0;
|
// game->ray_activ = 0;
|
||||||
if (rcast->ray_nb == game->ray_highlight)
|
// if (rcast->ray_nb == game->ray_highlight)
|
||||||
{
|
// {
|
||||||
game->ray_activ = 1;
|
// game->ray_activ = 1;
|
||||||
game->ray = ray;
|
// game->ray = ray;
|
||||||
}
|
// }
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
ray_intersect_wall(game, rcast, &ray);
|
ray_intersect_wall(game, rcast, &ray);
|
||||||
|
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
calcul_ray_end(rcast, &ray);
|
// calcul_ray_end(rcast, &ray);
|
||||||
if (game->ray_activ)
|
// if (game->ray_activ)
|
||||||
draw_line(&game->map_img, &ray, 0x00FF00FF);
|
// draw_line(&game->map_img, &ray, 0x00FF00FF);
|
||||||
else if (rcast->ray_nb % 10 == 0)
|
// else if (rcast->ray_nb % 10 == 0)
|
||||||
draw_line(&game->map_img, &ray, 0x00FFFFFF);
|
// draw_line(&game->map_img, &ray, 0x00FFFFFF);
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
calcul_wall(rcast);
|
calcul_wall(rcast);
|
||||||
@@ -145,7 +145,7 @@ void raycast(t_game *game, t_rcast *rcast)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
printf("\n\n");
|
// printf("\n\n");
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,24 +32,23 @@ int hook_action(t_game *game)
|
|||||||
plr_turn_right(&(game->plr));
|
plr_turn_right(&(game->plr));
|
||||||
|
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
// temp display one ray with infos
|
// // ray
|
||||||
if (!ft_arrint(game->k_hook, 65364, MAX_NB_KEY))
|
// if (!ft_arrint(game->k_hook, 65364, MAX_NB_KEY))
|
||||||
{
|
// {
|
||||||
if (game->ray_highlight <= SCREEN_WIDTH)
|
// if (game->ray_highlight <= SCREEN_WIDTH)
|
||||||
game->ray_highlight++;
|
// game->ray_highlight++;
|
||||||
else
|
// else
|
||||||
game->ray_highlight = -1;
|
// game->ray_highlight = -1;
|
||||||
is_action = 1;
|
// is_action = 1;
|
||||||
}
|
// }
|
||||||
if (!ft_arrint(game->k_hook, 65362, MAX_NB_KEY))
|
// if (!ft_arrint(game->k_hook, 65362, MAX_NB_KEY))
|
||||||
{
|
// {
|
||||||
if (game->ray_highlight >= 0)
|
// if (game->ray_highlight >= 0)
|
||||||
game->ray_highlight--;
|
// game->ray_highlight--;
|
||||||
else
|
// else
|
||||||
game->ray_highlight = SCREEN_WIDTH;
|
// game->ray_highlight = SCREEN_WIDTH;
|
||||||
is_action = 1;
|
// is_action = 1;
|
||||||
}
|
// }
|
||||||
// temp end
|
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
if (is_action)
|
if (is_action)
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ static void init_plr(t_plr *plr, t_map *map)
|
|||||||
plr->cosj = 0;
|
plr->cosj = 0;
|
||||||
plr->sini = 0;
|
plr->sini = 0;
|
||||||
plr->sinj = 0;
|
plr->sinj = 0;
|
||||||
|
if (map->plr_dir == 'E')
|
||||||
|
plr_turn(plr, 90);
|
||||||
|
if (map->plr_dir == 'S')
|
||||||
|
plr_turn(plr, 180);
|
||||||
|
if (map->plr_dir == 'W')
|
||||||
|
plr_turn(plr, -90);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_game(t_game *game)
|
void init_game(t_game *game)
|
||||||
@@ -53,13 +59,13 @@ void init_game(t_game *game)
|
|||||||
mb_add(game->mlx_ptr);
|
mb_add(game->mlx_ptr);
|
||||||
|
|
||||||
// tmp draw map
|
// tmp draw map
|
||||||
game->map_win.size_x = game->map.size_x * CELL;
|
// game->map_win.size_x = game->map.size_x * CELL;
|
||||||
game->map_win.size_y = game->map.size_y * CELL + SCREEN_HEIGHT;
|
// game->map_win.size_y = game->map.size_y * CELL + SCREEN_HEIGHT;
|
||||||
game->map_win.ptr = mlx_new_window(game->mlx_ptr, game->map_win.size_x, game->map_win.size_y, "map");
|
// game->map_win.ptr = mlx_new_window(game->mlx_ptr, game->map_win.size_x, game->map_win.size_y, "map");
|
||||||
init_img(&(game->map_img), game->mlx_ptr, &(game->map_win));
|
// init_img(&(game->map_img), game->mlx_ptr, &(game->map_win));
|
||||||
// ray
|
// // ray
|
||||||
game->ray_highlight = -1;
|
// game->ray_highlight = -1;
|
||||||
game->ray_activ = 0;
|
// game->ray_activ = 0;
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
// create window
|
// create window
|
||||||
|
|||||||
@@ -6,17 +6,18 @@
|
|||||||
/* By: pblagoje <pblagoje@student.42.fr> +#+ +:+ +#+ */
|
/* By: pblagoje <pblagoje@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/04/18 12:37:48 by pblagoje #+# #+# */
|
/* Created: 2022/04/18 12:37:48 by pblagoje #+# #+# */
|
||||||
/* Updated: 2022/04/30 11:56:09 by simplonco ### ########.fr */
|
/* Updated: 2022/05/04 00:51:54 by simplonco ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "cube3d.h"
|
#include "cube3d.h"
|
||||||
|
|
||||||
int set_player(t_map *map, int y, int x)
|
static int set_player(t_map *map, int y, int x, char dir)
|
||||||
{
|
{
|
||||||
map->plr_x = x;
|
map->plr_x = x;
|
||||||
map->plr_y = y;
|
map->plr_y = y;
|
||||||
map->content[y][x] = '0';
|
map->content[y][x] = '0';
|
||||||
|
map->plr_dir = dir;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ int check_content(t_map *map)
|
|||||||
else if (!ft_strchr(" 01SNWE", map->content[y][x]))
|
else if (!ft_strchr(" 01SNWE", map->content[y][x]))
|
||||||
return (EXIT_FAILURE);
|
return (EXIT_FAILURE);
|
||||||
else if (ft_strchr("SNWE", map->content[y][x]) \
|
else if (ft_strchr("SNWE", map->content[y][x]) \
|
||||||
&& set_player(map, y, x))
|
&& set_player(map, y, x, map->content[y][x]))
|
||||||
count++;
|
count++;
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,14 +40,14 @@ void rotate_double(t_plr *plr, t_d_coord *coord)
|
|||||||
coord->y = tmp.y + plr->exact.y;
|
coord->y = tmp.y + plr->exact.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void plr_turn_left(t_plr *plr)
|
void plr_turn(t_plr *plr, int deg)
|
||||||
{
|
{
|
||||||
double radi;
|
double radi;
|
||||||
double radj;
|
double radj;
|
||||||
|
|
||||||
if (plr->rot == -180)
|
if (plr->rot == -180)
|
||||||
(plr->rot) *= -1;
|
(plr->rot) *= -1;
|
||||||
plr->rot -= plr->deg;
|
plr->rot += deg;
|
||||||
// calculate trigo for rotations
|
// calculate trigo for rotations
|
||||||
radi = plr->rot * M_PI / 180;
|
radi = plr->rot * M_PI / 180;
|
||||||
radj = radi + (M_PI / 2);
|
radj = radi + (M_PI / 2);
|
||||||
@@ -57,19 +57,12 @@ void plr_turn_left(t_plr *plr)
|
|||||||
plr->sinj = sin(radj);
|
plr->sinj = sin(radj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void plr_turn_left(t_plr *plr)
|
||||||
|
{
|
||||||
|
plr_turn(plr, -plr->deg);
|
||||||
|
}
|
||||||
|
|
||||||
void plr_turn_right(t_plr *plr)
|
void plr_turn_right(t_plr *plr)
|
||||||
{
|
{
|
||||||
double radi;
|
plr_turn(plr, plr->deg);
|
||||||
double radj;
|
|
||||||
|
|
||||||
if (plr->rot == 180)
|
|
||||||
(plr->rot) *= -1;
|
|
||||||
plr->rot += plr->deg;
|
|
||||||
// calculate trigo for rotations
|
|
||||||
radi = plr->rot * M_PI / 180;
|
|
||||||
radj = radi + (M_PI / 2);
|
|
||||||
plr->cosi = cos(radi);
|
|
||||||
plr->sini = sin(radi);
|
|
||||||
plr->cosj = cos(radj);
|
|
||||||
plr->sinj = sin(radj);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user