mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
Compare commits
4 commits
37bb56733e
...
6cee6643e4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cee6643e4 | ||
|
|
ee56e2fdbd | ||
|
|
c3cb34c3bb | ||
|
|
b94e722ab9 |
7 changed files with 6720 additions and 12 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> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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_keypresses keypresses;
|
||||
int *screen_matrix;
|
||||
int last_since_shoot; // temp
|
||||
int delta;
|
||||
int last_tick;
|
||||
t_sprite **sprite_list;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/08 17:27:12 by tchampio #+# #+# */
|
||||
/* Updated: 2025/09/15 13:06:07 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/09/16 15:03:09 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -84,6 +84,11 @@ void create_hud(t_cub3d_data *data)
|
|||
draw_points(data);
|
||||
draw_perks(data);
|
||||
draw_round(data);
|
||||
matrix_image_put(data, data->player.weapon.texture,
|
||||
WIDTH / 2, HEIGHT - 175);
|
||||
if (data->player.weapon.is_shooting)
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
36
src/main.c
36
src/main.c
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
|
||||
/* Updated: 2025/09/15 15:45:27 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/09/16 16:07:09 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);
|
||||
free(zombie_ptr->image);
|
||||
zombie_ptr->sprite_type = DEAD_ZOMBIE;
|
||||
data->player.points += 60;
|
||||
}
|
||||
|
||||
void handle_shooting(t_cub3d_data *data)
|
||||
|
|
@ -47,16 +48,36 @@ void handle_shooting(t_cub3d_data *data)
|
|||
{
|
||||
if (!data->player.weapon.is_auto)
|
||||
data->keypresses.is_space_pressed = false;
|
||||
if (data->player.weapon.clip <= 0)
|
||||
return ;
|
||||
data->player.weapon.is_shooting = true;
|
||||
data->last_since_shoot = get_milliseconds();
|
||||
data->player.weapon.clip--;
|
||||
if (data->player.weapon.clip == 0)
|
||||
{
|
||||
ft_printf("reloading\n");
|
||||
if (data->player.weapon.remaining_ammos < 8)
|
||||
{
|
||||
data->player.weapon.clip = data->player.weapon.remaining_ammos;
|
||||
data->player.weapon.remaining_ammos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
data->player.weapon.clip = 8;
|
||||
data->player.weapon.remaining_ammos -= 8;
|
||||
}
|
||||
}
|
||||
if (data->player.aimed_zombie)
|
||||
{
|
||||
data->player.aimed_zombie->health -= 10;
|
||||
ft_printf("Shooting %p, now at %d HP\n", data->player.aimed_zombie,
|
||||
data->player.aimed_zombie->health);
|
||||
data->player.aimed_zombie->health -= 32;
|
||||
data->player.points += 10;
|
||||
ft_printf("Shooting %p, now at %d HP %d/%d\n", data->player.aimed_zombie,
|
||||
data->player.aimed_zombie->health, data->player.weapon.clip, data->player.weapon.remaining_ammos);
|
||||
if (data->player.aimed_zombie->health <= 0)
|
||||
kill_zombie(data, data->player.aimed_zombie);
|
||||
}
|
||||
else
|
||||
ft_printf("Shoot!\n");
|
||||
ft_printf("Shoot! %d/%d\n", data->player.weapon.clip, data->player.weapon.remaining_ammos);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -75,6 +96,11 @@ int game_loop(t_cub3d_data *data)
|
|||
raycaster(data, &ray);
|
||||
sprite_caster(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);
|
||||
mlx_put_image_to_window(data->mlx, data->mlx_win,
|
||||
data->img_data->img, 0, 0);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/06 11:29:14 by kcolin #+# #+# */
|
||||
/* Updated: 2025/09/10 15:58:32 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/09/16 16:06:46 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -65,7 +65,10 @@ void init_player(t_cub3d_data *data, t_player *player, t_mapdata *map)
|
|||
player->points = 500;
|
||||
ft_bzero(player->perk_order, 3);
|
||||
ft_bzero(&player->weapon, sizeof(t_weapon));
|
||||
player->weapon.clip = 8;
|
||||
player->weapon.remaining_ammos = 35;
|
||||
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')
|
||||
init_lon(player, dir);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 *shoot_texture;
|
||||
bool is_auto;
|
||||
bool is_shooting;
|
||||
bool reloading;
|
||||
int clip;
|
||||
int remaining_ammos;
|
||||
} t_weapon;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/18 13:05:31 by kcolin #+# #+# */
|
||||
/* Updated: 2025/09/15 15:39:44 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/09/16 16:08:40 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -80,4 +80,5 @@ void destroy_hud_textures(t_cub3d_data *data)
|
|||
while (i < 3)
|
||||
destroy_texture(data, data->perk_logos[i++]);
|
||||
destroy_texture(data, data->player.weapon.texture);
|
||||
destroy_texture(data, data->player.weapon.shoot_texture);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue