diff --git a/cub3d.h b/cub3d.h index 34a0837..4f3b386 100644 --- a/cub3d.h +++ b/cub3d.h @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */ -/* Updated: 2023/11/06 00:37:18 by houtworm ######## odam.nl */ +/* Updated: 2023/11/06 01:16:25 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -54,6 +54,8 @@ typedef struct s_varlist mlx_image_t *tstat; mlx_image_t *cstat; mlx_image_t *kstat; + mlx_image_t *astat; + mlx_image_t *hstat; mlx_image_t *wimg; mlx_texture_t *temptext; mlx_texture_t **walltext; @@ -105,6 +107,7 @@ typedef struct s_varlist int ammo; int weapon; int reload; + int hp; } t_varlist; // MAIN diff --git a/src/draw/stats.c b/src/draw/stats.c index 9a03c10..2e7c3a3 100644 --- a/src/draw/stats.c +++ b/src/draw/stats.c @@ -6,13 +6,13 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */ -/* Updated: 2023/11/06 00:21:45 by houtworm ######## odam.nl */ +/* Updated: 2023/11/06 01:17:31 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ #include "../../cub3d.h" -void ft_printstats(t_varlist *vl) +void ft_printgamestats(t_varlist *vl) { char *total; char *current; @@ -36,3 +36,26 @@ void ft_printstats(t_varlist *vl) mlx_set_instance_depth(vl->cstat->instances, 3); mlx_set_instance_depth(vl->kstat->instances, 4); } + +void ft_printplayerstats(t_varlist *vl) +{ + char *current; + char *temp; + + current = ft_itoa(vl->ammo); + temp = ft_vastrjoin(2, "Ammo: ", current); + vl->astat = mlx_put_string(vl->mlx, temp, 10, vl->h - 30); + ft_vafree(2, temp, current); + current = ft_itoa(vl->hp); + temp = ft_vastrjoin(2, "HP: ", current); + vl->hstat = mlx_put_string(vl->mlx, temp, 10, vl->h - 50); + ft_vafree(2, temp, current); + mlx_set_instance_depth(vl->astat->instances, 6); + mlx_set_instance_depth(vl->hstat->instances, 7); +} + +void ft_printstats(t_varlist *vl) +{ + ft_printgamestats(vl); + ft_printplayerstats(vl); +} diff --git a/src/input/rest.c b/src/input/rest.c index d8b9e99..186c1c9 100644 --- a/src/input/rest.c +++ b/src/input/rest.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */ -/* Updated: 2023/11/06 00:52:07 by houtworm ######## odam.nl */ +/* Updated: 2023/11/06 01:05:43 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -32,8 +32,11 @@ void ft_processguns(t_varlist *vl) { if (mlx_is_mouse_down(vl->mlx, MLX_MOUSE_BUTTON_LEFT) && vl->reload == 0) { - vl->anitime = vl->frametime; - vl->reload = 1; + if (vl->ammo || !vl->weapon) + { + vl->anitime = vl->frametime; + vl->reload = 1; + } } if (mlx_is_mouse_down(vl->mlx, MLX_MOUSE_BUTTON_RIGHT)) ft_putendl("zoom"); diff --git a/src/main/init.c b/src/main/init.c index a9a9bbe..d5887f4 100644 --- a/src/main/init.c +++ b/src/main/init.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */ -/* Updated: 2023/11/06 00:53:16 by houtworm ######## odam.nl */ +/* Updated: 2023/11/06 01:18:00 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -97,6 +97,7 @@ void ft_initmainstuff(t_varlist *vl) vl->mgun = 0; vl->ggun = 0; vl->ammo = 10; + vl->hp = 100; vl->weapon = 0; vl->reload = 0; vl->ccolor = 0; diff --git a/src/main/main.c b/src/main/main.c index 6a3d383..8e25a42 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */ -/* Updated: 2023/11/06 00:49:31 by houtworm ######## odam.nl */ +/* Updated: 2023/11/06 01:15:49 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -19,6 +19,8 @@ void ft_replaceimage(t_varlist *vl) mlx_delete_image(vl->mlx, vl->cstat); mlx_delete_image(vl->mlx, vl->kstat); mlx_delete_image(vl->mlx, vl->tstat); + mlx_delete_image(vl->mlx, vl->astat); + mlx_delete_image(vl->mlx, vl->hstat); mlx_delete_image(vl->mlx, vl->wimg); vl->img = mlx_new_image(vl->mlx, vl->w, vl->h); vl->wimg = mlx_new_image(vl->mlx, 64, 64); @@ -80,7 +82,11 @@ void ft_fireweapon(t_varlist *vl) vl->firetime = vl->anitime; vl->reload++; if (vl->reload > 4) + { + if (vl->weapon) + vl->ammo--; vl->reload = 0; + } } }