aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-02-04 23:45:21 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-02-04 23:45:21 +0100
commit20a7a10c762d2d81d3f749d08d4da3f56a045dce (patch)
tree0e04d3d6b0828b4b65e1bb4d49b464678492b03d
parentPretty good (diff)
download42-cub3d-20a7a10c762d2d81d3f749d08d4da3f56a045dce.tar.gz
42-cub3d-20a7a10c762d2d81d3f749d08d4da3f56a045dce.tar.bz2
42-cub3d-20a7a10c762d2d81d3f749d08d4da3f56a045dce.tar.xz
42-cub3d-20a7a10c762d2d81d3f749d08d4da3f56a045dce.tar.zst
42-cub3d-20a7a10c762d2d81d3f749d08d4da3f56a045dce.zip
Scale
Diffstat (limited to '')
-rw-r--r--inc/cub3d.h1
-rw-r--r--map/map_one.cub3
-rw-r--r--src/ft_drawmap.c21
-rw-r--r--src/ft_drawsquare.c8
-rw-r--r--src/ft_parse_map.c3
-rw-r--r--src/ft_print_list.c1
6 files changed, 24 insertions, 13 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index ce4c658..f031c1c 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -88,6 +88,7 @@ typedef struct s_cub
size_t line_chk;
size_t map_start;
uint8_t isspawn;
+ uint16_t scale;
struct s_win *wlist;
struct s_player *plist;
struct s_img img;
diff --git a/map/map_one.cub b/map/map_one.cub
index d5b931a..f0bd991 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -1,5 +1,4 @@
-R 1200 600
-
+R 1720 880
NO ./path_to_the_north_texture
SO ./path_to_the_south_texture
diff --git a/src/ft_drawmap.c b/src/ft_drawmap.c
index 698d852..02151a2 100644
--- a/src/ft_drawmap.c
+++ b/src/ft_drawmap.c
@@ -14,12 +14,14 @@
#include <libft.h>
#include <cub3d.h>
#include <mlx.h>
+#include <stdint.h>
static void
ft_draw_core_map(char **map, t_cub *clist)
{
- size_t x;
- size_t y;
+ const uint16_t scale = clist->scale;
+ size_t x;
+ size_t y;
x = 0;
y = 0;
@@ -28,13 +30,13 @@ static void
while (map[y][x])
{
if (map[y][x] == '1')
- ft_drawsquare(40 + (x * 41), 40 + (y * 41),
+ ft_drawsquare(scale + (x * (scale + 1)), scale + (y * (scale + 1)),
0x00aa99aa, clist);
else if (map[y][x] == '2')
- ft_drawsquare(40 + (x * 41), 40 + (y * 41),
+ ft_drawsquare(scale + (x * (scale + 1)), scale + (y * (scale + 1)),
0x0033ccff, clist);
else
- ft_drawsquare(40 + (x * 41), 40 + (y * 41),
+ ft_drawsquare(scale + (x * (scale + 1)), scale + (y * (scale + 1)),
ft_rgb_to_hex(clist->f_rgb), clist);
x++;
}
@@ -46,10 +48,13 @@ static void
static void
ft_draw_player(t_player *plist, t_cub *clist)
{
- const float x = plist->pos_x;
- const float y = plist->pos_y;
+ const float x = plist->pos_x;
+ const float y = plist->pos_y;
+ const uint16_t scale = clist->scale;
- ft_drawsquare(40 + (x * 41), 40 + (y * 41), 0x009843fa, clist);
+ ft_drawsquare(scale + (x * (scale + 1)),
+ scale + (y * (scale + 1)),
+ 0x009843fa, clist);
}
void
diff --git a/src/ft_drawsquare.c b/src/ft_drawsquare.c
index 1488c68..9e23937 100644
--- a/src/ft_drawsquare.c
+++ b/src/ft_drawsquare.c
@@ -11,20 +11,22 @@
/* / */
/* ************************************************************************** */
-#include <mlx.h>
#include <cub3d.h>
+#include <mlx.h>
+#include <stdint.h>
void
ft_drawsquare(int a, int b, int rgb, t_cub *clist)
{
+ const uint16_t scale = clist->scale;
int x;
int y;
x = a;
y = b;
- while (x > a - 40)
+ while (x > a - scale)
{
- while (y > b - 40)
+ while (y > b - scale)
{
*(int*)(clist->img.ptr + (x * 4 + (y * clist->img.sizeline))) = rgb;
y--;
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index 29f2c43..f5e491f 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -16,6 +16,7 @@
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
+#include <stdint.h>
static void
ft_check_cub(const char *map_path, t_cub *clist)
@@ -118,6 +119,8 @@ 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) - 2;
ft_print_list(clist);
close(fd);
}
diff --git a/src/ft_print_list.c b/src/ft_print_list.c
index 601a498..c459a11 100644
--- a/src/ft_print_list.c
+++ b/src/ft_print_list.c
@@ -36,5 +36,6 @@ void
i++;
}
ft_printf("Map width -- [%zu]\n", clist->map_w);
+ ft_printf("2D scale --- [%hu]\n", clist->scale);
ft_printf("----------------------\n");
}