treasure can be picked up

This commit is contained in:
djonker 2023-11-04 04:40:26 +01:00
parent 89583cb8e8
commit c20a056263
6 changed files with 88 additions and 7 deletions

11
cub3d.h
View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */
/* Updated: 2023/11/04 03:13:42 by houtworm ######## odam.nl */
/* Updated: 2023/11/04 04:36:12 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -34,6 +34,8 @@ typedef struct s_varlist
mlx_t *mlx;
mlx_image_t *img;
mlx_image_t *fps;
mlx_image_t *tstat;
mlx_image_t *kstat;
mlx_texture_t *curtext;
mlx_texture_t *northtext;
mlx_texture_t *easttext;
@ -46,7 +48,6 @@ typedef struct s_varlist
mlx_texture_t *endtext;
mlx_texture_t *nazitext;
t_sprite *sprite;
t_sprite *spriteorder;
int spritecount;
int fpsrefresh;
int w;
@ -85,6 +86,12 @@ typedef struct s_varlist
int32_t ccolor;
int resize;
int *zbuffer;
int treasure;
int tottreasure;
int enemies;
int kills;
int mgun;
int ggun;
} t_varlist;
void ft_frametime(t_varlist *vl);

15
maps/treasuretest.cub Normal file
View File

@ -0,0 +1,15 @@
C 0,100,255
F 100,100,100
NO ./assets/bluestone.png
EA ./assets/colorstone.png
SO ./assets/redbrick.png
WE ./assets/wood.png
1111111
1CCCCC1
1 1
1 1
1 N 1
1 1
1111111

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */
/* Updated: 2023/11/04 03:31:53 by houtworm ######## odam.nl */
/* Updated: 2023/11/04 04:08:23 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -22,6 +22,12 @@ t_varlist initvarlist(void)
vl.zbuffer = ft_calloc(4096, 8);
vl.spritecount = 0;
vl.hoffset = 0;
vl.treasure = 0;
vl.tottreasure = 0;
vl.enemies = 0;
vl.kills = 0;
vl.mgun = 0;
vl.ggun = 0;
vl.ccolor = 0;
vl.fcolor = 0;
vl.northtext = NULL;

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */
/* Updated: 2023/11/02 04:25:38 by houtworm ######## odam.nl */
/* Updated: 2023/11/04 03:51:16 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */

View File

@ -6,12 +6,34 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */
/* Updated: 2023/11/04 02:31:20 by houtworm ######## odam.nl */
/* Updated: 2023/11/04 04:34:54 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
#include "../cub3d.h"
void ft_printstats(t_varlist *vl)
{
char *enemies;
char *kills;
char *treasure;
char *found;
char *temp;
enemies = ft_itoa(vl->enemies);
kills = ft_itoa(vl->kills);
temp = ft_vastrjoin(4, "Kills: ", kills, "/", enemies);
vl->tstat = mlx_put_string(vl->mlx, temp, 10, 30);
free(temp);
treasure = ft_itoa(vl->tottreasure);
found = ft_itoa(vl->treasure);
temp = ft_vastrjoin(4, "Treasure: ", found, "/", treasure);
vl->kstat = mlx_put_string(vl->mlx, temp, 10, 50);
mlx_set_instance_depth(vl->tstat->instances, 3);
mlx_set_instance_depth(vl->kstat->instances, 4);
ft_vafree(5, enemies, kills, treasure, found, temp);
}
void ft_frametime(t_varlist *vl)
{
char *itoa;
@ -27,6 +49,29 @@ void ft_frametime(t_varlist *vl)
ft_vafree(2, itoa, print);
}
void ft_pickup(t_varlist *vl)
{
int i;
i = 0;
while (vl->sprite[i].x)
{
if ((int)vl->sprite[i].x == (int)vl->posx)
if ((int)vl->sprite[i].y == (int)vl->posy)
if (vl->sprite[i].type == 4)
{
while (vl->sprite[i].x)
{
vl->sprite[i] = vl->sprite[i + 1];
i++;
}
vl->spritecount--;
vl->treasure++;
}
i++;
}
}
void mainloop(void *param)
{
t_varlist *vl;
@ -34,10 +79,14 @@ void mainloop(void *param)
vl = param;
mlx_delete_image(vl->mlx, vl->img);
mlx_delete_image(vl->mlx, vl->fps);
mlx_delete_image(vl->mlx, vl->tstat);
mlx_delete_image(vl->mlx, vl->kstat);
vl->img = mlx_new_image(vl->mlx, vl->w, vl->h);
ft_raycast(vl);
ft_pickup(vl);
ft_drawsprites(vl);
ft_frametime(vl);
ft_printstats(vl);
ft_movementkeys(vl);
if (!vl->img || (mlx_image_to_window(vl->mlx, vl->img, 0, 0) < 0))
ft_errorexit("image to window failed ", "mainloop", 1);

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */
/* Updated: 2023/11/04 02:39:42 by houtworm ######## odam.nl */
/* Updated: 2023/11/04 04:09:24 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -53,6 +53,8 @@ char ft_addwalktroughsprite(t_varlist *vl, int x, int y, int type)
vl->sprite[vl->spritecount].x = x + 0.5;
vl->sprite[vl->spritecount].y = y + 0.5;
vl->sprite[vl->spritecount].type = type;
if (type == 4)
vl->tottreasure++;
vl->spritecount++;
return ('0');
}
@ -62,6 +64,8 @@ char ft_addsolidsprite(t_varlist *vl, int x, int y, int type)
vl->sprite[vl->spritecount].x = x + 0.5;
vl->sprite[vl->spritecount].y = y + 0.5;
vl->sprite[vl->spritecount].type = type;
if (type == 6)
vl->enemies++;
vl->spritecount++;
return ('2');
}
@ -114,7 +118,7 @@ char **ft_getmap(t_varlist *vl, int fd)
else if (line[x] == 'H')
map[y][x] = ft_addwalktroughsprite(vl, y, x, 3);
else if (line[x] == 'C')
map[y][x] = ft_addsolidsprite(vl, y, x, 4);
map[y][x] = ft_addwalktroughsprite(vl, y, x, 4);
else if (line[x] == 'X')
map[y][x] = ft_addsolidsprite(vl, y, x, 5);
else if (line[x] == 'K')