diff --git a/Makefile b/Makefile index dabe242..6504b8a 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: houtworm +#+ # # +#+ # # Created: 2023/10/26 10:46:29 by houtworm #+# #+# # -# Updated: 2023/11/05 05:18:12 by houtworm ######## odam.nl # +# Updated: 2023/11/05 06:56:35 by houtworm ######## odam.nl # # # # **************************************************************************** # @@ -26,6 +26,7 @@ SRC =src/main/main.c\ src/input/turn.c\ src/input/rest.c\ src/parse/parse.c\ + src/sprite/draw.c\ src/parse/map.c OBJ =$(SRC:src/%.c=obj/%.o) diff --git a/src/draw/draw.c b/src/draw/draw.c index 5001f58..5faff1a 100644 --- a/src/draw/draw.c +++ b/src/draw/draw.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 16:54:20 by houtworm #+# #+# */ -/* Updated: 2023/11/05 06:46:26 by houtworm ######## odam.nl */ +/* Updated: 2023/11/05 06:59:29 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ void ft_selecttexture(t_varlist *vl) } } -void ft_drawline(int x, t_varlist *vl, int drawstart, int drawend) +int ft_drawceiling(int x, t_varlist *vl, int drawstart) { int y; @@ -40,35 +40,46 @@ void ft_drawline(int x, t_varlist *vl, int drawstart, int drawend) mlx_put_pixel(vl->img, x, y, vl->ccolor); y++; } + return (y); +} + +int ft_drawwall(int x, t_varlist *vl, int drawstart, int drawend, int y) +{ double wallx; + int textx; + double step; + double textpos; + int texty; + uint8_t *texel; + uint32_t color; + if (vl->side == 0) wallx = vl->posy + vl->walldist * vl->raydiry; else wallx = vl->posx + vl->walldist * vl->raydirx; ft_selecttexture(vl); wallx -= floor(wallx); - int textx; textx = wallx * 64.0; if (vl->side == 0 && vl->raydirx > 0) textx = 64 - textx - 1; if (vl->side == 1 && vl->raydiry < 0) textx = 64 - textx - 1; - double step; step = 64.0 / vl->lineheight; - double textpos; textpos = (drawstart - vl->vaim - (vl->jump / vl->walldist) - vl->h / 2 + vl->lineheight / 2) * step; while (y < drawend) { - int texty; texty = (int)textpos & (64 - 1); textpos += step; - uint8_t *texel; - uint32_t color; texel = &vl->curtext->pixels[(vl->curtext->width * texty + textx) * 4]; color = texel[0] << 24 | texel[1] << 16 | texel[2] << 8 | texel[3]; mlx_put_pixel(vl->img, x, y, color); y++; } + return (y); +} + +void ft_drawfloor(int x, t_varlist *vl, int y) +{ while (vl->h > y) { mlx_put_pixel(vl->img, x, y, vl->fcolor); @@ -98,6 +109,7 @@ int ft_getwallheight(t_varlist *vl, int mode) void ft_drawmap(t_varlist *vl) { int x; + int y; int mapx; int mapy; @@ -107,7 +119,9 @@ void ft_drawmap(t_varlist *vl) while (x <= vl->w) { ft_raycast(vl, x, mapx, mapy); - ft_drawline(x, vl, ft_getwallheight(vl, 1), ft_getwallheight(vl, 2)); + y = ft_drawceiling(x, vl, ft_getwallheight(vl, 1)); + y = ft_drawwall(x, vl, ft_getwallheight(vl, 1), ft_getwallheight(vl, 2), y); + ft_drawfloor(x, vl, y); if (vl->side == 0) vl->walldist = (vl->sidedistx - vl->deltadistx); else