ammo system implemented

This commit is contained in:
djonker 2023-11-06 01:19:16 +01:00
parent 819642bc90
commit 7bffb146ec
5 changed files with 44 additions and 8 deletions

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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

View File

@ -6,13 +6,13 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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);
}

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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");

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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;

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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;
}
}
}