little cleanup

This commit is contained in:
djonker 2023-11-05 07:01:49 +01:00
parent 2ea2c8b89a
commit b4f01a697a
2 changed files with 25 additions and 10 deletions

View File

@ -6,7 +6,7 @@
# By: houtworm <codam@houtworm.net> +#+ # # By: houtworm <codam@houtworm.net> +#+ #
# +#+ # # +#+ #
# Created: 2023/10/26 10:46:29 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/turn.c\
src/input/rest.c\ src/input/rest.c\
src/parse/parse.c\ src/parse/parse.c\
src/sprite/draw.c\
src/parse/map.c src/parse/map.c
OBJ =$(SRC:src/%.c=obj/%.o) OBJ =$(SRC:src/%.c=obj/%.o)

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */ /* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2023/10/26 16:54:20 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; 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); mlx_put_pixel(vl->img, x, y, vl->ccolor);
y++; y++;
} }
return (y);
}
int ft_drawwall(int x, t_varlist *vl, int drawstart, int drawend, int y)
{
double wallx; double wallx;
int textx;
double step;
double textpos;
int texty;
uint8_t *texel;
uint32_t color;
if (vl->side == 0) if (vl->side == 0)
wallx = vl->posy + vl->walldist * vl->raydiry; wallx = vl->posy + vl->walldist * vl->raydiry;
else else
wallx = vl->posx + vl->walldist * vl->raydirx; wallx = vl->posx + vl->walldist * vl->raydirx;
ft_selecttexture(vl); ft_selecttexture(vl);
wallx -= floor(wallx); wallx -= floor(wallx);
int textx;
textx = wallx * 64.0; textx = wallx * 64.0;
if (vl->side == 0 && vl->raydirx > 0) if (vl->side == 0 && vl->raydirx > 0)
textx = 64 - textx - 1; textx = 64 - textx - 1;
if (vl->side == 1 && vl->raydiry < 0) if (vl->side == 1 && vl->raydiry < 0)
textx = 64 - textx - 1; textx = 64 - textx - 1;
double step;
step = 64.0 / vl->lineheight; step = 64.0 / vl->lineheight;
double textpos;
textpos = (drawstart - vl->vaim - (vl->jump / vl->walldist) - vl->h / 2 + vl->lineheight / 2) * step; textpos = (drawstart - vl->vaim - (vl->jump / vl->walldist) - vl->h / 2 + vl->lineheight / 2) * step;
while (y < drawend) while (y < drawend)
{ {
int texty;
texty = (int)textpos & (64 - 1); texty = (int)textpos & (64 - 1);
textpos += step; textpos += step;
uint8_t *texel;
uint32_t color;
texel = &vl->curtext->pixels[(vl->curtext->width * texty + textx) * 4]; texel = &vl->curtext->pixels[(vl->curtext->width * texty + textx) * 4];
color = texel[0] << 24 | texel[1] << 16 | texel[2] << 8 | texel[3]; color = texel[0] << 24 | texel[1] << 16 | texel[2] << 8 | texel[3];
mlx_put_pixel(vl->img, x, y, color); mlx_put_pixel(vl->img, x, y, color);
y++; y++;
} }
return (y);
}
void ft_drawfloor(int x, t_varlist *vl, int y)
{
while (vl->h > y) while (vl->h > y)
{ {
mlx_put_pixel(vl->img, x, y, vl->fcolor); 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) void ft_drawmap(t_varlist *vl)
{ {
int x; int x;
int y;
int mapx; int mapx;
int mapy; int mapy;
@ -107,7 +119,9 @@ void ft_drawmap(t_varlist *vl)
while (x <= vl->w) while (x <= vl->w)
{ {
ft_raycast(vl, x, mapx, mapy); 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) if (vl->side == 0)
vl->walldist = (vl->sidedistx - vl->deltadistx); vl->walldist = (vl->sidedistx - vl->deltadistx);
else else