added vertical aiming
This commit is contained in:
parent
598dfa0672
commit
495ba620af
4
Makefile
4
Makefile
@ -6,13 +6,13 @@
|
||||
# By: houtworm <codam@houtworm.net> +#+ #
|
||||
# +#+ #
|
||||
# Created: 2023/10/26 10:46:29 by houtworm #+# #+# #
|
||||
# Updated: 2023/11/01 14:59:05 by houtworm ######## odam.nl #
|
||||
# Updated: 2023/11/02 04:04:36 by houtworm ######## odam.nl #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME =cub3d
|
||||
CC =gcc
|
||||
FC =-Wall -Werror -Wextra -Wunreachable-code -Ofast -g -fsanitize=address
|
||||
FC =-Wall -Werror -Wextra -Wunreachable-code -Ofast -g #-fsanitize=address
|
||||
HEAD =-I ./include -I $(MLX)/include
|
||||
RM =rm -rf
|
||||
LIB =libft/libft.a getnextline/get_next_line.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm
|
||||
|
@ -25,7 +25,6 @@ Cub3D is a simple raycasting game using the mlx library
|
||||
- A Start Menu?
|
||||
- Jumping?
|
||||
- Crouching?
|
||||
- Vertical Aiming?
|
||||
|
||||
---
|
||||
## Features
|
||||
@ -46,6 +45,7 @@ Cub3D is a simple raycasting game using the mlx library
|
||||
- Player can walk in 8 directions
|
||||
- Player can Run
|
||||
- Map sizes up to 1 Megabyte (1000x1000)
|
||||
- Vertical Aiming
|
||||
|
||||
---
|
||||
## Bugs
|
||||
|
3
cub3d.h
3
cub3d.h
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */
|
||||
/* Updated: 2023/11/01 15:42:29 by houtworm ######## odam.nl */
|
||||
/* Updated: 2023/11/02 04:18:39 by houtworm ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -64,6 +64,7 @@ typedef struct s_varlist
|
||||
int side;
|
||||
double run;
|
||||
double oldmouseposx;
|
||||
double oldmouseposy;
|
||||
int32_t fcolor;
|
||||
int32_t ccolor;
|
||||
int resize;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */
|
||||
/* Updated: 2023/11/01 21:41:55 by houtworm ######## odam.nl */
|
||||
/* Updated: 2023/11/02 04:28:53 by houtworm ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,7 +18,7 @@ t_varlist initvarlist(void)
|
||||
|
||||
vl.w = 800;
|
||||
vl.h = 600;
|
||||
vl.hoffset = 50;
|
||||
vl.hoffset = 0;
|
||||
vl.ccolor = 0;
|
||||
vl.fcolor = 0;
|
||||
vl.northtext = NULL;
|
||||
|
40
src/keys.c
40
src/keys.c
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */
|
||||
/* Updated: 2023/11/02 02:21:54 by houtworm ######## odam.nl */
|
||||
/* Updated: 2023/11/02 04:25:38 by houtworm ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,8 +14,7 @@
|
||||
|
||||
void ft_movementkeys(t_varlist *vl)
|
||||
{
|
||||
double olddirx;
|
||||
double oldplanex;
|
||||
double temp;
|
||||
double distance;
|
||||
|
||||
if (vl->side)
|
||||
@ -27,9 +26,7 @@ void ft_movementkeys(t_varlist *vl)
|
||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_SPACE))
|
||||
ft_putendl("jump");
|
||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT_CONTROL))
|
||||
vl->hoffset = 0;
|
||||
else
|
||||
vl->hoffset = 50;
|
||||
ft_putendl("crouch");
|
||||
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)
|
||||
@ -84,21 +81,21 @@ void ft_movementkeys(t_varlist *vl)
|
||||
}
|
||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT))
|
||||
{
|
||||
olddirx = vl->dirx;
|
||||
vl->dirx = vl->dirx * cos(vl->rotspeed) - vl->diry * sin(vl->rotspeed);
|
||||
vl->diry = olddirx * sin(vl->rotspeed) + vl->diry * cos(vl->rotspeed);
|
||||
oldplanex = vl->planex;
|
||||
vl->planex = vl->planex * cos(vl->rotspeed) - vl->planey * sin(vl->rotspeed);
|
||||
vl->planey = oldplanex * sin(vl->rotspeed) + vl->planey * cos(vl->rotspeed);
|
||||
temp = vl->dirx;
|
||||
vl->dirx = temp * cos(vl->rotspeed) - vl->diry * sin(vl->rotspeed);
|
||||
vl->diry = temp * sin(vl->rotspeed) + vl->diry * cos(vl->rotspeed);
|
||||
temp = vl->planex;
|
||||
vl->planex = temp * cos(vl->rotspeed) - vl->planey * sin(vl->rotspeed);
|
||||
vl->planey = temp * sin(vl->rotspeed) + vl->planey * cos(vl->rotspeed);
|
||||
}
|
||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_RIGHT))
|
||||
{
|
||||
olddirx = vl->dirx;
|
||||
vl->dirx = vl->dirx * cos(-vl->rotspeed) - vl->diry * sin(-vl->rotspeed);
|
||||
vl->diry = olddirx * sin(-vl->rotspeed) + vl->diry * cos(-vl->rotspeed);
|
||||
oldplanex = vl->planex;
|
||||
vl->planex = vl->planex * cos(-vl->rotspeed) - vl->planey * sin(-vl->rotspeed);
|
||||
vl->planey = oldplanex * sin(-vl->rotspeed) + vl->planey * cos(-vl->rotspeed);
|
||||
temp = vl->dirx;
|
||||
vl->dirx = temp * cos(-vl->rotspeed) - vl->diry * sin(-vl->rotspeed);
|
||||
vl->diry = temp * sin(-vl->rotspeed) + vl->diry * cos(-vl->rotspeed);
|
||||
temp = vl->planex;
|
||||
vl->planex = temp * cos(-vl->rotspeed) - vl->planey * sin(-vl->rotspeed);
|
||||
vl->planey = temp * sin(-vl->rotspeed) + vl->planey * cos(-vl->rotspeed);
|
||||
}
|
||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT_SHIFT))
|
||||
vl->run = 2;
|
||||
@ -165,6 +162,13 @@ void cursorhook(double xpos, double ypos, void *param)
|
||||
vl->planey = oldplanex * sin(-speed) + vl->planey * cos(-speed);
|
||||
}
|
||||
vl->oldmouseposx = xpos;
|
||||
if (ypos < vl->oldmouseposy)
|
||||
if (vl->hoffset < 300)
|
||||
vl->hoffset = vl->hoffset + 3;
|
||||
if (ypos > vl->oldmouseposy)
|
||||
if (vl->hoffset > -300)
|
||||
vl->hoffset = vl->hoffset - 3;
|
||||
vl->oldmouseposy = ypos;
|
||||
}
|
||||
|
||||
void resizehook(int x, int y, void *param)
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */
|
||||
/* Updated: 2023/11/01 15:42:14 by houtworm ######## odam.nl */
|
||||
/* Updated: 2023/11/02 03:57:40 by houtworm ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,7 +20,6 @@ void ft_frametime(t_varlist *vl)
|
||||
vl->frametime = vl->mlx->delta_time;
|
||||
vl->movespeed = vl->frametime * 3.0;
|
||||
vl->rotspeed = vl->frametime * 3.0;
|
||||
mlx_delete_image(vl->mlx, vl->fps);
|
||||
itoa = ft_itoa(1 / vl->frametime);
|
||||
print = ft_strjoin(itoa, " FPS");
|
||||
vl->fps = mlx_put_string(vl->mlx, print, 10, 10);
|
||||
@ -34,6 +33,7 @@ void mainloop(void *param)
|
||||
|
||||
vl = param;
|
||||
mlx_delete_image(vl->mlx, vl->img);
|
||||
mlx_delete_image(vl->mlx, vl->fps);
|
||||
vl->img = mlx_new_image(vl->mlx, vl->w, vl->h);
|
||||
ft_raycast(vl);
|
||||
ft_frametime(vl);
|
||||
@ -68,6 +68,7 @@ int main(int argc, char **argv)
|
||||
mlx_delete_texture(vl.southtext);
|
||||
mlx_delete_texture(vl.westtext);
|
||||
mlx_delete_texture(vl.barreltext);
|
||||
mlx_delete_image(vl.mlx, vl.fps);
|
||||
mlx_delete_image(vl.mlx, vl.img);
|
||||
mlx_terminate(vl.mlx);
|
||||
exit (0);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */
|
||||
/* Updated: 2023/10/29 19:30:54 by houtworm ######## odam.nl */
|
||||
/* Updated: 2023/11/02 03:56:15 by houtworm ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -69,11 +69,12 @@ char **ft_getmap(t_varlist *vl, int fd)
|
||||
ret = get_next_line(fd, &line);
|
||||
if (line[0])
|
||||
break ;
|
||||
free(line);
|
||||
}
|
||||
if (ret == 0)
|
||||
{
|
||||
free(map[y]);
|
||||
free(line);
|
||||
/*free(line);*/
|
||||
return (map);
|
||||
}
|
||||
x = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user