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> +#+ #
|
# 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/01 14:59:05 by houtworm ######## odam.nl #
|
# Updated: 2023/11/02 04:04:36 by houtworm ######## odam.nl #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
NAME =cub3d
|
NAME =cub3d
|
||||||
CC =gcc
|
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
|
HEAD =-I ./include -I $(MLX)/include
|
||||||
RM =rm -rf
|
RM =rm -rf
|
||||||
LIB =libft/libft.a getnextline/get_next_line.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm
|
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?
|
- A Start Menu?
|
||||||
- Jumping?
|
- Jumping?
|
||||||
- Crouching?
|
- Crouching?
|
||||||
- Vertical Aiming?
|
|
||||||
|
|
||||||
---
|
---
|
||||||
## Features
|
## Features
|
||||||
@ -46,6 +45,7 @@ Cub3D is a simple raycasting game using the mlx library
|
|||||||
- Player can walk in 8 directions
|
- Player can walk in 8 directions
|
||||||
- Player can Run
|
- Player can Run
|
||||||
- Map sizes up to 1 Megabyte (1000x1000)
|
- Map sizes up to 1 Megabyte (1000x1000)
|
||||||
|
- Vertical Aiming
|
||||||
|
|
||||||
---
|
---
|
||||||
## Bugs
|
## Bugs
|
||||||
|
3
cub3d.h
3
cub3d.h
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */
|
/* 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;
|
int side;
|
||||||
double run;
|
double run;
|
||||||
double oldmouseposx;
|
double oldmouseposx;
|
||||||
|
double oldmouseposy;
|
||||||
int32_t fcolor;
|
int32_t fcolor;
|
||||||
int32_t ccolor;
|
int32_t ccolor;
|
||||||
int resize;
|
int resize;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */
|
/* 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.w = 800;
|
||||||
vl.h = 600;
|
vl.h = 600;
|
||||||
vl.hoffset = 50;
|
vl.hoffset = 0;
|
||||||
vl.ccolor = 0;
|
vl.ccolor = 0;
|
||||||
vl.fcolor = 0;
|
vl.fcolor = 0;
|
||||||
vl.northtext = NULL;
|
vl.northtext = NULL;
|
||||||
|
40
src/keys.c
40
src/keys.c
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */
|
/* 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)
|
void ft_movementkeys(t_varlist *vl)
|
||||||
{
|
{
|
||||||
double olddirx;
|
double temp;
|
||||||
double oldplanex;
|
|
||||||
double distance;
|
double distance;
|
||||||
|
|
||||||
if (vl->side)
|
if (vl->side)
|
||||||
@ -27,9 +26,7 @@ void ft_movementkeys(t_varlist *vl)
|
|||||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_SPACE))
|
if (mlx_is_key_down(vl->mlx, MLX_KEY_SPACE))
|
||||||
ft_putendl("jump");
|
ft_putendl("jump");
|
||||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT_CONTROL))
|
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT_CONTROL))
|
||||||
vl->hoffset = 0;
|
ft_putendl("crouch");
|
||||||
else
|
|
||||||
vl->hoffset = 50;
|
|
||||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_W))
|
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)
|
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))
|
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT))
|
||||||
{
|
{
|
||||||
olddirx = vl->dirx;
|
temp = vl->dirx;
|
||||||
vl->dirx = vl->dirx * cos(vl->rotspeed) - vl->diry * sin(vl->rotspeed);
|
vl->dirx = temp * cos(vl->rotspeed) - vl->diry * sin(vl->rotspeed);
|
||||||
vl->diry = olddirx * sin(vl->rotspeed) + vl->diry * cos(vl->rotspeed);
|
vl->diry = temp * sin(vl->rotspeed) + vl->diry * cos(vl->rotspeed);
|
||||||
oldplanex = vl->planex;
|
temp = vl->planex;
|
||||||
vl->planex = vl->planex * cos(vl->rotspeed) - vl->planey * sin(vl->rotspeed);
|
vl->planex = temp * cos(vl->rotspeed) - vl->planey * sin(vl->rotspeed);
|
||||||
vl->planey = oldplanex * sin(vl->rotspeed) + vl->planey * cos(vl->rotspeed);
|
vl->planey = temp * sin(vl->rotspeed) + vl->planey * cos(vl->rotspeed);
|
||||||
}
|
}
|
||||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_RIGHT))
|
if (mlx_is_key_down(vl->mlx, MLX_KEY_RIGHT))
|
||||||
{
|
{
|
||||||
olddirx = vl->dirx;
|
temp = vl->dirx;
|
||||||
vl->dirx = vl->dirx * cos(-vl->rotspeed) - vl->diry * sin(-vl->rotspeed);
|
vl->dirx = temp * cos(-vl->rotspeed) - vl->diry * sin(-vl->rotspeed);
|
||||||
vl->diry = olddirx * sin(-vl->rotspeed) + vl->diry * cos(-vl->rotspeed);
|
vl->diry = temp * sin(-vl->rotspeed) + vl->diry * cos(-vl->rotspeed);
|
||||||
oldplanex = vl->planex;
|
temp = vl->planex;
|
||||||
vl->planex = vl->planex * cos(-vl->rotspeed) - vl->planey * sin(-vl->rotspeed);
|
vl->planex = temp * cos(-vl->rotspeed) - vl->planey * sin(-vl->rotspeed);
|
||||||
vl->planey = oldplanex * sin(-vl->rotspeed) + vl->planey * cos(-vl->rotspeed);
|
vl->planey = temp * sin(-vl->rotspeed) + vl->planey * cos(-vl->rotspeed);
|
||||||
}
|
}
|
||||||
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT_SHIFT))
|
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT_SHIFT))
|
||||||
vl->run = 2;
|
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->planey = oldplanex * sin(-speed) + vl->planey * cos(-speed);
|
||||||
}
|
}
|
||||||
vl->oldmouseposx = xpos;
|
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)
|
void resizehook(int x, int y, void *param)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */
|
/* 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->frametime = vl->mlx->delta_time;
|
||||||
vl->movespeed = vl->frametime * 3.0;
|
vl->movespeed = vl->frametime * 3.0;
|
||||||
vl->rotspeed = vl->frametime * 3.0;
|
vl->rotspeed = vl->frametime * 3.0;
|
||||||
mlx_delete_image(vl->mlx, vl->fps);
|
|
||||||
itoa = ft_itoa(1 / vl->frametime);
|
itoa = ft_itoa(1 / vl->frametime);
|
||||||
print = ft_strjoin(itoa, " FPS");
|
print = ft_strjoin(itoa, " FPS");
|
||||||
vl->fps = mlx_put_string(vl->mlx, print, 10, 10);
|
vl->fps = mlx_put_string(vl->mlx, print, 10, 10);
|
||||||
@ -34,6 +33,7 @@ void mainloop(void *param)
|
|||||||
|
|
||||||
vl = param;
|
vl = param;
|
||||||
mlx_delete_image(vl->mlx, vl->img);
|
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);
|
vl->img = mlx_new_image(vl->mlx, vl->w, vl->h);
|
||||||
ft_raycast(vl);
|
ft_raycast(vl);
|
||||||
ft_frametime(vl);
|
ft_frametime(vl);
|
||||||
@ -68,6 +68,7 @@ int main(int argc, char **argv)
|
|||||||
mlx_delete_texture(vl.southtext);
|
mlx_delete_texture(vl.southtext);
|
||||||
mlx_delete_texture(vl.westtext);
|
mlx_delete_texture(vl.westtext);
|
||||||
mlx_delete_texture(vl.barreltext);
|
mlx_delete_texture(vl.barreltext);
|
||||||
|
mlx_delete_image(vl.mlx, vl.fps);
|
||||||
mlx_delete_image(vl.mlx, vl.img);
|
mlx_delete_image(vl.mlx, vl.img);
|
||||||
mlx_terminate(vl.mlx);
|
mlx_terminate(vl.mlx);
|
||||||
exit (0);
|
exit (0);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */
|
/* 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);
|
ret = get_next_line(fd, &line);
|
||||||
if (line[0])
|
if (line[0])
|
||||||
break ;
|
break ;
|
||||||
|
free(line);
|
||||||
}
|
}
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
free(map[y]);
|
free(map[y]);
|
||||||
free(line);
|
/*free(line);*/
|
||||||
return (map);
|
return (map);
|
||||||
}
|
}
|
||||||
x = 0;
|
x = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user