diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_draw_circle.c | 10 | ||||
-rw-r--r-- | src/ft_draw_hud.c | 113 | ||||
-rw-r--r-- | src/ft_draw_map.c | 14 | ||||
-rw-r--r-- | src/ft_draw_scene.c | 4 | ||||
-rw-r--r-- | src/ft_draw_square.c | 4 | ||||
-rw-r--r-- | src/ft_draw_verline.c | 34 | ||||
-rw-r--r-- | src/ft_extra_keys.c | 8 | ||||
-rw-r--r-- | src/ft_get_player_spawn.c | 5 | ||||
-rw-r--r-- | src/ft_get_res.c | 14 | ||||
-rw-r--r-- | src/ft_init_lists.c | 15 | ||||
-rw-r--r-- | src/ft_init_winlx.c | 5 | ||||
-rw-r--r-- | src/ft_key_loop.c | 12 | ||||
-rw-r--r-- | src/ft_map_error.c | 2 | ||||
-rw-r--r-- | src/ft_music.c | 19 |
14 files changed, 213 insertions, 46 deletions
diff --git a/src/ft_draw_circle.c b/src/ft_draw_circle.c index be95617..570543a 100644 --- a/src/ft_draw_circle.c +++ b/src/ft_draw_circle.c @@ -16,7 +16,7 @@ #include <math.h> void - ft_draw_circle(int32_t a, int32_t b, int32_t color, t_cub *cl) + ft_draw_circle(float a, float b, int32_t color, t_cub *cl) { float scale; float i; @@ -31,10 +31,10 @@ void while (i < 360) { angle = i; - x1 = scale * cos(angle * 3.14159 / 180); - y1 = scale * sin(angle * 3.14159 / 180); - *(int*)(cl->img.ptr + (a + (int)x1) * 4 + - ((b + (int)y1) * cl->img.sizeline)) = color; + x1 = scale * cos(angle * 3.14159265358979323846 / 180); + y1 = scale * sin(angle * 3.14159265358979323846 / 180); + *(int*)(cl->img.ptr + ((int)a + (int)x1) * 4 + + (((int)b + (int)y1) * cl->img.sizeline)) = color; i += 0.1; } i = 0; diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c new file mode 100644 index 0000000..9cb5b1c --- /dev/null +++ b/src/ft_draw_hud.c @@ -0,0 +1,113 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_hud.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/22 20:02:47 by rbousset #+# #+# */ +/* Updated: 2020/02/22 20:02:48 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <cub3d.h> +#include <mlx.h> +#include <stdint.h> + +static void + ft_draw_hud_back(t_win *wl, t_cub *cl) +{ + const uint16_t scl = cl->mlist->scale; + uint32_t x; + uint32_t y; + int32_t col; + + col = 0x00404040; + x = 0; + y = wl->y_size - ((cl->mlist->map_h * scl)); + while (x < wl->x_size) + { + while (y < wl->y_size) + { + *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = col; + if (!(y % 3)) + { + if (col < 0x00909090) + col += 0x00010101; + } + y++; + } + col = 0x00404040; + y = wl->y_size - ((cl->mlist->map_h * scl)); + x++; + } +} + +static void + ft_draw_hud_back_top_l(size_t map_h, size_t map_w, t_win *wl, t_cub *cl) +{ + const uint16_t scl = cl->mlist->scale; + uint32_t x; + uint32_t y; + int32_t col; + + col = 0x00373737; + x = 0; + y = wl->y_size - (map_h * scl) - 20; + while (x < (map_w * scl) + 20) + { + while (y < wl->y_size - (map_h * scl)) + { + *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = col; + if (!(y % 3)) + { + if (col < 0x00aaaaaa) + col += 0x00010101; + } + y++; + } + col = 0x00353535; + y = wl->y_size - (map_h * scl) - 20; + x++; + } +} + +static void + ft_draw_hud_back_top_r(size_t map_h, size_t map_w, t_win *wl, t_cub *cl) +{ + const uint16_t scl = cl->mlist->scale; + uint32_t x; + uint32_t y; + int32_t col; + + col = 0x00373737; + x = wl->x_size - (map_w * scl) + 20; + y = wl->y_size - (map_h * scl) - 20; + while (x < wl->x_size) + { + while (y < wl->y_size - (map_h * scl)) + { + *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = col; + if (!(y % 2)) + { + if (col < 0x00aaaaaa) + col += 0x00010101; + } + y++; + } + col = 0x00353535; + y = wl->y_size - (map_h * scl) - 20; + x++; + } +} + +void + ft_draw_hud(t_cub *clist) +{ + ft_draw_hud_back(clist->wlist, clist); + ft_draw_hud_back_top_l(clist->mlist->map_h, + clist->mlist->map_w, clist->wlist, clist); + ft_draw_hud_back_top_r(clist->mlist->map_h, + clist->mlist->map_w, clist->wlist, clist); + ft_draw_map(clist->mlist->map, clist); +} diff --git a/src/ft_draw_map.c b/src/ft_draw_map.c index 39299c1..a334fc1 100644 --- a/src/ft_draw_map.c +++ b/src/ft_draw_map.c @@ -24,9 +24,9 @@ static uint16_t static void ft_draw_player(t_player *plist, t_cub *clist) { + const uint16_t scale = clist->mlist->scale; const float x = plist->pos_x; const float y = plist->pos_y; - const uint16_t scale = clist->mlist->scale; ft_draw_circle( (scale / 2) + (x * (scale)), @@ -49,14 +49,14 @@ void while (map[y][x]) { if (map[y][x] == '1') - ft_draw_square(scale + (x * (scale)), - ft_y_offset(clist) + (y * (scale)), 0x0000ffaa, clist); + ft_draw_square(scale + 9 + (x * (scale)), + ft_y_offset(clist) - 9 + (y * (scale)), 0x00ca5422, clist); else if (map[y][x] == '2') - ft_draw_square(scale + (x * (scale)), - ft_y_offset(clist) + (y * (scale)), 0x0033ccff, clist); + ft_draw_square(scale + 9 + (x * (scale)), + ft_y_offset(clist) - 9 + (y * (scale)), 0x0033ccff, clist); else - ft_draw_square(scale + (x * (scale)), ft_y_offset(clist) + - (y * (scale)), ft_rgb_to_hex(clist->f_rgb), clist); + ft_draw_square(scale + 9 + (x * (scale)), ft_y_offset(clist) + - 9 + (y * (scale)), 0x006afa6a, clist); x++; } x = 0; diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 3bf453a..b5f2283 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -23,8 +23,8 @@ void clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, &clist->img.sizeline, &clist->img.endian); ft_castray(clist); - if (clist->minimap) - ft_draw_map(clist->mlist->map, clist); + if (clist->ishud) + ft_draw_hud(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_draw_square.c b/src/ft_draw_square.c index 8bbce36..355969e 100644 --- a/src/ft_draw_square.c +++ b/src/ft_draw_square.c @@ -23,9 +23,9 @@ void x = a; y = b; - while (x > a - scale) + while (x >= a - scale) { - while (y > b - scale) + while (y >= b - scale) { *(int*)(clist->img.ptr + (x * 4 + (y * clist->img.sizeline))) = rgb; y--; diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index d526b6a..e1bcb16 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -37,6 +37,36 @@ static void } } +/* #include <libft.h> */ +/* static void */ +/* ft_draw_ceil_tex(t_cub *cl, int x, int y) */ +/* { */ +/* int16_t i; */ +/* int32_t d; */ +/* int32_t tex_y; */ + +/* i = 0; */ +/* while (i < y) */ +/* { */ +/* d = i * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; */ +/* d = (d <= 0) ? (-d) : (d); */ +/* ft_printf("%d\n", d); */ +/* tex_y = ((d * cl->tlist[1].img_h) / cl->rlist.line_h) / 256; */ +/* (tex_y <= 0) ? (tex_y = 1) : 0; */ +/* cl->img.ptr[x * 4 + (cl->img.sizeline * i)] = */ +/* (int8_t)cl->tlist[1].ptr[cl->tlist[1].tex_x * 4 + 4 * */ +/* cl->tlist[1].img_h * tex_y]; */ +/* cl->img.ptr[x * 4 + (cl->img.sizeline * i) + 1] = */ +/* (int8_t)cl->tlist[1].ptr[cl->tlist[1].tex_x * 4 + 4 * */ +/* cl->tlist[1].img_h * tex_y + 1]; */ +/* cl->img.ptr[x * 4 + (cl->img.sizeline * i) + 2] = */ +/* (int8_t)cl->tlist[1].ptr[cl->tlist[1].tex_x * 4 + 4 * */ +/* cl->tlist[1].img_h * tex_y + 2]; */ +/* cl->img.ptr[x * 4 + cl->wlist->x_size * i + 3] = (char)0; */ +/* i++; */ +/* } */ +/* } */ + int8_t ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2) { @@ -46,12 +76,14 @@ int8_t (y < 0) ? (y = 0) : 0; (y2 < 0) ? (y2 = 0) : 0; ft_draw_ceil(cl, y, x); + (cl->rlist.line_h <= 0) ? (cl->rlist.line_h = 1) : 0; + /* ft_draw_ceil_tex(cl, y, x); */ while (y < y2) { d = y * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; d = (d <= 0) ? (-d) : (d); tex_y = ((d * cl->tlist[cl->w_side].img_h) / cl->rlist.line_h) / 256; - (tex_y < 0) ? (tex_y = 0) : 0; + (tex_y <= 0) ? (tex_y = 1) : 0; ft_draw_texture(cl, x, y, tex_y); y++; } diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c index 39a297b..507f808 100644 --- a/src/ft_extra_keys.c +++ b/src/ft_extra_keys.c @@ -53,14 +53,14 @@ int int ft_f1_key(t_cub *clist) { - if (clist->minimap == 0) + if (clist->ishud == 0) { - clist->minimap = 1; + clist->ishud = 1; ft_draw_scene(clist); } - else if (clist->minimap == 1) + else if (clist->ishud == 1) { - clist->minimap = 0; + clist->ishud = 0; ft_draw_scene(clist); } return (0); diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c index e1f313e..617ec22 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -32,13 +32,8 @@ static void static void ft_get_s_dir(t_player *pl) { - float sav_dir_x; - float sav_plane_x; - - sav_dir_x = pl->dir_x; pl->dir_x = -pl->dir_x; pl->dir_y = -pl->dir_y; - sav_plane_x = pl->plane_x; pl->plane_x = -pl->plane_x; pl->plane_y = -pl->plane_y; } diff --git a/src/ft_get_res.c b/src/ft_get_res.c index 8607f62..26853be 100644 --- a/src/ft_get_res.c +++ b/src/ft_get_res.c @@ -31,6 +31,15 @@ static int8_t return (0); } +static void + ft_securize_scr(t_win *wl) +{ + while (wl->x_size % 10) + wl->x_size -= 1; + while (wl->y_size % 10) + wl->y_size -= 1; +} + int8_t ft_get_res(char **words, t_cub *clist) { @@ -48,8 +57,8 @@ int8_t return (-1); wlist->x_size = ft_atoi(words[1]); wlist->y_size = ft_atoi(words[2]); - if (wlist->x_size <= 1 - || wlist->y_size <= 1) + if (wlist->x_size <= 10 + || wlist->y_size <= 10) { ft_strlcpy(clist->errmsg, FT_ERR_RES_SMALL, ft_strlen(FT_ERR_RES_SMALL) + 1); @@ -57,5 +66,6 @@ int8_t } if (ft_get_screen_size(wlist) < 0) return (-1); + ft_securize_scr(wlist); return (0); } diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 6917db2..5592358 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -78,16 +78,19 @@ static t_cub !(clist->mlist = ft_init_map())) return (NULL); ft_bzero(clist->errmsg, 40); - i = 0; - while (i < 5) - { + i = -1; + while (++i < 5) clist->key_input[i] = -1; - i++; - } - clist->minimap = 0; + clist->ishud = 0; clist->f_rgb = ft_init_rgb(); clist->c_rgb = ft_init_rgb(); clist->rlist = ft_init_s_ray(); + clist->key_ptr[0] = ft_w_key; + clist->key_ptr[1] = ft_a_key; + clist->key_ptr[2] = ft_s_key; + clist->key_ptr[3] = ft_d_key; + clist->key_ptr[4] = ft_left_key; + clist->key_ptr[5] = ft_right_key; return (clist); } diff --git a/src/ft_init_winlx.c b/src/ft_init_winlx.c index 6657408..b41dc4a 100644 --- a/src/ft_init_winlx.c +++ b/src/ft_init_winlx.c @@ -26,7 +26,8 @@ int clist->wlist->x_size, clist->wlist->y_size, "Cub3D"))) return (-1); clist->wlist->inited = 1; - ft_printf("Created window of size %ux%u\n", - clist->wlist->x_size, clist->wlist->y_size); + ft_printf("Created window of size %ux%u\nHost OS: %s\n", + clist->wlist->x_size, clist->wlist->y_size, FT_OS); + /* ft_music(clist); */ return (0); } diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index aa7017f..d92b37e 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -13,6 +13,7 @@ #include <libft.h> #include <cub3d.h> #include <stdint.h> +#include <stddef.h> static void ft_collision(float old_y, float old_x, t_player *pl, t_map *ml) @@ -30,24 +31,17 @@ static void int ft_key_loop(t_cub *cl) { - int (*fun_ptr[6])(t_cub*); uint8_t i; const float old_y = cl->plist->pos_y; const float old_x = cl->plist->pos_x; - fun_ptr[0] = ft_w_key; - fun_ptr[1] = ft_a_key; - fun_ptr[2] = ft_s_key; - fun_ptr[3] = ft_d_key; - fun_ptr[4] = ft_left_key; - fun_ptr[5] = ft_right_key; i = 0; while (i < 5 && cl->key_input[i] != -1 && cl->key_input[i] <= 5) { - (*fun_ptr[cl->key_input[i]])(cl); + cl->key_ptr[cl->key_input[i]](cl); ft_collision(old_y, old_x, cl->plist, cl->mlist); i++; } - ft_draw_scene(cl); + ft_draw_scene(cl); return (0); } diff --git a/src/ft_map_error.c b/src/ft_map_error.c index 5d5ab68..a36507a 100644 --- a/src/ft_map_error.c +++ b/src/ft_map_error.c @@ -19,7 +19,7 @@ int { ft_dprintf(STDERR_FILENO, "Error\n"); ft_dprintf(STDERR_FILENO, - "\033[1;31mMap error: line %zu: %s\033[0m\n", + "\033[1;31mMap error: line %lu: %s\033[0m\n", clist->mlist->line_chk, errmsg); return (ft_exit(4, clist)); diff --git a/src/ft_music.c b/src/ft_music.c new file mode 100644 index 0000000..1be430b --- /dev/null +++ b/src/ft_music.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_music.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 17:17:54 by rbousset #+# #+# */ +/* Updated: 2020/02/24 17:17:56 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <cub3d.h> + +void + ft_music(t_cub *cl) +{ + (void)cl; +} |