aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_draw_map.c
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z3r8p1.le-101.fr>2020-02-13 19:22:15 +0100
committerRudy Bousset <rbousset@z3r8p1.le-101.fr>2020-02-13 19:22:15 +0100
commitfb98fd19ba9e27eb3a169a7599ce41fb0877b7a6 (patch)
tree2185933c9bde571819dfd480b48aa66459a30b2e /src/ft_draw_map.c
parentSolid map is better (diff)
download42-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/ft_draw_map.c')
-rw-r--r--src/ft_draw_map.c46
1 files changed, 46 insertions, 0 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);
+}