animations run on a timer

This commit is contained in:
djonker 2023-11-06 00:57:40 +01:00
parent b3a3e18063
commit 819642bc90
6 changed files with 62 additions and 40 deletions

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/11/05 23:27:12 by houtworm ######## odam.nl */ /* Updated: 2023/11/06 00:37:18 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -52,6 +52,7 @@ typedef struct s_varlist
mlx_image_t *img; mlx_image_t *img;
mlx_image_t *fstat; mlx_image_t *fstat;
mlx_image_t *tstat; mlx_image_t *tstat;
mlx_image_t *cstat;
mlx_image_t *kstat; mlx_image_t *kstat;
mlx_image_t *wimg; mlx_image_t *wimg;
mlx_texture_t *temptext; mlx_texture_t *temptext;
@ -94,6 +95,9 @@ typedef struct s_varlist
int *distance; int *distance;
int treasure; int treasure;
int tottreasure; int tottreasure;
int tottime;
double anitime;
double firetime;
int enemies; int enemies;
int kills; int kills;
int mgun; int mgun;

View File

@ -12,7 +12,7 @@ WE ./assets/wall/wood.png
1 1V A A 1 1 ] 1 1 1 1 1V A A 1 1 ] 1 1 1
1 11111111111 11111111111 111111111111111111111 1 1111111111 1111111111 1 11111111111 11111111111 111111111111111111111 1 1111111111 1111111111
1 1B f $ f B1 1 1 1 17 1 D KC K 1 1 1 1B f $ f B1 1 1 1 17 1 D KC K 1 1
1 1 Kl T lK 1 1s K l K D 1 9&9 1 K l K D l 1 91 K K K K K K K K 1 1 14Kl T lK 1 1s K l K D 1 9&9 1 K l K D l 1 91 K K K K K K K K 1
1 13 8 8 21 1 1 1 C 17 1 1111111111 K K K K K K 1 1 13 8 8 21 1 1 1 C 17 1 1111111111 K K K K K K 1
1 11111 11111 11111111111 D K T K 11111111111 1 1 K K K K 1 1 11111 11111 11111111111 D K T K 11111111111 1 1 K K K K 1
1 A A 1 1 1 K K 1 1 D Kl K 1 K K 1 1 A A 1 1 1 K K 1 1 D Kl K 1 K K 1

View File

@ -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/05 07:56:06 by houtworm ######## odam.nl */ /* Updated: 2023/11/06 00:21:45 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,7 +25,7 @@ void ft_printstats(t_varlist *vl)
total = ft_itoa(vl->enemies); total = ft_itoa(vl->enemies);
current = ft_itoa(vl->kills); current = ft_itoa(vl->kills);
temp = ft_vastrjoin(4, "Kills: ", current, "/", total); temp = ft_vastrjoin(4, "Kills: ", current, "/", total);
vl->tstat = mlx_put_string(vl->mlx, temp, 10, 30); vl->cstat = mlx_put_string(vl->mlx, temp, 10, 30);
ft_vafree(3, temp, total, current); ft_vafree(3, temp, total, current);
total = ft_itoa(vl->tottreasure); total = ft_itoa(vl->tottreasure);
current = ft_itoa(vl->treasure); current = ft_itoa(vl->treasure);
@ -33,6 +33,6 @@ void ft_printstats(t_varlist *vl)
vl->kstat = mlx_put_string(vl->mlx, temp, 10, 50); vl->kstat = mlx_put_string(vl->mlx, temp, 10, 50);
ft_vafree(3, temp, total, current); ft_vafree(3, temp, total, current);
mlx_set_instance_depth(vl->fstat->instances, 2); mlx_set_instance_depth(vl->fstat->instances, 2);
mlx_set_instance_depth(vl->tstat->instances, 3); mlx_set_instance_depth(vl->cstat->instances, 3);
mlx_set_instance_depth(vl->kstat->instances, 4); mlx_set_instance_depth(vl->kstat->instances, 4);
} }

View File

@ -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/05 23:53:12 by houtworm ######## odam.nl */ /* Updated: 2023/11/06 00:52:07 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -30,34 +30,10 @@ void ft_processacro(t_varlist *vl, double movespeed)
void ft_processguns(t_varlist *vl) void ft_processguns(t_varlist *vl)
{ {
if (vl->reload == 4)
{
vl->reload = 0;
ft_putendl("recovered");
}
if (vl->reload == 3)
{
vl->reload = 4;
ft_putendl("recover");
}
if (vl->reload == 2)
{
vl->reload = 3;
ft_putendl("shoot");
}
if (vl->reload == 1)
{
vl->reload = 2;
ft_putendl("aim");
}
if (mlx_is_mouse_down(vl->mlx, MLX_MOUSE_BUTTON_LEFT) && vl->reload == 0) if (mlx_is_mouse_down(vl->mlx, MLX_MOUSE_BUTTON_LEFT) && vl->reload == 0)
{ {
vl->anitime = vl->frametime;
vl->reload = 1; vl->reload = 1;
ft_putendl("ready");
} }
if (mlx_is_mouse_down(vl->mlx, MLX_MOUSE_BUTTON_RIGHT)) if (mlx_is_mouse_down(vl->mlx, MLX_MOUSE_BUTTON_RIGHT))
ft_putendl("zoom"); ft_putendl("zoom");

View File

@ -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/05 22:29:03 by houtworm ######## odam.nl */ /* Updated: 2023/11/06 00:53:16 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -73,11 +73,11 @@ void ft_initweapons(t_varlist *vl)
vl->gun2text[3] = mlx_load_png("./assets/weapon/mgun/4.png"); vl->gun2text[3] = mlx_load_png("./assets/weapon/mgun/4.png");
vl->gun2text[4] = mlx_load_png("./assets/weapon/mgun/5.png"); vl->gun2text[4] = mlx_load_png("./assets/weapon/mgun/5.png");
vl->gun3text = ft_calloc(4096, 8); vl->gun3text = ft_calloc(4096, 8);
vl->gun3text[0] = mlx_load_png("./assets/weapon/mgun/1.png"); vl->gun3text[0] = mlx_load_png("./assets/weapon/ggun/1.png");
vl->gun3text[1] = mlx_load_png("./assets/weapon/mgun/2.png"); vl->gun3text[1] = mlx_load_png("./assets/weapon/ggun/2.png");
vl->gun3text[2] = mlx_load_png("./assets/weapon/mgun/3.png"); vl->gun3text[2] = mlx_load_png("./assets/weapon/ggun/3.png");
vl->gun3text[3] = mlx_load_png("./assets/weapon/mgun/4.png"); vl->gun3text[3] = mlx_load_png("./assets/weapon/ggun/4.png");
vl->gun3text[4] = mlx_load_png("./assets/weapon/mgun/5.png"); vl->gun3text[4] = mlx_load_png("./assets/weapon/ggun/5.png");
} }
void ft_initmainstuff(t_varlist *vl) void ft_initmainstuff(t_varlist *vl)

View File

@ -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/05 23:41:31 by houtworm ######## odam.nl */ /* Updated: 2023/11/06 00:49:31 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,6 +16,7 @@ void ft_replaceimage(t_varlist *vl)
{ {
mlx_delete_image(vl->mlx, vl->img); mlx_delete_image(vl->mlx, vl->img);
mlx_delete_image(vl->mlx, vl->fstat); mlx_delete_image(vl->mlx, vl->fstat);
mlx_delete_image(vl->mlx, vl->cstat);
mlx_delete_image(vl->mlx, vl->kstat); mlx_delete_image(vl->mlx, vl->kstat);
mlx_delete_image(vl->mlx, vl->tstat); mlx_delete_image(vl->mlx, vl->tstat);
mlx_delete_image(vl->mlx, vl->wimg); mlx_delete_image(vl->mlx, vl->wimg);
@ -44,6 +45,47 @@ void ft_printmap(t_varlist *vl)
printf("right: x: %c, y: %c\n", vl->map[(int)(vl->posx + vl->dirx * movespeed)][(int)vl->posy], vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * movespeed)]); printf("right: x: %c, y: %c\n", vl->map[(int)(vl->posx + vl->dirx * movespeed)][(int)vl->posy], vl->map[(int)vl->posx][(int)(vl->posy - vl->diry * movespeed)]);
} }
void ft_timers(t_varlist *vl)
{
char *time;
char *temp;
vl->frametime = vl->mlx->delta_time;
vl->anitime = vl->anitime + vl->frametime;
vl->tottime = (int)mlx_get_time();
time = ft_itoa(vl->tottime);
temp = ft_vastrjoin(3, "Time: ", time, " Seconds");
vl->tstat = mlx_put_string(vl->mlx, temp, 10, 70);
mlx_set_instance_depth(vl->tstat->instances, 5);
ft_vafree(2, time, temp);
}
void ft_fireweapon(t_varlist *vl)
{
double reloadtime;
if (vl->weapon == 0)
reloadtime = 0.05;
if (vl->weapon == 1)
reloadtime = 0.1;
if (vl->weapon == 2)
reloadtime = 0.05;
if (vl->weapon == 3)
reloadtime = 0.03;
if (vl->reload)
{
if (vl->anitime - vl->firetime > reloadtime)
{
vl->anitime = 0;
vl->firetime = vl->anitime;
vl->reload++;
if (vl->reload > 4)
vl->reload = 0;
}
}
}
void mainloop(void *param) void mainloop(void *param)
{ {
t_varlist *vl; t_varlist *vl;
@ -55,10 +97,10 @@ void mainloop(void *param)
/*ft_enemyaction(vl);*/ /*ft_enemyaction(vl);*/
ft_drawsprites(vl); ft_drawsprites(vl);
ft_drawweapon(vl); ft_drawweapon(vl);
ft_fireweapon(vl);
/*ft_drawminimap(vl);*/ /*ft_drawminimap(vl);*/
vl->frametime = vl->mlx->delta_time; ft_timers(vl);
ft_printstats(vl); ft_printstats(vl);
vl->frametime = vl->mlx->delta_time;
ft_processinput(vl); ft_processinput(vl);
/*ft_printmap(vl);*/ /*ft_printmap(vl);*/
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))