mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
enhancement: Added a nuzzle flash for the gun
This commit is contained in:
parent
b94e722ab9
commit
c3cb34c3bb
6 changed files with 6695 additions and 8 deletions
6670
ressources/weapon_shooting.xpm
Normal file
6670
ressources/weapon_shooting.xpm
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */
|
/* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/09/10 15:58:56 by tchampio ### ########.fr */
|
/* Updated: 2025/09/16 15:13:28 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -39,6 +39,7 @@ typedef struct s_cub3d_data
|
||||||
t_player player;
|
t_player player;
|
||||||
t_keypresses keypresses;
|
t_keypresses keypresses;
|
||||||
int *screen_matrix;
|
int *screen_matrix;
|
||||||
|
int last_since_shoot; // temp
|
||||||
int delta;
|
int delta;
|
||||||
int last_tick;
|
int last_tick;
|
||||||
t_sprite **sprite_list;
|
t_sprite **sprite_list;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/09/08 17:27:12 by tchampio #+# #+# */
|
/* Created: 2025/09/08 17:27:12 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/09/16 11:28:56 by tchampio ### ########.fr */
|
/* Updated: 2025/09/16 15:03:09 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -84,7 +84,11 @@ void create_hud(t_cub3d_data *data)
|
||||||
draw_points(data);
|
draw_points(data);
|
||||||
draw_perks(data);
|
draw_perks(data);
|
||||||
draw_round(data);
|
draw_round(data);
|
||||||
matrix_image_put(data, data->player.weapon.texture,
|
if (data->player.weapon.is_shooting)
|
||||||
WIDTH / 2, HEIGHT - 175);
|
matrix_image_put(data, data->player.weapon.shoot_texture,
|
||||||
|
WIDTH / 2, HEIGHT - 175);
|
||||||
|
else
|
||||||
|
matrix_image_put(data, data->player.weapon.texture,
|
||||||
|
WIDTH / 2, HEIGHT - 175);
|
||||||
matrix_set(data, WIDTH / 2, HEIGHT / 2, 0x0000FF00);
|
matrix_set(data, WIDTH / 2, HEIGHT / 2, 0x0000FF00);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
13
src/main.c
13
src/main.c
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
|
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/09/15 15:45:27 by tchampio ### ########.fr */
|
/* Updated: 2025/09/16 15:15:08 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -39,6 +39,7 @@ void kill_zombie(t_cub3d_data *data, t_sprite *zombie_ptr)
|
||||||
mlx_destroy_image(data->mlx, zombie_ptr->image->img);
|
mlx_destroy_image(data->mlx, zombie_ptr->image->img);
|
||||||
free(zombie_ptr->image);
|
free(zombie_ptr->image);
|
||||||
zombie_ptr->sprite_type = DEAD_ZOMBIE;
|
zombie_ptr->sprite_type = DEAD_ZOMBIE;
|
||||||
|
data->player.points += 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_shooting(t_cub3d_data *data)
|
void handle_shooting(t_cub3d_data *data)
|
||||||
|
|
@ -47,9 +48,12 @@ void handle_shooting(t_cub3d_data *data)
|
||||||
{
|
{
|
||||||
if (!data->player.weapon.is_auto)
|
if (!data->player.weapon.is_auto)
|
||||||
data->keypresses.is_space_pressed = false;
|
data->keypresses.is_space_pressed = false;
|
||||||
|
data->player.weapon.is_shooting = true;
|
||||||
|
data->last_since_shoot = get_milliseconds();
|
||||||
if (data->player.aimed_zombie)
|
if (data->player.aimed_zombie)
|
||||||
{
|
{
|
||||||
data->player.aimed_zombie->health -= 10;
|
data->player.aimed_zombie->health -= 32;
|
||||||
|
data->player.points += 10;
|
||||||
ft_printf("Shooting %p, now at %d HP\n", data->player.aimed_zombie,
|
ft_printf("Shooting %p, now at %d HP\n", data->player.aimed_zombie,
|
||||||
data->player.aimed_zombie->health);
|
data->player.aimed_zombie->health);
|
||||||
if (data->player.aimed_zombie->health <= 0)
|
if (data->player.aimed_zombie->health <= 0)
|
||||||
|
|
@ -75,6 +79,11 @@ int game_loop(t_cub3d_data *data)
|
||||||
raycaster(data, &ray);
|
raycaster(data, &ray);
|
||||||
sprite_caster(data);
|
sprite_caster(data);
|
||||||
create_hud(data);
|
create_hud(data);
|
||||||
|
if (data->player.weapon.is_shooting)
|
||||||
|
{
|
||||||
|
if (get_milliseconds() - data->last_since_shoot > 7000)
|
||||||
|
data->player.weapon.is_shooting = false;
|
||||||
|
}
|
||||||
matrix_to_image(data);
|
matrix_to_image(data);
|
||||||
mlx_put_image_to_window(data->mlx, data->mlx_win,
|
mlx_put_image_to_window(data->mlx, data->mlx_win,
|
||||||
data->img_data->img, 0, 0);
|
data->img_data->img, 0, 0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/06 11:29:14 by kcolin #+# #+# */
|
/* Created: 2025/08/06 11:29:14 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/09/10 15:58:32 by tchampio ### ########.fr */
|
/* Updated: 2025/09/16 14:59:49 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -66,6 +66,7 @@ void init_player(t_cub3d_data *data, t_player *player, t_mapdata *map)
|
||||||
ft_bzero(player->perk_order, 3);
|
ft_bzero(player->perk_order, 3);
|
||||||
ft_bzero(&player->weapon, sizeof(t_weapon));
|
ft_bzero(&player->weapon, sizeof(t_weapon));
|
||||||
player->weapon.texture = load_hud_texture(data, "ressources/weapon.xpm");
|
player->weapon.texture = load_hud_texture(data, "ressources/weapon.xpm");
|
||||||
|
player->weapon.shoot_texture = load_hud_texture(data, "ressources/weapon_shooting.xpm");
|
||||||
if (dir == 'N' || dir == 'S')
|
if (dir == 'N' || dir == 'S')
|
||||||
init_lon(player, dir);
|
init_lon(player, dir);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */
|
/* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/09/15 13:18:49 by tchampio ### ########.fr */
|
/* Updated: 2025/09/16 15:01:18 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -36,6 +36,8 @@ typedef struct s_weapon
|
||||||
t_img_data *texture;
|
t_img_data *texture;
|
||||||
t_img_data *shoot_texture;
|
t_img_data *shoot_texture;
|
||||||
bool is_auto;
|
bool is_auto;
|
||||||
|
bool is_shooting;
|
||||||
|
bool reloading;
|
||||||
int clip;
|
int clip;
|
||||||
int remaining_ammos;
|
int remaining_ammos;
|
||||||
} t_weapon;
|
} t_weapon;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue