86 lines
2.4 KiB
C
86 lines
2.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* algo.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */
|
|
/* Updated: 2024/10/29 14:10:10 by mcolonna ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "algo.h"
|
|
#include "input.h"
|
|
|
|
void *g_mlx = NULL;
|
|
void *g_win = NULL;
|
|
t_map g_map;
|
|
t_player g_player;
|
|
|
|
void draw_screen(void)
|
|
{
|
|
void *img_ptr;
|
|
u_int32_t *img_data;
|
|
|
|
img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
img_data = get_data_addr(img_ptr);
|
|
if (!img_data)
|
|
exit(1);
|
|
render(img_data);
|
|
mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0);
|
|
mlx_destroy_image(g_mlx, img_ptr);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
static void loop(void)
|
|
{
|
|
move();
|
|
if (g_input_actions.quit)
|
|
{
|
|
mlx_destroy_window(g_mlx, g_win);
|
|
exit(0);
|
|
}
|
|
draw_screen();
|
|
}
|
|
|
|
static int loop_hook(void *param)
|
|
{
|
|
(void)param;
|
|
timedloop(loop);
|
|
return (0);
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
g_mlx = mlx_init();
|
|
input_init();
|
|
if (argc != 2)
|
|
{
|
|
printf("Syntax: %s <map.cub>\n", argv[0]);
|
|
return (1);
|
|
}
|
|
if (!map_from_file(&g_map, argv[1]))
|
|
return (1);
|
|
g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d");
|
|
mlx_hook(g_win, KeyPress, KeyPressMask, keypress, NULL);
|
|
mlx_hook(g_win, KeyRelease, KeyReleaseMask, keyrelease, NULL);
|
|
mlx_loop_hook(g_mlx, loop_hook, NULL);
|
|
draw_screen();
|
|
mlx_loop(g_mlx);
|
|
return (0);
|
|
}
|