42_cub3d/algo.c
ReverseSky a824900a7c a
2024-10-15 13:58:25 +02:00

89 lines
3.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: greg <greg@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */
/* Updated: 2024/10/14 18:07:09 by greg ### ########.fr */
/* */
/* ************************************************************************** */
#include "algo.h"
int worldMap[mapWidth][mapHeight] =
{
{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,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1},
{1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1},
{1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1},
{1,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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}
};
/* dirX -1 = north dirX 1 = sud dirY -1 = east dirY 1 = west*/
static int initalgo(t_ray *ray)
{
ray->posX = 13;
ray->posY = 10;
ray->dirX = -1;
ray->dirY = 0;
ray->planeX = 0;
ray->planeY = 0.66; // FOV de 66 degres
ray->movespeed = 0.1;
ray->rotspeed = 0.1;
ray->width = 1920;
ray->height = 1080;
return (0);
}
void load_textures(t_tex *tex, t_ray *ray)
{
int width, height;
// Charger les textures
tex->tex_north = mlx_xpm_file_to_image(ray->mlx_ptr, "textures/north.xpm", &ray->width, &ray->height);
tex->tex_south = mlx_xpm_file_to_image(ray->mlx_ptr, "textures/south.xpm", &ray->width, &ray->height);
tex->tex_east = mlx_xpm_file_to_image(ray->mlx_ptr, "textures/east.xpm", &ray->width, &ray->height);
tex->tex_west = mlx_xpm_file_to_image(ray->mlx_ptr, "textures/west.xpm", &ray->width, &ray->height);
}
int main(void)
{
t_ray ray;
// Initialisation
ray.mlx_ptr = mlx_init();
ray.win_ptr = mlx_new_window(ray.mlx_ptr, 1920, 1080, "cub3d");
ray.img_ptr = mlx_new_image(ray.mlx_ptr, 1920, 1080);
initalgo(&ray);
// hook keypress
mlx_hook(ray.win_ptr, 2, 1L<<0, keypress, &ray);
// render the initial frame
render(&ray);
// start the mlx loop
mlx_loop(ray.mlx_ptr);
return (0);
}