sprites can be walk trough or solid

This commit is contained in:
djonker 2023-11-04 03:34:03 +01:00
parent 8eb0f6c5ea
commit 89583cb8e8
5 changed files with 20 additions and 42 deletions

View File

@ -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
---

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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;

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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);

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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;