aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-05 14:12:03 +0100
committerRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-05 14:12:03 +0100
commite6bbc5e1a7d1b88a5ed241283ec19fbaa672dc33 (patch)
tree7b5e2219785805cefc80bd209c892df42679c303 /src
parentBetter code (diff)
download42-cub3d-e6bbc5e1a7d1b88a5ed241283ec19fbaa672dc33.tar.gz
42-cub3d-e6bbc5e1a7d1b88a5ed241283ec19fbaa672dc33.tar.bz2
42-cub3d-e6bbc5e1a7d1b88a5ed241283ec19fbaa672dc33.tar.xz
42-cub3d-e6bbc5e1a7d1b88a5ed241283ec19fbaa672dc33.tar.zst
42-cub3d-e6bbc5e1a7d1b88a5ed241283ec19fbaa672dc33.zip
Bug fix
Diffstat (limited to 'src')
-rw-r--r--src/ft_check_missing.c2
-rw-r--r--src/ft_drawmap.c13
-rw-r--r--src/ft_drawsquare.c4
-rw-r--r--src/ft_get_map.c12
-rw-r--r--src/ft_init_lists.c1
-rw-r--r--src/ft_parse_map.c5
-rw-r--r--src/ft_print_list.c2
7 files changed, 28 insertions, 11 deletions
diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c
index 325af54..50fabbb 100644
--- a/src/ft_check_missing.c
+++ b/src/ft_check_missing.c
@@ -35,6 +35,8 @@ int
return (ft_missing_error("east side texture", clist));
else if (!clist->we_tex_path[0])
return (ft_missing_error("west side texture", clist));
+ else if (!clist->sprite_path[0])
+ return (ft_missing_error("sprite texture", clist));
else if (clist->wlist->x_size == 0 || clist->wlist->y_size == 0)
return (ft_missing_error("resolution", clist));
else if (clist->f_color < 0)
diff --git a/src/ft_drawmap.c b/src/ft_drawmap.c
index 02151a2..7d7cafe 100644
--- a/src/ft_drawmap.c
+++ b/src/ft_drawmap.c
@@ -19,7 +19,7 @@
static void
ft_draw_core_map(char **map, t_cub *clist)
{
- const uint16_t scale = clist->scale;
+ const uint8_t scale = clist->scale;
size_t x;
size_t y;
@@ -30,13 +30,14 @@ static void
while (map[y][x])
{
if (map[y][x] == '1')
- ft_drawsquare(scale + (x * (scale + 1)), scale + (y * (scale + 1)),
- 0x00aa99aa, clist);
+ ft_drawsquare(scale + (x * (scale + 1)),
+ scale + (y * (scale + 1)), 0x00aa99aa, clist);
else if (map[y][x] == '2')
- ft_drawsquare(scale + (x * (scale + 1)), scale + (y * (scale + 1)),
- 0x0033ccff, clist);
+ ft_drawsquare(scale + (x * (scale + 1)),
+ scale + (y * (scale + 1)), 0x0033ccff, clist);
else
- ft_drawsquare(scale + (x * (scale + 1)), scale + (y * (scale + 1)),
+ ft_drawsquare(scale + (x * (scale + 1)),
+ scale + (y * (scale + 1)),
ft_rgb_to_hex(clist->f_rgb), clist);
x++;
}
diff --git a/src/ft_drawsquare.c b/src/ft_drawsquare.c
index 9e23937..dd7cce7 100644
--- a/src/ft_drawsquare.c
+++ b/src/ft_drawsquare.c
@@ -19,8 +19,8 @@ void
ft_drawsquare(int a, int b, int rgb, t_cub *clist)
{
const uint16_t scale = clist->scale;
- int x;
- int y;
+ int x;
+ int y;
x = a;
y = b;
diff --git a/src/ft_get_map.c b/src/ft_get_map.c
index c5ab0d7..720f412 100644
--- a/src/ft_get_map.c
+++ b/src/ft_get_map.c
@@ -16,6 +16,17 @@
#include <stddef.h>
#include <stdint.h>
+static size_t
+ ft_get_map_h(char **map)
+{
+ size_t i;
+
+ i = 0;
+ while (map[i])
+ i++;
+ return (i);
+}
+
static void
ft_linecpy(char *line, char *mapl, size_t start)
{
@@ -98,6 +109,7 @@ int
clist->mapl[((clist->map_w + 1) * i) - 1] = '\0';
ft_free_words(clist->map);
clist->map = ft_split(clist->mapl, '\n');
+ clist->map_h = ft_get_map_h(clist->map);
ft_memdel((void**)&clist->mapl);
return (0);
}
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index 175f5ee..291ef7b 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -70,6 +70,7 @@ t_cub
clist->f_color = -1;
clist->c_color = -1;
clist->map_w = 0;
+ clist->map_h = 0;
clist->line_chk = 0;
clist->map_start = 0;
clist->isspawn = 0;
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index 5a72bd8..58df20a 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -119,8 +119,9 @@ void
ft_check_map_last_line(clist);
ft_get_player_spawn(clist->plist, clist);
ft_check_missing(clist);
- clist->scale = ((uint16_t)clist->wlist->x_size /
- (uint16_t)clist->map_w) - 1;
+ if ((clist->scale = ((uint16_t)clist->wlist->x_size /
+ (uint16_t)clist->map_w) - 1) < 1)
+ clist->scale = 1;
ft_print_list(clist);
close(fd);
}
diff --git a/src/ft_print_list.c b/src/ft_print_list.c
index c459a11..4e9e8d7 100644
--- a/src/ft_print_list.c
+++ b/src/ft_print_list.c
@@ -36,6 +36,6 @@ void
i++;
}
ft_printf("Map width -- [%zu]\n", clist->map_w);
- ft_printf("2D scale --- [%hu]\n", clist->scale);
+ ft_printf("2D scale --- [%hhu]\n", clist->scale);
ft_printf("----------------------\n");
}