Skip to content

Commit

Permalink
Merge branch 'main' into mouse_hide_show_removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Haliris authored Sep 2, 2024
2 parents 23915a4 + a0bc695 commit 30db053
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 9 deletions.
12 changes: 10 additions & 2 deletions includes/cub3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jteissie <jteissie@student.42.fr> +#+ +:+ +#+ */
/* By: tsuchen <tsuchen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/15 00:19:44 by tsuchen #+# #+# */
/* Updated: 2024/09/02 13:38:28 by jteissie ### ########.fr */
/* Updated: 2024/09/02 16:29:45 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -50,6 +50,10 @@
# define ROT_STEP 1.5f
# define MOUSE_ROT_STEP 1.0f
# define MOV_STEP 0.1f
# define MINI_MAP_W 200
# define MINI_MAP_H 200
# define MINI_MAP_X 15
# define MINI_MAP_Y 15
# define KEY_PRESS 2
# define MOUSE_PRESS 4
# define MOUSE_MOVE 6
Expand Down Expand Up @@ -111,11 +115,13 @@ typedef struct s_data
char *map_path;
int map_fd;
size_t map_bound;
size_t map_width;
char **map;
void *mlx;
void *window;
int pause;
t_image image;
t_image mini_map;
t_textdata *textures;
t_wall w_data;
t_vec p_pos;
Expand Down Expand Up @@ -143,5 +149,7 @@ int rc_rendering(t_data *data);
void rc_render_wall(t_data *data, int x, int y, double ray_dist);
void rc_mlx_pixel_put(t_image *image, int x, int y, int color);
void rc_stripe_pixel_put(t_data *data, int x, double ray_dist);
/* Mini Map */
void put_mini_map(t_data *data);

#endif
2 changes: 1 addition & 1 deletion maps/subject_test.cub
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ C 225,30,0
1000000000110000000000001
1011000001110000000000001
1001000000000000000000001
111111111011000001110000100000001
1111111110110000011100001000000011
100000000011000001110111111111111
11110111111111011100000010001
11110111111111011101010000001
Expand Down
1 change: 1 addition & 0 deletions maps/wall_test.cub
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ C 225,30,0
100010001
1000N0001
100000001
100111001
111111111
8 changes: 6 additions & 2 deletions srcs/game_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* game_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jteissie <jteissie@student.42.fr> +#+ +:+ +#+ */
/* By: tsuchen <tsuchen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/27 17:03:43 by jteissie #+# #+# */
/* Updated: 2024/09/02 13:33:15 by jteissie ### ########.fr */
/* Updated: 2024/09/02 16:17:55 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -65,5 +65,9 @@ int game_init(t_data *data)
data->image.img = mlx_new_image(data->mlx, WIDTH, HEIGHT);
data->image.addr = mlx_get_data_addr(data->image.img, &data->image.bpp,
&data->image.line_length, &data->image.endian);
data->mini_map.img = mlx_new_image(data->mlx, MINI_MAP_W, MINI_MAP_H);
data->mini_map.addr = mlx_get_data_addr(data->mini_map.img,
&data->mini_map.bpp, &data->mini_map.line_length,
&data->mini_map.endian);
return (SUCCESS);
}
4 changes: 3 additions & 1 deletion srcs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jteissie <jteissie@student.42.fr> +#+ +:+ +#+ */
/* By: tsuchen <tsuchen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/15 12:03:33 by tsuchen #+# #+# */
/* Updated: 2024/09/02 17:28:23 by jteissie ### ########.fr */
Expand All @@ -27,6 +27,7 @@
// i++;
// }
// printf("Map bound: %zu\n", data->map_bound);
// printf("Map width: %zu\n", data->map_width);
// }

static t_bool is_cub_file(char *file)
Expand Down Expand Up @@ -54,6 +55,7 @@ static int init_data(t_data *data, char *map_file)
ft_putstr_fd("Could not open map file!\n", STDERR_FILENO);
return (PANIC);
}
data->map_width = 0;
return (SUCCESS);
}

Expand Down
29 changes: 28 additions & 1 deletion srcs/map/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,35 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/15 12:13:17 by tsuchen #+# #+# */
/* Updated: 2024/08/15 12:13:23 by tsuchen ### ########.fr */
/* Updated: 2024/09/02 16:30:51 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

#include "cub3d.h"

void put_mini_map(t_data *data)
{
int x;
int y;
int map_x;
int map_y;

x = 0;
while (x < MINI_MAP_W)
{
y = 0;
while (y < MINI_MAP_H)
{
map_x = x * (data->map_width - 1) / MINI_MAP_W;
map_y = y * (data->map_bound) / MINI_MAP_H;
if (data->map[map_y][map_x] == '1')
rc_mlx_pixel_put(&data->mini_map, x, y, 0x212529);
else
rc_mlx_pixel_put(&data->mini_map, x, y, 0xE9ECEF);
if ((int)data->p_pos.x == map_y && (int)data->p_pos.y == map_x)
rc_mlx_pixel_put(&data->mini_map, x, y, 0xD62828);
y++;
}
x++;
}
}
4 changes: 3 additions & 1 deletion srcs/parser/build_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/16 16:51:48 by jteissie #+# #+# */
/* Updated: 2024/08/30 14:07:33 by tsuchen ### ########.fr */
/* Updated: 2024/09/02 12:16:14 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -43,6 +43,8 @@ static t_list *read_map_file(char *line, t_data *data)
return (NULL);
}
ft_lstadd_back(&map_list, new_node);
if (ft_strlen(line) > data->map_width)
data->map_width = ft_strlen(line);
}
else
free(line);
Expand Down
5 changes: 4 additions & 1 deletion srcs/raycasting/raycasting.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/15 12:13:34 by tsuchen #+# #+# */
/* Updated: 2024/09/02 10:37:34 by tsuchen ### ########.fr */
/* Updated: 2024/09/02 16:10:12 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -84,6 +84,9 @@ int rc_rendering(t_data *data)
ray_dist = rc_raydist(&data->ray_dir, data);
rc_stripe_pixel_put(data, x, ray_dist);
}
put_mini_map(data);
mlx_put_image_to_window(data->mlx, data->window, data->image.img, 0, 0);
mlx_put_image_to_window(data->mlx, data->window, data->mini_map.img,
MINI_MAP_X, MINI_MAP_Y);
return (0);
}

0 comments on commit 30db053

Please sign in to comment.