diff options
author | Rudy Bousset <rbousset@z3r8p1.le-101.fr> | 2020-02-13 19:22:15 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z3r8p1.le-101.fr> | 2020-02-13 19:22:15 +0100 |
commit | fb98fd19ba9e27eb3a169a7599ce41fb0877b7a6 (patch) | |
tree | 2185933c9bde571819dfd480b48aa66459a30b2e /src | |
parent | Solid map is better (diff) | |
download | 42-cub3d-fb98fd19ba9e27eb3a169a7599ce41fb0877b7a6.tar.gz 42-cub3d-fb98fd19ba9e27eb3a169a7599ce41fb0877b7a6.tar.bz2 42-cub3d-fb98fd19ba9e27eb3a169a7599ce41fb0877b7a6.tar.xz 42-cub3d-fb98fd19ba9e27eb3a169a7599ce41fb0877b7a6.tar.zst 42-cub3d-fb98fd19ba9e27eb3a169a7599ce41fb0877b7a6.zip |
Better code structure
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_draw_map.c | 46 | ||||
-rw-r--r-- | src/ft_draw_scene.c (renamed from src/ft_drawmap.c) | 50 | ||||
-rw-r--r-- | src/ft_draw_square.c (renamed from src/ft_drawsquare.c) | 2 | ||||
-rw-r--r-- | src/ft_extra_keys.c | 18 | ||||
-rw-r--r-- | src/ft_init_lists.c | 1 | ||||
-rw-r--r-- | src/ft_key_events.c | 5 | ||||
-rw-r--r-- | src/main.c | 2 |
7 files changed, 74 insertions, 50 deletions
diff --git a/src/ft_draw_map.c b/src/ft_draw_map.c new file mode 100644 index 0000000..e32b4e9 --- /dev/null +++ b/src/ft_draw_map.c @@ -0,0 +1,46 @@ +#include <cub3d.h> +#include <stdint.h> + +static void + ft_draw_player(t_player *plist, t_cub *clist) +{ + const float x = plist->pos_x; + const float y = plist->pos_y - 1; + const uint16_t scale = clist->scale; + + ft_draw_square( + scale + (x * (scale)), + scale + (y * (scale)), + 0x009843fa, + clist); +} + +void + ft_draw_map(char **map, t_cub *clist) +{ + const uint8_t scale = clist->scale; + size_t x; + size_t y; + + x = 0; + y = 0; + while (map[y]) + { + while (map[y][x]) + { + if (map[y][x] == '1') + ft_draw_square(scale + (x * (scale)), + scale + (y * (scale)), 0x00aa99aa, clist); + else if (map[y][x] == '2') + ft_draw_square(scale + (x * (scale)), + scale + (y * (scale)), 0x0033ccff, clist); + else + ft_draw_square(scale + (x * (scale)), scale + (y * (scale)), + ft_rgb_to_hex(clist->f_rgb), clist); + x++; + } + x = 0; + y++; + } + ft_draw_player(clist->plist, clist); +} diff --git a/src/ft_drawmap.c b/src/ft_draw_scene.c index b8b4e2c..57cecd4 100644 --- a/src/ft_drawmap.c +++ b/src/ft_draw_scene.c @@ -16,52 +16,8 @@ #include <mlx.h> #include <stdint.h> -static void - ft_draw_core_map(char **map, t_cub *clist) -{ - const uint8_t scale = clist->scale; - size_t x; - size_t y; - - x = 0; - y = 0; - while (map[y]) - { - while (map[y][x]) - { - if (map[y][x] == '1') - ft_drawsquare(scale + (x * (scale)), - scale + (y * (scale)), 0x00aa99aa, clist); - else if (map[y][x] == '2') - ft_drawsquare(scale + (x * (scale)), - scale + (y * (scale)), 0x0033ccff, clist); - else - ft_drawsquare(scale + (x * (scale)), - scale + (y * (scale)), - ft_rgb_to_hex(clist->f_rgb), clist); - x++; - } - x = 0; - y++; - } -} - -static void - ft_draw_player(t_player *plist, t_cub *clist) -{ - const float x = plist->pos_x; - const float y = plist->pos_y; - const uint16_t scale = clist->scale; - - ft_drawsquare( - scale + (x * (scale + 1)), - scale + (y * (scale + 1)), - 0x009843fa, - clist); -} - void - ft_drawmap(t_cub *clist) + ft_draw_scene(t_cub *clist) { mlx_clear_window(clist->wlist->wlx, clist->wlist->winptr); clist->img.img = mlx_new_image(clist->wlist->wlx, @@ -69,8 +25,8 @@ void clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, &clist->img.sizeline, &clist->img.endian); ft_castray(clist); - ft_draw_core_map(clist->map, clist); - ft_draw_player(clist->plist, clist); + if (clist->minimap) + ft_draw_map(clist->map, clist); mlx_put_image_to_window(clist->wlist->wlx, clist->wlist->winptr, clist->img.img, 0, 0); mlx_destroy_image(clist->wlist->wlx, clist->img.img); diff --git a/src/ft_drawsquare.c b/src/ft_draw_square.c index dd7cce7..72cf904 100644 --- a/src/ft_drawsquare.c +++ b/src/ft_draw_square.c @@ -16,7 +16,7 @@ #include <stdint.h> void - ft_drawsquare(int a, int b, int rgb, t_cub *clist) + ft_draw_square(int a, int b, int rgb, t_cub *clist) { const uint16_t scale = clist->scale; int x; diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c new file mode 100644 index 0000000..5bbb4b4 --- /dev/null +++ b/src/ft_extra_keys.c @@ -0,0 +1,18 @@ +#include <cub3d.h> +#include <stdint.h> + +int8_t + ft_f1_key(t_cub *clist) +{ + if (clist->minimap == 0) + { + clist->minimap = 1; + ft_draw_scene(clist); + } + else if (clist->minimap == 1) + { + clist->minimap = 0; + ft_draw_scene(clist); + } + return (0); +} diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 8bb0d24..d56f40c 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -89,6 +89,7 @@ static t_cub clist->y_step = 0; clist->line_chk = 0; clist->map_start = 0; + clist->minimap = 0; clist->isspawn = 0; clist->f_rgb = ft_init_rgb(); clist->c_rgb = ft_init_rgb(); diff --git a/src/ft_key_events.c b/src/ft_key_events.c index 2112d2e..40f211a 100644 --- a/src/ft_key_events.c +++ b/src/ft_key_events.c @@ -73,6 +73,7 @@ int (tmp_code == FT_S_KEY) ? (keycode = 2) : 0; (tmp_code == FT_D_KEY) ? (keycode = 3) : 0; (tmp_code == 3) ? (keycode = INT16_MAX) : 0; + (tmp_code == 4) ? (keycode = INT16_MAX) : 0; pl = clist->plist; if (keycode <= 3) { @@ -81,10 +82,12 @@ int (pl->pos_x < 0.4) ? (pl->pos_x = 0.4) : 0; (pl->pos_y > clist->map_h - 1.4) ? (pl->pos_y = clist->map_h - 1.4) : 0; (pl->pos_x > clist->map_w - 1.4) ? (pl->pos_x = clist->map_w - 1.4) : 0; - ft_drawmap(clist); + ft_draw_scene(clist); return (0); } else if (keycode == FT_ESC_KEY) return (ft_exit(0, (clist))); + else if (keycode == FT_F1_KEY) + return (ft_f1_key(clist)); return (0); } @@ -32,7 +32,7 @@ int ft_parse_map(argv[1], clist); if (ft_init_winlx(clist) < 0) return (ft_exit(3, clist)); - ft_drawmap(clist); + ft_draw_scene(clist); ft_hooks_and_loops(clist->wlist, clist); return (0); } |