diff --git a/Readme.md b/Readme.md index 9833a94..b7bd152 100644 --- a/Readme.md +++ b/Readme.md @@ -13,7 +13,6 @@ Cub3D is a simple raycasting game using the mlx library ### Extra - Help screen? - Levels? -- Barrels? - Collectables - Enemies? - Moving Enemies? @@ -52,6 +51,8 @@ Cub3D is a simple raycasting game using the mlx library - Map sizes up to 1 Megabyte (1000x1000) - Vertical Aiming - Fullscreen +- Barrels +- Lights --- diff --git a/cub3d.h b/cub3d.h index b0d9339..a63ba10 100644 --- a/cub3d.h +++ b/cub3d.h @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */ -/* Updated: 2023/11/04 01:53:08 by houtworm ######## odam.nl */ +/* Updated: 2023/11/04 03:13:42 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ typedef struct s_sprite { + double distance; double x; double y; int type; diff --git a/src/draw.c b/src/draw.c index a25758d..056c317 100644 --- a/src/draw.c +++ b/src/draw.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 16:54:20 by houtworm #+# #+# */ -/* Updated: 2023/11/04 02:29:31 by houtworm ######## odam.nl */ +/* Updated: 2023/11/04 03:23:55 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -33,49 +33,26 @@ mlx_texture_t *ft_selectsprite(t_varlist *vl, int type) return (sprite); } -double ft_puthighestfirst(t_varlist *vl, double *spritedistance, double oldrecord, int j) -{ - int i; - double record; - int furthest; - - i = 0; - record = 0; - furthest = 0; - while (vl->spritecount > i) - { - if (spritedistance[i] > record && spritedistance[i] < oldrecord) - { - record = spritedistance[i]; - furthest = i; - } - i++; - } - oldrecord = record; - vl->spriteorder[j] = vl->sprite[furthest]; - return (oldrecord); -} - void ft_sortsprites(t_varlist *vl) { int i; - double *spritedistance; - double oldrecord; + t_sprite temp; i = 0; - spritedistance = ft_calloc(4096, 8); - vl->spriteorder = ft_calloc(4096, 8); while (vl->spritecount > i) { - spritedistance[i] = ((vl->posx - vl->sprite[i].x) * (vl->posx - vl->sprite[i].x) + (vl->posy - vl->sprite[i].y) * (vl->posy - vl->sprite[i].y)); + vl->sprite[i].distance = pow((vl->posx - vl->sprite[i].x), 2) + pow((vl->posy - vl->sprite[i].y), 2); i++; } - i = 0; - oldrecord = 99999999999999.0; - while (vl->spritecount > i) + while (i) { - oldrecord = ft_puthighestfirst(vl, spritedistance, oldrecord, i); - i++; + if (vl->sprite[i].distance > vl->sprite[i - 1].distance) + { + temp = vl->sprite[i]; + vl->sprite[i] = vl->sprite[i - 1]; + vl->sprite[i - 1] = temp; + } + i--; } } @@ -107,9 +84,9 @@ void ft_drawsprites(t_varlist *vl) ft_sortsprites(vl); while (vl->spritecount > i) { - spritex = vl->spriteorder[i].x - vl->posx; - spritey = vl->spriteorder[i].y - vl->posy; - sprite = ft_selectsprite(vl, vl->spriteorder[i].type); + spritex = vl->sprite[i].x - vl->posx; + spritey = vl->sprite[i].y - vl->posy; + sprite = ft_selectsprite(vl, vl->sprite[i].type); invdet = 1.0 / (vl->planex * vl->diry - vl->dirx * vl->planey); transformx = invdet * (vl->diry * spritex - vl->dirx * spritey); transformy = invdet * (-vl->planey * spritex + vl->planex * spritey); diff --git a/src/init.c b/src/init.c index 54766df..8eb32fa 100644 --- a/src/init.c +++ b/src/init.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */ -/* Updated: 2023/11/04 01:52:30 by houtworm ######## odam.nl */ +/* Updated: 2023/11/04 03:31:53 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/map.c b/src/map.c index c3ed81a..a5a0d4f 100644 --- a/src/map.c +++ b/src/map.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */ -/* Updated: 2023/11/04 02:34:10 by houtworm ######## odam.nl */ +/* Updated: 2023/11/04 02:39:42 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -92,7 +92,6 @@ char **ft_getmap(t_varlist *vl, int fd) if (ret == 0) { free(map[y]); - /*free(line);*/ return (map); } x = 0;