mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
started to move all variables to a struct
This commit is contained in:
parent
f9825feeea
commit
c1484d2d3c
6 changed files with 74 additions and 31 deletions
47
src/main.c
47
src/main.c
|
|
@ -6,12 +6,11 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
|
||||
/* Updated: 2025/06/24 10:40:02 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/06/24 11:50:17 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/libft.h"
|
||||
#include "../includes/cub3d_consts.h"
|
||||
#include "../includes/structs.h"
|
||||
#include "../mlx/mlx.h"
|
||||
#include "../includes/maputils.h"
|
||||
|
|
@ -24,10 +23,11 @@ void my_mlx_pixel_put(t_mlx_data *data, int x, int y, int color)
|
|||
char *dst;
|
||||
|
||||
dst = data->addr + (y * data->line_length + x * (data->bits_per_pixel / 8));
|
||||
*(unsigned int*)dst = color;
|
||||
*(unsigned int *)dst = color;
|
||||
}
|
||||
|
||||
void draw_2d_wall(unsigned int color, t_mlx_data *data, int size, int x, int y)
|
||||
void draw_2d_wall(unsigned int color, t_mlx_data *data,
|
||||
int size, int x, int y)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
|
@ -85,15 +85,15 @@ void draw_map(t_mapdata *map, t_mlx_data *data)
|
|||
int j;
|
||||
|
||||
i = 0;
|
||||
while (map->mapflood[i])
|
||||
while (map->map[i])
|
||||
{
|
||||
j = 0;
|
||||
while (map->mapflood[i][j])
|
||||
while (map->map[i][j])
|
||||
{
|
||||
if (map->mapflood[i][j] == '1')
|
||||
draw_2d_wall(map->f_color, data, 10, 10 * j, 10 * i);
|
||||
if (map->map[i][j] == '1')
|
||||
draw_2d_wall(map->f_color, data, 20, 20 * j, 20 * i);
|
||||
else if (ft_strchr("NSEW", map->map[i][j]))
|
||||
draw_2d_wall(0x00FF0000, data, 10, 10 * j, 10 * i);
|
||||
draw_2d_wall(0x00FF0000, data, 20, 20 * j, 20 * i);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
|
|
@ -102,23 +102,20 @@ void draw_map(t_mapdata *map, t_mlx_data *data)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
void *mlx;
|
||||
void *mlx_win;
|
||||
t_mlx_data data;
|
||||
t_mapdata map;
|
||||
t_cub3d_data data;
|
||||
|
||||
ft_bzero(&map, sizeof(map));
|
||||
data.map = ft_calloc(sizeof(t_mapdata), 1);
|
||||
if (argc < 2)
|
||||
return (ft_printf("Error: Missing cub3d file\n"), 1);
|
||||
if (!check_cubfile(argv[1], &map))
|
||||
return (ft_printf("Error: Wrong map file. Reason: %s\n", map.error), 1);
|
||||
mlx = mlx_init();
|
||||
mlx_win = mlx_new_window(mlx, 800, 600, "Cub3d");
|
||||
data.img = mlx_new_image(mlx, 800, 600);
|
||||
data.addr = mlx_get_data_addr(data.img, &data.bits_per_pixel, &data.line_length, &data.endian);
|
||||
mlx_hook(mlx_win, 17, 0L, destroy, &map);
|
||||
draw_map(&map, &data);
|
||||
mlx_key_hook(mlx_win, key_destroy, &map);
|
||||
mlx_put_image_to_window(mlx, mlx_win, data.img, 0, 0);
|
||||
mlx_loop(mlx);
|
||||
if (!check_cubfile(argv[1], data.map))
|
||||
return (ft_printf("Error: Wrong map file. Reason: %s\n", data.map->error), 1);
|
||||
data.mlx = mlx_init();
|
||||
data.mlx_win = mlx_new_window(data.mlx, 800, 600, "Cub3d");
|
||||
data.mlx_data->img = mlx_new_image(data.mlx, 800, 600);
|
||||
data.mlx_data->addr = mlx_get_data_addr(data.mlx_data->img, &data.mlx_data->bits_per_pixel, &data.mlx_data->line_length, &data.mlx_data->endian);
|
||||
mlx_hook(data.mlx_win, 17, 0L, destroy, data.map);
|
||||
draw_map(data.map, data.mlx_data);
|
||||
mlx_key_hook(data.mlx_win, key_destroy, data.map);
|
||||
mlx_put_image_to_window(data.mlx, data.mlx_win, data.mlx_data->img, 0, 0);
|
||||
mlx_loop(data.mlx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
|
||||
/* Updated: 2025/06/24 10:40:30 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/06/24 11:31:48 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -59,7 +59,6 @@ void flood_fill(t_mapdata *map, int x, int y)
|
|||
return ;
|
||||
if (map->mapflood[y][x] == ' ' || map->mapflood[y][x] == '\n')
|
||||
map->isvalid = false;
|
||||
|
||||
map->mapflood[y][x] = '1';
|
||||
flood_fill(map, x + 1, y);
|
||||
flood_fill(map, x, y + 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue