Added memorybook to parsing and cleaned most of the files
This commit is contained in:
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cube3d.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:42:00 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:43:02 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
void destroy_mlx(void *param)
|
||||
@@ -28,7 +40,7 @@ int shut_down(void)
|
||||
return (0);
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
t_game *game;
|
||||
|
||||
@@ -37,23 +49,15 @@ int main(int ac, char **av)
|
||||
return (EXIT_FAILURE);
|
||||
game = init_struct();
|
||||
mb_init(destroy_mlx, game);
|
||||
|
||||
if (init_parsing(game, av[1]) && write(2, "The .cub file is invalid.\n", 26))
|
||||
if (init_parsing(game, av[1]))
|
||||
return (EXIT_FAILURE);
|
||||
|
||||
if (check_map(&(game->map)) && write(2, "The map is invalid.\n", 20))
|
||||
if (check_map(&(game->map)))
|
||||
return (EXIT_FAILURE);
|
||||
init_game(game);
|
||||
|
||||
// draw game a first time before it start
|
||||
draw(game);
|
||||
// receive a keypress event
|
||||
mlx_hook(game->win.ptr, 2, 1L << 0, keypress, game);
|
||||
// receive a keyprelease event
|
||||
mlx_hook(game->win.ptr, 3, 1L << 1, keyrelease, game);
|
||||
// receive event when clicking the red button to close the window
|
||||
mlx_hook(game->win.ptr, 17, 1L << 17, shut_down, NULL);
|
||||
// infinite loop that waits for events to occurs
|
||||
mlx_loop_hook(game->mlx_ptr, hook_action, game);
|
||||
mlx_loop(game->mlx_ptr);
|
||||
return (0);
|
||||
|
||||
@@ -1,65 +1,16 @@
|
||||
#include "cube3d.h"
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* draw.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:55:29 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:55:31 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
// tmp draw map
|
||||
// static void draw_square(t_game *game, t_coord pos, int border, int fill, int size, int rotation)
|
||||
// {
|
||||
// int i;
|
||||
// int j;
|
||||
// t_coord new;
|
||||
//
|
||||
// i = 0;
|
||||
// while (i < size)
|
||||
// {
|
||||
// j = 0;
|
||||
// while (j < size)
|
||||
// {
|
||||
// new.x = pos.x + j;
|
||||
// new.y = pos.y + i;
|
||||
// if (rotation)
|
||||
// rotate(&(game->plr), &(new));
|
||||
// if (!i || i == size - 1)
|
||||
// draw_pixel(&game->map_img, new.x, new.y, border);
|
||||
// else if (!j || j == size - 1)
|
||||
// draw_pixel(&game->map_img, new.x, new.y, border);
|
||||
// else
|
||||
// draw_pixel(&game->map_img, new.x, new.y, fill);
|
||||
// j++;
|
||||
// }
|
||||
// i++;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// static void draw_map(t_game *game)
|
||||
// {
|
||||
// t_coord incr;
|
||||
// t_coord pos;
|
||||
// int cell;
|
||||
//
|
||||
// cell = game->map.cell;
|
||||
// incr.x = 0;
|
||||
// pos.x = 0;
|
||||
// pos.y = 0;
|
||||
// while ((game->map.content)[incr.x])
|
||||
// {
|
||||
// incr.y = 0;
|
||||
// while ((game->map.content)[incr.x][incr.y])
|
||||
// {
|
||||
// if ((game->map.content)[incr.x][incr.y] == '1' )
|
||||
// draw_square(game, pos, 0x00999999, 0x00000000, cell, 0);
|
||||
// else
|
||||
// draw_square(game, pos, 0x00555555, 0x00333333, cell, 0);
|
||||
// (incr.y)++;
|
||||
// pos.x += cell;
|
||||
// }
|
||||
// (incr.x)++;
|
||||
// pos.x = 0;
|
||||
// pos.y += cell;
|
||||
// }
|
||||
// pos.x = game->plr.pos.x - cell / 2;
|
||||
// pos.y = game->plr.pos.y - cell / 2;
|
||||
// draw_square(game, pos, 0x00999900, 0x00330033, cell, 1);
|
||||
// }
|
||||
// tmp end
|
||||
#include "cube3d.h"
|
||||
|
||||
static int pxl_out_limits(t_img *img, int x, int y)
|
||||
{
|
||||
@@ -80,7 +31,7 @@ void draw_pixel(t_img *img, int x, int y, int color)
|
||||
if (pxl_out_limits(img, x, y))
|
||||
return ;
|
||||
position = y * img->szl + x * (img->bpp / 8);
|
||||
*(unsigned int*)(img->data + position) = color;
|
||||
*(unsigned int *)(img->data + position) = color;
|
||||
}
|
||||
|
||||
void draw_line(t_img *img, t_vec *vec, int color)
|
||||
@@ -105,16 +56,6 @@ void draw_line(t_img *img, t_vec *vec, int color)
|
||||
|
||||
void draw(t_game *game)
|
||||
{
|
||||
// tmp draw map
|
||||
// draw_map(game);
|
||||
// tmp end
|
||||
|
||||
raycast(game, &(game->rcast));
|
||||
|
||||
// tmp draw map
|
||||
// draw_screen(game, &(game->rcast));
|
||||
// mlx_put_image_to_window(game->mlx_ptr, game->map_win.ptr, game->map_img.ptr, 0, SCREEN_HEIGHT);
|
||||
// tmp end
|
||||
|
||||
mlx_put_image_to_window(game->mlx_ptr, game->win.ptr, game->img.ptr, 0, 0);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* draw_column.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:51:59 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:52:01 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
static void draw_floor_ceiling(t_game *game, t_rcast *rcast, t_txt *txt)
|
||||
@@ -40,16 +52,6 @@ static void draw_txt_column(t_game *game, t_wall *wall, t_img *txt_img)
|
||||
int j;
|
||||
|
||||
img_x = (wall->posx * txt_img->width) / game->rcast.cell;
|
||||
|
||||
// tmp draw map
|
||||
// if (game->ray_activ)
|
||||
// {
|
||||
// printf("img_x:%i ", img_x);
|
||||
// draw_line(&game->img, &wall->vec, 0x00FF00FF);
|
||||
// return ;
|
||||
// }
|
||||
// tmp end
|
||||
|
||||
j = wall->limit;
|
||||
i = 0;
|
||||
while (j < wall->height - wall->limit)
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ray_intersect.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:52:25 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:52:27 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
static void init_ray_params(t_rcast *rcast, t_vec *ray)
|
||||
|
||||
@@ -1,34 +1,16 @@
|
||||
#include "cube3d.h"
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* raycast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:54:22 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:54:23 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
// tmp draw map
|
||||
// static void calcul_ray_end(t_rcast *rcast, t_vec *ray)
|
||||
// {
|
||||
// if (rcast->is_x)
|
||||
// {
|
||||
// ray->end.x = rcast->cell_x * rcast->cell;
|
||||
// if (rcast->ray_sign_x == 1)
|
||||
// ray->end.x += rcast->cell;
|
||||
// if (rcast->slope_x)
|
||||
// {
|
||||
// rcast->ratio = (double)(ray->end.x - ray->start.x);
|
||||
// rcast->ratio /= (double)rcast->slope_x;
|
||||
// ray->end.y = ray->start.y + (double)rcast->slope_y * rcast->ratio;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ray->end.y = rcast->cell_y * rcast->cell;
|
||||
// if (rcast->ray_sign_y == 1)
|
||||
// ray->end.y += rcast->cell;
|
||||
// if (rcast->slope_y)
|
||||
// {
|
||||
// rcast->ratio = (double)(ray->end.y - ray->start.y);
|
||||
// rcast->ratio /= (double)rcast->slope_y;
|
||||
// ray->end.x = ray->start.x + (double)rcast->slope_x * rcast->ratio;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// tmp end
|
||||
#include "cube3d.h"
|
||||
|
||||
static void calcul_img_column(t_game *game, t_rcast *rcast, t_wall *wall)
|
||||
{
|
||||
@@ -37,42 +19,22 @@ static void calcul_img_column(t_game *game, t_rcast *rcast, t_wall *wall)
|
||||
if (rcast->is_x == 1)
|
||||
{
|
||||
tmp = wall->delta;
|
||||
// tmp += rcast->slope_y;
|
||||
tmp *= -rcast->ray_sign_y;
|
||||
tmp /= ft_abs(rcast->slope_x);
|
||||
tmp += game->plr.pos.y;
|
||||
|
||||
// tmp draw map
|
||||
// if (game->ray_activ)
|
||||
// printf("tmp:%i ", tmp);
|
||||
// tmp end
|
||||
|
||||
wall->posx = tmp % rcast->cell;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = wall->delta;
|
||||
// tmp += rcast->slope_x;
|
||||
tmp *= -rcast->ray_sign_x;
|
||||
tmp /= ft_abs(rcast->slope_y);
|
||||
tmp += game->plr.pos.x;
|
||||
|
||||
// tmp draw map
|
||||
// if (game->ray_activ)
|
||||
// printf("tmp:%i ", tmp);
|
||||
// tmp end
|
||||
|
||||
wall->posx = tmp % rcast->cell;
|
||||
}
|
||||
|
||||
// tmp draw map
|
||||
// if (game->ray_activ)
|
||||
// printf("wall->posx:%i ", wall->posx);
|
||||
// tmp end
|
||||
|
||||
}
|
||||
|
||||
static void fill_wall_vector(t_rcast *rcast, t_wall *wall)
|
||||
static void fill_wall_vector(t_rcast *rcast, t_wall *wall)
|
||||
{
|
||||
int height;
|
||||
|
||||
@@ -117,35 +79,10 @@ void raycast(t_game *game, t_rcast *rcast)
|
||||
rcast->ray_nb = 0;
|
||||
while (rcast->ray_nb <= rcast->screen_width)
|
||||
{
|
||||
|
||||
// tmp draw map
|
||||
// // rays
|
||||
// game->ray_activ = 0;
|
||||
// if (rcast->ray_nb == game->ray_highlight)
|
||||
// {
|
||||
// game->ray_activ = 1;
|
||||
// game->ray = ray;
|
||||
// }
|
||||
// tmp end
|
||||
|
||||
ray_intersect_wall(game, rcast, &ray);
|
||||
|
||||
// tmp draw map
|
||||
// calcul_ray_end(rcast, &ray);
|
||||
// if (game->ray_activ)
|
||||
// draw_line(&game->map_img, &ray, 0x00FF00FF);
|
||||
// else if (rcast->ray_nb % 10 == 0)
|
||||
// draw_line(&game->map_img, &ray, 0x00FFFFFF);
|
||||
// tmp end
|
||||
|
||||
calcul_wall(rcast);
|
||||
calcul_img_column(game, rcast, &rcast->wall);
|
||||
draw_column(game, rcast, &rcast->wall, &game->txt);
|
||||
(rcast->ray_nb)++;
|
||||
}
|
||||
|
||||
// tmp draw map
|
||||
// printf("\n\n");
|
||||
// tmp end
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* key_action_1.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:48:28 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:49:27 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
int is_esc(int *k_hook, int *is_action)
|
||||
@@ -5,9 +17,9 @@ int is_esc(int *k_hook, int *is_action)
|
||||
if (!ft_arrint(k_hook, KEY_ESC, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int is_go_left(int *k_hook, int *is_action)
|
||||
@@ -15,14 +27,14 @@ int is_go_left(int *k_hook, int *is_action)
|
||||
if (!ft_arrint(k_hook, KEY_A, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
if (!ft_arrint(k_hook, KEY_Q, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int is_go_right(int *k_hook, int *is_action)
|
||||
@@ -30,9 +42,9 @@ int is_go_right(int *k_hook, int *is_action)
|
||||
if (!ft_arrint(k_hook, KEY_D, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int is_go_forward(int *k_hook, int *is_action)
|
||||
@@ -40,14 +52,14 @@ int is_go_forward(int *k_hook, int *is_action)
|
||||
if (!ft_arrint(k_hook, KEY_W, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
if (!ft_arrint(k_hook, KEY_Z, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int is_go_backward(int *k_hook, int *is_action)
|
||||
@@ -55,7 +67,7 @@ int is_go_backward(int *k_hook, int *is_action)
|
||||
if (!ft_arrint(k_hook, KEY_S, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* key_action_2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:48:54 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:48:56 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
int is_turn_left(int *k_hook, int *is_action)
|
||||
@@ -5,9 +17,9 @@ int is_turn_left(int *k_hook, int *is_action)
|
||||
if (!ft_arrint(k_hook, ARROW_LEFT, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int is_turn_right(int *k_hook, int *is_action)
|
||||
@@ -15,7 +27,7 @@ int is_turn_right(int *k_hook, int *is_action)
|
||||
if (!ft_arrint(k_hook, ARROW_RIGHT, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* keyhook.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:45:52 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:47:13 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
// temp, to map all the keys on linux and mac
|
||||
static int print_keycode(int keycode, t_plr *plr)
|
||||
{
|
||||
ft_putnbr_fd(keycode, 1);
|
||||
ft_putchar_fd(' ', 1);
|
||||
ft_putnbr_fd(plr->rot, 1);
|
||||
ft_putchar_fd('\n', 1);
|
||||
return(0);
|
||||
}
|
||||
// temp end
|
||||
static int print_keycode(int keycode, t_plr *plr)
|
||||
{
|
||||
ft_putnbr_fd(keycode, 1);
|
||||
ft_putchar_fd(' ', 1);
|
||||
ft_putnbr_fd(plr->rot, 1);
|
||||
ft_putchar_fd('\n', 1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int hook_action(t_game *game)
|
||||
{
|
||||
@@ -30,40 +40,16 @@ int hook_action(t_game *game)
|
||||
plr_turn_left(&(game->plr));
|
||||
if (is_turn_right(game->k_hook, &is_action))
|
||||
plr_turn_right(&(game->plr));
|
||||
|
||||
// tmp draw map
|
||||
// // ray
|
||||
// if (!ft_arrint(game->k_hook, 65364, MAX_NB_KEY))
|
||||
// {
|
||||
// if (game->ray_highlight <= SCREEN_WIDTH)
|
||||
// game->ray_highlight++;
|
||||
// else
|
||||
// game->ray_highlight = -1;
|
||||
// is_action = 1;
|
||||
// }
|
||||
// if (!ft_arrint(game->k_hook, 65362, MAX_NB_KEY))
|
||||
// {
|
||||
// if (game->ray_highlight >= 0)
|
||||
// game->ray_highlight--;
|
||||
// else
|
||||
// game->ray_highlight = SCREEN_WIDTH;
|
||||
// is_action = 1;
|
||||
// }
|
||||
// tmp end
|
||||
|
||||
if (is_action)
|
||||
draw(game);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int keypress(int keycode, t_game *game)
|
||||
int keypress(int keycode, t_game *game)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
// temp
|
||||
print_keycode(keycode, &game->plr);
|
||||
// temp end
|
||||
|
||||
print_keycode(keycode, &game->plr);
|
||||
i = 0;
|
||||
while (i < MAX_NB_KEY && game->k_hook[i] != 0 && game->k_hook[i] != keycode)
|
||||
i++;
|
||||
@@ -71,11 +57,10 @@ int keypress(int keycode, t_game *game)
|
||||
game->k_hook[i] = 0;
|
||||
else if (i < MAX_NB_KEY)
|
||||
game->k_hook[i] = keycode;
|
||||
// hook_action(game);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int keyrelease(int keycode, t_game *game)
|
||||
int keyrelease(int keycode, t_game *game)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* init_game.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:58:13 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:59:14 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
static void init_img(t_img *img, void *mlx_ptr, t_win *win)
|
||||
@@ -16,12 +28,10 @@ static void init_raycast(t_rcast *rcast)
|
||||
rcast->screen_dist = dist;
|
||||
rcast->screen_width = SCREEN_WIDTH;
|
||||
rcast->screen_height = SCREEN_HEIGHT;
|
||||
// screen size
|
||||
rcast->screen_size.start.x = -SCREEN_WIDTH / 2;
|
||||
rcast->screen_size.start.y = -dist;
|
||||
rcast->screen_size.end.x = SCREEN_WIDTH / 2;
|
||||
rcast->screen_size.end.y = -dist;
|
||||
// first ray
|
||||
rcast->ray.start.x = 0;
|
||||
rcast->ray.start.y = 0;
|
||||
rcast->ray.end.x = -SCREEN_WIDTH / 2;
|
||||
@@ -30,12 +40,10 @@ static void init_raycast(t_rcast *rcast)
|
||||
|
||||
static void init_plr(t_plr *plr, t_map *map)
|
||||
{
|
||||
// player first position
|
||||
plr->exact.x = map->plr_x * CELL + CELL / 2;
|
||||
plr->exact.y = map->plr_y * CELL + CELL / 2;
|
||||
plr->pos.x = plr->exact.x;
|
||||
plr->pos.y = plr->exact.y;
|
||||
// rotation
|
||||
plr->deg = PLR_ROT;
|
||||
plr->rot = 0;
|
||||
plr->cosi = 0;
|
||||
@@ -52,33 +60,16 @@ static void init_plr(t_plr *plr, t_map *map)
|
||||
|
||||
void init_game(t_game *game)
|
||||
{
|
||||
// plr
|
||||
init_plr(&(game->plr), &(game->map));
|
||||
// init connexion to server
|
||||
game->mlx_ptr = mlx_init();
|
||||
mb_add(game->mlx_ptr);
|
||||
|
||||
// tmp draw map
|
||||
// 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.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));
|
||||
// // ray
|
||||
// game->ray_highlight = -1;
|
||||
// game->ray_activ = 0;
|
||||
// tmp end
|
||||
|
||||
// create window
|
||||
game->win.size_x = SCREEN_WIDTH;
|
||||
game->win.size_y = SCREEN_HEIGHT;
|
||||
game->win.ptr = mlx_new_window(game->mlx_ptr, game->win.size_x, game->win.size_y, "cub3d");
|
||||
// create img
|
||||
game->win.ptr = mlx_new_window(game->mlx_ptr, game->win.size_x, \
|
||||
game->win.size_y, "cub3d");
|
||||
init_img(&(game->img), game->mlx_ptr, &game->win);
|
||||
// create textures img
|
||||
init_txtr(&game->txt, game->mlx_ptr);
|
||||
// k(ey)_hook is the array containing the values of key press events
|
||||
ft_bzero(&game->k_hook, sizeof(game->k_hook));
|
||||
// raycasting
|
||||
init_raycast(&(game->rcast));
|
||||
game->rcast.cell = game->map.cell;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* init_struct.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:57:22 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:57:28 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
static void init_null_mlx_ptr(t_game *game)
|
||||
@@ -35,11 +47,8 @@ t_game *init_struct(void)
|
||||
t_game *game;
|
||||
|
||||
game = mb_alloc(sizeof(t_game));
|
||||
// map
|
||||
init_map(&(game->map));
|
||||
// init textures and floor/ceiling colors
|
||||
init_txt_null(&(game->txt));
|
||||
// put all mlx allocated pointer to null
|
||||
init_null_mlx_ptr(game);
|
||||
return (game);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* init_textures.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:57:11 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:57:13 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
static void init_txtr_img(t_img *img, void *mlx_ptr, char *path)
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* memorybook.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:56:30 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:58:58 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
void mb_set_params_exit(void (*f)(void *), void *param);
|
||||
void mb_exec_exit_func();
|
||||
void mb_exec_exit_func(void);
|
||||
t_list **mb_get_lst(void);
|
||||
int mb_comp_addr(void *to_find, void *to_compare);
|
||||
|
||||
|
||||
@@ -1,19 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* memorybook_2d.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:55:48 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:55:51 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
void mb_add_2d(void **addr, int nb)
|
||||
{
|
||||
while (nb)
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < nb)
|
||||
{
|
||||
mb_add(addr[nb]);
|
||||
nb--;
|
||||
mb_add(addr[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void mb_free_2d(void **addr, int nb)
|
||||
{
|
||||
while (nb)
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < nb)
|
||||
{
|
||||
mb_free(addr[nb]);
|
||||
nb--;
|
||||
mb_free(addr[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* memorybook_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:56:23 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:56:25 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
/* private struct definition :
|
||||
|
||||
44
srcs/parsing/check_map_borders.c
Normal file
44
srcs/parsing/check_map_borders.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <pblagoje@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/18 12:37:48 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:05:47 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
int check_borders(t_map *map)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
y = 0;
|
||||
while (map->content[y] != NULL)
|
||||
{
|
||||
x = 0;
|
||||
while (map->content[y][x] != '\0' && map->content[y][x] != '\n')
|
||||
{
|
||||
if (y == 0 || y == map->size_y - 1)
|
||||
if (map->content[y][x] != '1' && map->content[y][x] != ' ')
|
||||
mb_exit("Error\nInvalid map borders.\n", EXIT_FAILURE);
|
||||
if (x == 0 || x == map->size_x - 1)
|
||||
if (map->content[y][x] != '1' && map->content[y][x] != ' ')
|
||||
mb_exit("Error\nInvalid map borders.\n", EXIT_FAILURE);
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int check_map(t_map *map)
|
||||
{
|
||||
if (check_borders(map) || check_content(map))
|
||||
mb_exit("Error\nInvalid map content.\n", EXIT_FAILURE);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_map.c :+: :+: :+: */
|
||||
/* check_map_content.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <pblagoje@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/18 12:37:48 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 00:51:54 by simplonco ### ########.fr */
|
||||
/* Created: 2022/05/04 13:04:44 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:05:34 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -73,9 +73,9 @@ int check_content(t_map *map)
|
||||
while (map->content[y][x] != '\0' && map->content[y][x] != '\n')
|
||||
{
|
||||
if (map->content[y][x] == ' ' && check_spaces(map, y, x))
|
||||
return (EXIT_FAILURE);
|
||||
mb_exit("Error\nInvalid space positions.\n", EXIT_FAILURE);
|
||||
else if (!ft_strchr(" 01SNWE", map->content[y][x]))
|
||||
return (EXIT_FAILURE);
|
||||
mb_exit("Error\nInvalid map characters.\n", EXIT_FAILURE);
|
||||
else if (ft_strchr("SNWE", map->content[y][x]) \
|
||||
&& set_player(map, y, x, map->content[y][x]))
|
||||
count++;
|
||||
@@ -84,40 +84,6 @@ int check_content(t_map *map)
|
||||
y++;
|
||||
}
|
||||
if (count != 1)
|
||||
return (EXIT_FAILURE);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int check_borders(t_map *map)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
y = 0;
|
||||
while (map->content[y] != NULL)
|
||||
{
|
||||
x = 0;
|
||||
while (map->content[y][x] != '\0' && map->content[y][x] != '\n')
|
||||
{
|
||||
if (y == 0 || y == map->size_y - 1)
|
||||
if (map->content[y][x] != '1' && map->content[y][x] != ' ')
|
||||
return (EXIT_FAILURE);
|
||||
if (x == 0 || x == map->size_x - 1)
|
||||
if (map->content[y][x] != '1' && map->content[y][x] != ' ')
|
||||
return (EXIT_FAILURE);
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int check_map(t_map *map)
|
||||
{
|
||||
if (check_borders(map) || check_content(map))
|
||||
{
|
||||
ft_putstr_fd("Error\nThe map characters are invalid.\n", 2);
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
mb_exit("Error\nToo many player starting positions.\n", EXIT_FAILURE);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: pblagoje <pblagoje@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/16 20:54:37 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/02 15:45:01 by simplonco ### ########.fr */
|
||||
/* Updated: 2022/05/04 13:01:16 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,21 +17,25 @@ int set_path(t_txt *txt, char *path, char identifier)
|
||||
if (identifier == 'N' && txt->txt_north == NULL)
|
||||
{
|
||||
txt->txt_north = ft_strdup(path);
|
||||
mb_add(txt->txt_north);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
else if (identifier == 'S' && txt->txt_south == NULL)
|
||||
{
|
||||
txt->txt_south = ft_strdup(path);
|
||||
mb_add(txt->txt_south);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
else if (identifier == 'W' && txt->txt_west == NULL)
|
||||
{
|
||||
txt->txt_west = ft_strdup(path);
|
||||
mb_add(txt->txt_west);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
else if (identifier == 'E' && txt->txt_east == NULL)
|
||||
{
|
||||
txt->txt_east = ft_strdup(path);
|
||||
mb_add(txt->txt_east);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
return (EXIT_FAILURE);
|
||||
@@ -45,21 +49,21 @@ static int check_path(t_txt *txt, char *element, char identifier)
|
||||
while (element && *element && ft_strchr(" \t\r", *element))
|
||||
element++;
|
||||
path = ft_substr(element, 0, ft_strlen(element));
|
||||
mb_add(path);
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1 || check_extension(path, ".xpm"))
|
||||
{
|
||||
ft_putstr_fd("Error\nInvalid texture file.\n", 2);
|
||||
free(path);
|
||||
mb_free(path);
|
||||
close(fd);
|
||||
return (EXIT_FAILURE);
|
||||
mb_exit("Error\nInvalid texture file.\n", EXIT_FAILURE);
|
||||
}
|
||||
if (set_path(txt, path, identifier) == EXIT_FAILURE)
|
||||
{
|
||||
free(path);
|
||||
mb_free(path);
|
||||
close(fd);
|
||||
return (EXIT_FAILURE);
|
||||
mb_exit("Error\nCouldn't save texture paths.\n", EXIT_FAILURE);
|
||||
}
|
||||
free(path);
|
||||
mb_free(path);
|
||||
close(fd);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
@@ -81,6 +85,7 @@ static int check_element(t_game *game, char *element)
|
||||
if (ft_strnstr("F C ", identifier, 5) && \
|
||||
!check_rgb(&(game->txt), element, identifier[0]))
|
||||
return (EXIT_SUCCESS);
|
||||
mb_exit("Error\nInvalid textures and/or RGB elements.\n", EXIT_FAILURE);
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -98,15 +103,16 @@ int check_elements(t_game *game, char *file)
|
||||
while (count < TOTAL_ELEMENTS)
|
||||
{
|
||||
get_next_line(fd, &line);
|
||||
mb_add(line);
|
||||
if (line && *line != '\n' && !check_element(game, line))
|
||||
count++;
|
||||
else if (!line || (*line != '\n' && *line != '\0'))
|
||||
{
|
||||
free(line);
|
||||
mb_free(line);
|
||||
close(fd);
|
||||
return (-1);
|
||||
}
|
||||
free(line);
|
||||
mb_free(line);
|
||||
line = NULL;
|
||||
}
|
||||
return (fd);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: pblagoje <pblagoje@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/15 16:11:24 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/01 22:53:25 by simplonco ### ########.fr */
|
||||
/* Updated: 2022/05/04 12:58:13 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -51,7 +51,7 @@ static void set_rgb(int *plan, char **rgb)
|
||||
*plan = 0 << 24 | r << 16 | g << 8 | b;
|
||||
}
|
||||
|
||||
void ft_free_2d(char **str)
|
||||
/*void ft_free_2d(char **str)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -62,14 +62,14 @@ void ft_free_2d(char **str)
|
||||
i++;
|
||||
}
|
||||
free(str);
|
||||
}
|
||||
}*/
|
||||
|
||||
int check_rgb(t_txt *txt, char *elem, char identifier)
|
||||
{
|
||||
char **rgb;
|
||||
|
||||
rgb = ft_split(elem, ',');
|
||||
mb_add_2d((void**)rgb, ft_strlen_2d(rgb));
|
||||
mb_add_2d((void **)rgb, ft_strlen_2d(rgb));
|
||||
if (!rgb || ft_strlen_2d(rgb) != 3 || elem[ft_strlen(elem) - 1] == ',')
|
||||
mb_exit("Error\nInvalid RGB code.\n", EXIT_FAILURE);
|
||||
if ((identifier != 'F' && identifier != 'C') || check_colors(rgb))
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: pblagoje <pblagoje@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/15 16:03:50 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/04/23 18:57:37 by pblagoje ### ########.fr */
|
||||
/* Updated: 2022/05/04 13:14:21 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,11 +17,12 @@ int size_map(t_map *map, int fd)
|
||||
char *line;
|
||||
|
||||
get_next_line(fd, &line);
|
||||
mb_add(line);
|
||||
while (line)
|
||||
{
|
||||
if ((*line == '\n' || *line == '\0') && map->size_x)
|
||||
{
|
||||
free(line);
|
||||
mb_free(line);
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
else if (*line != '\n' && (int)ft_strlen(line) > map->size_x)
|
||||
@@ -32,9 +33,10 @@ int size_map(t_map *map, int fd)
|
||||
}
|
||||
if (*line != '\n' && *line != '\0')
|
||||
map->size_y++;
|
||||
free(line);
|
||||
mb_free(line);
|
||||
line = NULL;
|
||||
get_next_line(fd, &line);
|
||||
mb_add(line);
|
||||
}
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
@@ -50,8 +52,8 @@ int find_map(t_map *map, char *file)
|
||||
return (-1);
|
||||
while (count < TOTAL_ELEMENTS + 1)
|
||||
{
|
||||
free(map->tmp_str);
|
||||
get_next_line(fd, &map->tmp_str);
|
||||
mb_add(map->tmp_str);
|
||||
if (!map->tmp_str)
|
||||
{
|
||||
close(fd);
|
||||
@@ -88,22 +90,25 @@ int fill_map(t_map *map, int fd)
|
||||
map->content = (char **)mb_alloc((map->size_y + 1) * sizeof(char *));
|
||||
if (!map->content)
|
||||
{
|
||||
free(map->tmp_str);
|
||||
mb_free(map->tmp_str);
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
i = -1;
|
||||
while (++i < map->size_y)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
get_next_line(fd, &map->tmp_str);
|
||||
mb_add(map->tmp_str);
|
||||
}
|
||||
map->content[i] = (char *)mb_alloc((map->size_x + 1) * sizeof(char));
|
||||
if (!map->content[i])
|
||||
{
|
||||
free(map->tmp_str);
|
||||
mb_free(map->tmp_str);
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
fill_row(map->content[i], map->tmp_str, map->size_x);
|
||||
free(map->tmp_str);
|
||||
mb_free(map->tmp_str);
|
||||
map->tmp_str = NULL;
|
||||
}
|
||||
map->content[i] = NULL;
|
||||
@@ -116,20 +121,20 @@ int init_parsing(t_game *game, char *file)
|
||||
|
||||
fd = check_elements(game, file);
|
||||
if (fd == -1)
|
||||
return (EXIT_FAILURE);
|
||||
mb_exit("Error\nInvalid .cub file.\n", EXIT_FAILURE);
|
||||
if (size_map(&(game->map), fd))
|
||||
{
|
||||
close(fd);
|
||||
return (EXIT_FAILURE);
|
||||
mb_exit("Error\nInvalid map format.\n", EXIT_FAILURE);
|
||||
}
|
||||
close(fd);
|
||||
fd = find_map(&(game->map), file);
|
||||
if (fd == -1)
|
||||
return (EXIT_FAILURE);
|
||||
mb_exit("Error\nCouldn't locate the map.\n", EXIT_FAILURE);
|
||||
if (fill_map(&(game->map), fd) == EXIT_FAILURE)
|
||||
{
|
||||
close(fd);
|
||||
return (EXIT_FAILURE);
|
||||
mb_exit("Error\nCouldn't save the map.\n", EXIT_FAILURE);
|
||||
}
|
||||
close(fd);
|
||||
return (EXIT_SUCCESS);
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* player_limits.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:50:31 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:50:37 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
int is_wall(t_game *game, int cell_x, int cell_y)
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* player_moves.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:50:18 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:50:21 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
void plr_posx_decrement(t_game *game, t_plr *plr)
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* player_rotates.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/04 13:49:40 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/05/04 13:49:57 by pblagoje ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3d.h"
|
||||
|
||||
void rotate(t_plr *plr, t_coord *coord)
|
||||
@@ -5,17 +17,13 @@ void rotate(t_plr *plr, t_coord *coord)
|
||||
int old_x;
|
||||
t_coord tmp;
|
||||
|
||||
// do nothing if not rotating
|
||||
if (plr->rot == 0)
|
||||
return ;
|
||||
// offset center
|
||||
tmp.x = coord->x - plr->pos.x;
|
||||
tmp.y = coord->y - plr->pos.y;
|
||||
// calculate new coordinates
|
||||
old_x = tmp.x;
|
||||
tmp.x = tmp.x * plr->cosi + tmp.y * plr->cosj;
|
||||
tmp.y = old_x * plr->sini + tmp.y * plr->sinj;
|
||||
// de-offset center
|
||||
coord->x = tmp.x + plr->pos.x;
|
||||
coord->y = tmp.y + plr->pos.y;
|
||||
}
|
||||
@@ -25,17 +33,13 @@ void rotate_double(t_plr *plr, t_d_coord *coord)
|
||||
double old_x;
|
||||
t_d_coord tmp;
|
||||
|
||||
// do nothing if not rotating
|
||||
if (plr->rot == 0)
|
||||
return ;
|
||||
// offset center
|
||||
tmp.x = coord->x - plr->exact.x;
|
||||
tmp.y = coord->y - plr->exact.y;
|
||||
// calculate new coordinates
|
||||
old_x = tmp.x;
|
||||
tmp.x = tmp.x * plr->cosi + tmp.y * plr->cosj;
|
||||
tmp.y = old_x * plr->sini + tmp.y * plr->sinj;
|
||||
// de-offset center
|
||||
coord->x = tmp.x + plr->exact.x;
|
||||
coord->y = tmp.y + plr->exact.y;
|
||||
}
|
||||
@@ -48,7 +52,6 @@ void plr_turn(t_plr *plr, int deg)
|
||||
if (plr->rot == -180)
|
||||
(plr->rot) *= -1;
|
||||
plr->rot += deg;
|
||||
// calculate trigo for rotations
|
||||
radi = plr->rot * M_PI / 180;
|
||||
radj = radi + (M_PI / 2);
|
||||
plr->cosi = cos(radi);
|
||||
|
||||
Reference in New Issue
Block a user