frames keep drawing independent of keypresses

This commit is contained in:
djonker 2023-10-26 15:23:38 +02:00
parent ed426d992a
commit 4a0671fce6
14 changed files with 94 additions and 14 deletions

BIN
assets/barrel.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
assets/bluestone.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
assets/colorstone.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
assets/eagle.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
assets/greenlight.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 393 B

BIN
assets/greystone.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
assets/mossy.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
assets/pillar.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/purplestone.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
assets/redbrick.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
assets/wood.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
cub3d

Binary file not shown.

View File

@ -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/10/26 10:47:00 by houtworm ######## odam.nl */ /* Updated: 2023/10/26 13:56:49 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -5,13 +5,92 @@
/* +:+ */ /* +:+ */
/* By: houtworm <codam@houtworm.net> +#+ */ /* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2023/10/26 10:46:22 by houtworm #+# #+# */ /* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */
/* Updated: 2023/10/26 10:46:24 by houtworm ######## odam.nl */ /* Updated: 2023/10/26 15:01:26 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../cub3d.h" #include "../cub3d.h"
void ft_getnextframe(t_varlist *vl)
{
int y;
int x;
y = 1;
while (vl->h > y)
{
x = 1;
while (vl->w > x)
{
mlx_put_pixel(vl->img, x, y, 0x000000FF);
x++;
}
y++;
}
}
void framehook(void *param)
{
t_varlist *vl;
vl = param;
mlx_delete_image(vl->mlx, vl->img);
vl->img = mlx_new_image(vl->mlx, vl->w, vl->h);
ft_getnextframe(vl);
if (!vl->img || (mlx_image_to_window(vl->mlx, vl->img, 0, 0) < 0))
exit (1);
ft_putendl("frame");
}
void keyhook(mlx_key_data_t kd, void *param)
{
t_varlist *vl;
vl = param;
vl->w =vl->w;
if (mlx_is_mouse_down(vl->mlx, MLX_MOUSE_BUTTON_LEFT))
ft_putendl("shoot");
if (mlx_is_key_down(vl->mlx, MLX_KEY_ESCAPE))
{
ft_putendl("escape is pressed");
mlx_close_window(vl->mlx);
return ;
}
if (kd.key == MLX_KEY_W && kd.action == MLX_PRESS)
ft_putendl("W is pressed");
if (kd.key == MLX_KEY_A && kd.action == MLX_PRESS)
ft_putendl("A is pressed");
if (kd.key == MLX_KEY_S && kd.action == MLX_PRESS)
ft_putendl("S is pressed");
if (kd.key == MLX_KEY_D && kd.action == MLX_PRESS)
ft_putendl("D is pressed");
}
void scrollhook(double xdelta, double ydelta, void *param)
{
t_varlist *vl;
vl = param;
vl = vl;
xdelta++;
if (ydelta > 0)
ft_putendl("scroll up");
if (ydelta < 0)
ft_putendl("scroll down");
}
void resizehook(int x, int y, void *param)
{
t_varlist *vl;
vl = param;
vl->h = y;
vl->w = x;
vl->mlx->height = y;
vl->mlx->width = x;
}
t_varlist initvarlist(void) t_varlist initvarlist(void)
{ {
t_varlist vl; t_varlist vl;
@ -20,26 +99,27 @@ t_varlist initvarlist(void)
vl.h = 600; vl.h = 600;
vl.mlx = mlx_init(vl.w, vl.h, "Cub3D", true); vl.mlx = mlx_init(vl.w, vl.h, "Cub3D", true);
if (!vl.mlx) if (!vl.mlx)
exit(1); exit (1);
vl.img = mlx_new_image(vl.mlx, vl.w, vl.h); vl.img = mlx_new_image(vl.mlx, vl.w, vl.h);
return (vl); return (vl);
} }
void redrawimage(t_varlist *vl) int main(int argc, char **argv)
{
mlx_delete_image(vl->mlx, vl->img);
vl->img = mlx_new_image(vl->mlx, vl->w, vl->h);
}
int32_t main(void)
{ {
t_varlist vl; t_varlist vl;
if (argc > 2)
exit(2);
argv = argv;
vl = initvarlist(); vl = initvarlist();
if (!vl.img || (mlx_image_to_window(vl.mlx, vl.img, 0, 0) < 0)) if (!vl.img || (mlx_image_to_window(vl.mlx, vl.img, 0, 0) < 0))
exit (1); exit (1);
mlx_key_hook(vl.mlx, &keyhook, &vl);
mlx_resize_hook(vl.mlx, &resizehook, &vl);
mlx_scroll_hook(vl.mlx, &scrollhook, &vl);
mlx_loop_hook(vl.mlx, &framehook, &vl);
mlx_loop(vl.mlx); mlx_loop(vl.mlx);
mlx_delete_image(vl.mlx, vl.img); mlx_delete_image(vl.mlx, vl.img);
mlx_terminate(vl.mlx); mlx_terminate(vl.mlx);
exit (EXIT_SUCCESS); exit (0);
} }