weapons are animated and fire

This commit is contained in:
djonker 2023-11-06 00:08:25 +01:00
parent 57b23d89f9
commit b3a3e18063
28 changed files with 213 additions and 21 deletions

View File

@ -6,7 +6,7 @@
# By: houtworm <codam@houtworm.net> +#+ #
# +#+ #
# Created: 2023/10/26 10:46:29 by houtworm #+# #+# #
# Updated: 2023/11/05 11:49:30 by houtworm ######## odam.nl #
# Updated: 2023/11/05 22:29:47 by houtworm ######## odam.nl #
# #
# **************************************************************************** #
@ -27,6 +27,7 @@ SRC =src/main/main.c\
src/draw/raycast.c\
src/draw/world.c\
src/draw/texture.c\
src/draw/weapon.c\
src/draw/stats.c\
src/input/game.c\
src/input/move.c\

View File

Before

Width:  |  Height:  |  Size: 1003 B

After

Width:  |  Height:  |  Size: 1003 B

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 697 B

After

Width:  |  Height:  |  Size: 697 B

View File

Before

Width:  |  Height:  |  Size: 887 B

After

Width:  |  Height:  |  Size: 887 B

View File

Before

Width:  |  Height:  |  Size: 963 B

After

Width:  |  Height:  |  Size: 963 B

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 963 B

After

Width:  |  Height:  |  Size: 963 B

View File

Before

Width:  |  Height:  |  Size: 816 B

After

Width:  |  Height:  |  Size: 816 B

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 984 B

After

Width:  |  Height:  |  Size: 984 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

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/05 21:40:56 by houtworm ######## odam.nl */
/* Updated: 2023/11/05 23:27:12 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -53,11 +53,16 @@ typedef struct s_varlist
mlx_image_t *fstat;
mlx_image_t *tstat;
mlx_image_t *kstat;
mlx_image_t *wimg;
mlx_texture_t *temptext;
mlx_texture_t **walltext;
mlx_texture_t **decotext;
mlx_texture_t **picktext;
mlx_texture_t **nazitext;
mlx_texture_t **gun0text;
mlx_texture_t **gun1text;
mlx_texture_t **gun2text;
mlx_texture_t **gun3text;
t_sprite *sprite;
int spritecount;
int w;
@ -95,6 +100,7 @@ typedef struct s_varlist
int ggun;
int ammo;
int weapon;
int reload;
} t_varlist;
// MAIN
@ -122,8 +128,9 @@ void cursorhook(double x, double y, void *param);
// DRAW
void ft_raycast(t_varlist *vl, int x, int mapx, int mapy);
void ft_drawmap(t_varlist *vl);
void ft_drawweapon(t_varlist *vl);
int ft_gettextx(t_varlist *vl);
uint32_t ft_gettextcolor(t_varlist *vl, int texty, int textx);
uint32_t ft_gettextcolor(mlx_texture_t *texture, int texty, int textx);
// SPRITE
void ft_drawsprite(t_varlist *vl, t_draw *draw, int x);
t_draw *ft_initdrawsprite(t_varlist *vl, int i);

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 16:54:20 by houtworm #+# #+# */
/* Updated: 2023/11/05 08:17:39 by houtworm ######## odam.nl */
/* Updated: 2023/11/05 23:26:38 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -49,12 +49,12 @@ int ft_gettextx(t_varlist *vl)
return (textx);
}
uint32_t ft_gettextcolor(t_varlist *vl, int texty, int textx)
uint32_t ft_gettextcolor(mlx_texture_t *texture, int texty, int textx)
{
uint8_t *texel;
uint32_t color;
texel = &vl->temptext->pixels[(vl->temptext->width * texty + textx) * 4];
texel = &texture->pixels[(texture->width * texty + textx) * 4];
color = texel[0] << 24 | texel[1] << 16 | texel[2] << 8 | texel[3];
return (color);
}

131
src/draw/weapon.c Normal file
View File

@ -0,0 +1,131 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* weapon.c :+: :+: */
/* +:+ */
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */
/* Updated: 2023/11/05 23:44:25 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
#include "../../cub3d.h"
void ft_drawknife(t_varlist *vl)
{
int x;
int y;
int i;
uint32_t color;
x = 0;
y = 0;
i = 1;
while (i < 4096)
{
color = ft_gettextcolor(vl->gun0text[vl->reload], y, x);
if (color != 0x980088FF)
mlx_put_pixel(vl->wimg, x, y, color);
x++;
if (i % 64 == 0)
{
x = 0;
y++;
}
i++;
}
}
void ft_drawpistol(t_varlist *vl)
{
int x;
int y;
int i;
uint32_t color;
x = 0;
y = 0;
i = 1;
while (i < 4096)
{
color = ft_gettextcolor(vl->gun1text[vl->reload], y, x);
if (color != 0x980088FF)
mlx_put_pixel(vl->wimg, x, y, color);
x++;
if (i % 64 == 0)
{
x = 0;
y++;
}
i++;
}
}
void ft_drawmgun(t_varlist *vl)
{
int x;
int y;
int i;
uint32_t color;
x = 0;
y = 0;
i = 1;
while (i < 4096)
{
color = ft_gettextcolor(vl->gun2text[vl->reload], y, x);
if (color != 0x980088FF)
mlx_put_pixel(vl->wimg, x, y, color);
x++;
if (i % 64 == 0)
{
x = 0;
y++;
}
i++;
}
}
void ft_drawggun(t_varlist *vl)
{
int x;
int y;
int i;
uint32_t color;
x = 0;
y = 0;
i = 1;
while (i < 4096)
{
color = ft_gettextcolor(vl->gun3text[vl->reload], y, x);
if (color != 0x980088FF)
mlx_put_pixel(vl->wimg, x, y, color);
x++;
if (i % 64 == 0)
{
x = 0;
y++;
}
i++;
}
}
void ft_drawweapon(t_varlist *vl)
{
int size;
if (vl->weapon == 0)
ft_drawknife(vl);
if (vl->weapon == 1)
ft_drawpistol(vl);
if (vl->weapon == 2)
ft_drawmgun(vl);
if (vl->weapon == 3)
ft_drawggun(vl);
size = vl->h * 0.8;
mlx_resize_image(vl->wimg, size, size);
mlx_image_to_window(vl->mlx, vl->wimg, vl->w / 2 - size / 2, vl->h - size);
mlx_set_instance_depth(vl->wimg->instances, 5);
}

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 16:54:20 by houtworm #+# #+# */
/* Updated: 2023/11/05 07:32:02 by houtworm ######## odam.nl */
/* Updated: 2023/11/05 23:27:55 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -40,7 +40,7 @@ int ft_drawwall(int x, t_varlist *vl, int drawstart, int drawend, int y)
{
texty = (int)textpos & (64 - 1);
textpos += step;
color = ft_gettextcolor(vl, texty, textx);
color = ft_gettextcolor(vl->temptext, texty, textx);
mlx_put_pixel(vl->img, x, y, color);
y++;
}

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 16:50:23 by houtworm #+# #+# */
/* Updated: 2023/11/05 21:51:13 by houtworm ######## odam.nl */
/* Updated: 2023/11/05 23:53:12 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -30,8 +30,35 @@ void ft_processacro(t_varlist *vl, double movespeed)
void ft_processguns(t_varlist *vl)
{
if (mlx_is_mouse_down(vl->mlx, MLX_MOUSE_BUTTON_LEFT))
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)
{
vl->reload = 1;
ft_putendl("ready");
}
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/05 11:42:47 by houtworm ######## odam.nl */
/* Updated: 2023/11/05 22:29:03 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -52,6 +52,34 @@ void ft_initenemies(t_varlist *vl)
vl->nazitext[0] = mlx_load_png("./assets/nazi/guard/guard1.png");
}
void ft_initweapons(t_varlist *vl)
{
vl->gun0text = ft_calloc(4096, 8);
vl->gun0text[0] = mlx_load_png("./assets/weapon/knife/1.png");
vl->gun0text[1] = mlx_load_png("./assets/weapon/knife/2.png");
vl->gun0text[2] = mlx_load_png("./assets/weapon/knife/3.png");
vl->gun0text[3] = mlx_load_png("./assets/weapon/knife/4.png");
vl->gun0text[4] = mlx_load_png("./assets/weapon/knife/5.png");
vl->gun1text = ft_calloc(4096, 8);
vl->gun1text[0] = mlx_load_png("./assets/weapon/pistol/1.png");
vl->gun1text[1] = mlx_load_png("./assets/weapon/pistol/2.png");
vl->gun1text[2] = mlx_load_png("./assets/weapon/pistol/3.png");
vl->gun1text[3] = mlx_load_png("./assets/weapon/pistol/4.png");
vl->gun1text[4] = mlx_load_png("./assets/weapon/pistol/5.png");
vl->gun2text = ft_calloc(4096, 8);
vl->gun2text[0] = mlx_load_png("./assets/weapon/mgun/1.png");
vl->gun2text[1] = mlx_load_png("./assets/weapon/mgun/2.png");
vl->gun2text[2] = mlx_load_png("./assets/weapon/mgun/3.png");
vl->gun2text[3] = mlx_load_png("./assets/weapon/mgun/4.png");
vl->gun2text[4] = mlx_load_png("./assets/weapon/mgun/5.png");
vl->gun3text = ft_calloc(4096, 8);
vl->gun3text[0] = mlx_load_png("./assets/weapon/mgun/1.png");
vl->gun3text[1] = mlx_load_png("./assets/weapon/mgun/2.png");
vl->gun3text[2] = mlx_load_png("./assets/weapon/mgun/3.png");
vl->gun3text[3] = mlx_load_png("./assets/weapon/mgun/4.png");
vl->gun3text[4] = mlx_load_png("./assets/weapon/mgun/5.png");
}
void ft_initmainstuff(t_varlist *vl)
{
vl->w = 800;
@ -69,6 +97,8 @@ void ft_initmainstuff(t_varlist *vl)
vl->mgun = 0;
vl->ggun = 0;
vl->ammo = 10;
vl->weapon = 0;
vl->reload = 0;
vl->ccolor = 0;
vl->fcolor = 0;
vl->walltext[0] = NULL;
@ -85,6 +115,7 @@ t_varlist initgame(void)
ft_initsprites(&vl);
ft_initpickups(&vl);
ft_initenemies(&vl);
ft_initweapons(&vl);
vl.mlx = mlx_init(vl.w, vl.h, "Cub3D", true);
if (!vl.mlx)
ft_errorexit("MLX failed to init", "initvarlist", 1);

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */
/* Updated: 2023/11/05 21:50:28 by houtworm ######## odam.nl */
/* Updated: 2023/11/05 23:41:31 by houtworm ######## odam.nl */
/* */
/* ************************************************************************** */
@ -18,7 +18,9 @@ void ft_replaceimage(t_varlist *vl)
mlx_delete_image(vl->mlx, vl->fstat);
mlx_delete_image(vl->mlx, vl->kstat);
mlx_delete_image(vl->mlx, vl->tstat);
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);
}
void ft_printmap(t_varlist *vl)
@ -40,15 +42,8 @@ void ft_printmap(t_varlist *vl)
printf("backward: 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("left: 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)]);
printf("weapon: %d\n", vl->weapon);
}
/*void ft_drawweapon(t_varlist *vl)*/
/*{*/
/*}*/
void mainloop(void *param)
{
t_varlist *vl;
@ -59,13 +54,13 @@ void mainloop(void *param)
ft_checkpickup(vl);
/*ft_enemyaction(vl);*/
ft_drawsprites(vl);
/*ft_drawweapon(vl);*/
ft_drawweapon(vl);
/*ft_drawminimap(vl);*/
vl->frametime = vl->mlx->delta_time;
ft_printstats(vl);
vl->frametime = vl->mlx->delta_time;
ft_processinput(vl);
ft_printmap(vl);
/*ft_printmap(vl);*/
if (!vl->img || (mlx_image_to_window(vl->mlx, vl->img, 0, 0) < 0))
ft_errorexit("image to window failed ", "mainloop", 1);
mlx_set_instance_depth(vl->img->instances, 1);