jumping and crouching works fine now

This commit is contained in:
djonker 2023-11-05 03:22:41 +01:00
parent 8ff76fe2e5
commit 37b31d1e70
5 changed files with 24 additions and 18 deletions

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */
/* Updated: 2023/11/04 04:36:12 by houtworm ######## odam.nl */
/* Updated: 2023/11/05 02:59:11 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -62,7 +62,8 @@ typedef struct s_varlist
double planey;
double camerax;
double cameray;
int hoffset;
int vaim;
int jump;
double raydirx;
double raydiry;
double movespeed;

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 16:54:20 by houtworm #+# #+# */
/* Updated: 2023/11/04 05:33:09 by houtworm ######## odam.nl */
/* Updated: 2023/11/05 03:05:46 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -90,7 +90,7 @@ void ft_drawsprites(t_varlist *vl)
transformx = invdet * (vl->diry * spritex - vl->dirx * spritey);
transformy = invdet * (-vl->planey * spritex + vl->planex * spritey);
spritescreenx = (vl->w / 2) * (1 + transformx / transformy);
vmovescreen = vl->hoffset + 0 / transformy;
vmovescreen = vl->vaim + vl->jump / transformy;
spriteheight = fabs((vl->h / transformy));
drawstarty = -spriteheight / 2 + vl->h / 2 + vmovescreen;
if (drawstarty < 0)
@ -182,7 +182,7 @@ void ft_drawline(int x, t_varlist *vl, int drawstart, int drawend)
double step;
step = 64.0 / vl->lineheight;
double textpos;
textpos = (drawstart - vl->hoffset - vl->h / 2 + vl->lineheight / 2) * step;
textpos = (drawstart - vl->vaim - (vl->jump / vl->perpwalldist) - vl->h / 2 + vl->lineheight / 2) * step;
while (y < drawend)
{
int texty;

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */
/* Updated: 2023/11/04 04:08:23 by houtworm ######## odam.nl */
/* Updated: 2023/11/05 02:59:50 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -21,7 +21,8 @@ t_varlist initvarlist(void)
vl.sprite = ft_calloc(4096, 8);
vl.zbuffer = ft_calloc(4096, 8);
vl.spritecount = 0;
vl.hoffset = 0;
vl.vaim = 0;
vl.jump = 0;
vl.treasure = 0;
vl.tottreasure = 0;
vl.enemies = 0;

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */
/* Updated: 2023/11/04 03:51:16 by houtworm ######## odam.nl */
/* Updated: 2023/11/05 03:15:39 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -23,10 +23,14 @@ void ft_movementkeys(t_varlist *vl)
distance = vl->sidedistx - vl->deltadistx;
if (mlx_is_mouse_down(vl->mlx, MLX_MOUSE_BUTTON_LEFT))
ft_putendl("shoot");
if (mlx_is_key_down(vl->mlx, MLX_KEY_SPACE))
ft_putendl("jump");
if (mlx_is_key_down(vl->mlx, MLX_KEY_SPACE) && vl->jump < 10)
vl->jump = 200;
else if (vl->jump > 0)
vl->jump = vl->jump - 150 * vl->movespeed;
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT_CONTROL))
ft_putendl("crouch");
vl->jump = -200;
else if (vl->jump < 0)
vl->jump = vl->jump + 150 * vl->movespeed;
if (mlx_is_key_down(vl->mlx, MLX_KEY_W))
{
if (vl->map[(int)(vl->posx + vl->dirx * vl->movespeed)][(int)vl->posy] == '0' && distance > 0.4)
@ -163,11 +167,11 @@ void cursorhook(double xpos, double ypos, void *param)
}
vl->oldmouseposx = xpos;
if (ypos < vl->oldmouseposy)
if (vl->hoffset < 300)
vl->hoffset = vl->hoffset + 3;
if (vl->vaim < 300)
vl->vaim = vl->vaim + 3;
if (ypos > vl->oldmouseposy)
if (vl->hoffset > -300)
vl->hoffset = vl->hoffset - 3;
if (vl->vaim > -300)
vl->vaim = vl->vaim - 3;
vl->oldmouseposy = ypos;
}

View File

@ -6,7 +6,7 @@
/* By: djonker <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/27 14:36:42 by djonker #+# #+# */
/* Updated: 2023/11/04 00:09:58 by houtworm ######## odam.nl */
/* Updated: 2023/11/05 03:03:31 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -71,10 +71,10 @@ void ft_raycast(t_varlist *vl)
else
vl->perpwalldist = (vl->sidedisty - vl->deltadisty);
vl->lineheight = vl->h / vl->perpwalldist;
drawstart = -vl->lineheight / 2 + vl->h / 2 + vl->hoffset;
drawstart = -vl->lineheight / 2 + vl->h / 2 + vl->vaim + (vl->jump / vl->perpwalldist);
if (drawstart < 0)
drawstart = 0;
drawend = vl->lineheight / 2 + vl->h / 2 + vl->hoffset;
drawend = vl->lineheight / 2 + vl->h / 2 + vl->vaim + (vl->jump / vl->perpwalldist);
if (drawend >= vl->h)
drawend = vl->h - 1;
ft_drawline(x, vl, drawstart, drawend);