102 lines
3.9 KiB
C
102 lines
3.9 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* algo.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */
|
|
/* Updated: 2024/10/15 16:00:41 by mcolonna ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "algo.h"
|
|
|
|
void *g_mlx = NULL;
|
|
void *g_win = NULL;
|
|
t_ray g_ray;
|
|
|
|
int g_world_map[MAP_WIDTH][MAP_HEIGHT] = {
|
|
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
|
{1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
|
|
{1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
|
|
{1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
|
|
{1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1},
|
|
{1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
|
|
{1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1},
|
|
{1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
|
|
{1, 0, 1, 1, 0, 0, 1, 1, 0,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, 0, 0, 0, 0, 0, 0, 1},
|
|
{1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
|
|
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
|
|
};
|
|
|
|
// TODO from map
|
|
|
|
static int initalgo(void)
|
|
{
|
|
g_ray.pos.x = 14;
|
|
g_ray.pos.y = 6.5;
|
|
g_ray.rot = 0;
|
|
return (0);
|
|
}
|
|
|
|
// TODO manage image format error better
|
|
|
|
void draw_screen(void)
|
|
{
|
|
int bpp;
|
|
int size_line;
|
|
int endian;
|
|
void *img_ptr;
|
|
u_int32_t *img_data;
|
|
|
|
img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
img_data = (u_int32_t *)
|
|
mlx_get_data_addr(img_ptr, &bpp, &size_line, &endian);
|
|
if (bpp != 32 || endian != 0)
|
|
{
|
|
printf("image format error\n");
|
|
exit(1);
|
|
}
|
|
render(img_data);
|
|
mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0);
|
|
}
|
|
|
|
void load_textures(t_tex *tex)
|
|
{
|
|
int width;
|
|
int height;
|
|
|
|
tex->tex_north = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm",
|
|
&width, &height);
|
|
tex->tex_south = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm",
|
|
&width, &height);
|
|
tex->tex_east = mlx_xpm_file_to_image(g_mlx, "textures/east.xpm",
|
|
&width, &height);
|
|
tex->tex_west = mlx_xpm_file_to_image(g_mlx, "textures/west.xpm",
|
|
&width, &height);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
g_mlx = mlx_init();
|
|
g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d");
|
|
initalgo();
|
|
mlx_hook(g_win, KeyPress, KeyPressMask, keypress, NULL);
|
|
draw_screen();
|
|
mlx_loop(g_mlx);
|
|
return (0);
|
|
}
|