diff --git a/src/hud/hud.c b/src/hud/hud.c index c8debef..a67a813 100644 --- a/src/hud/hud.c +++ b/src/hud/hud.c @@ -6,7 +6,7 @@ /* By: tchampio +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/09/08 17:27:12 by tchampio #+# #+# */ -/* Updated: 2025/09/17 16:55:05 by tchampio ### ########.fr */ +/* Updated: 2025/09/16 15:03:09 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -84,11 +84,11 @@ void create_hud(t_cub3d_data *data) draw_points(data); draw_perks(data); draw_round(data); - if (data->player.weapon->is_shooting) - matrix_image_put(data, data->player.weapon->shoot_texture, + 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, + matrix_image_put(data, data->player.weapon.texture, WIDTH / 2, HEIGHT - 175); matrix_set(data, WIDTH / 2, HEIGHT / 2, 0x0000FF00); } diff --git a/src/main.c b/src/main.c index 3224d56..c053bd9 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */ -/* Updated: 2025/09/17 16:55:39 by tchampio ### ########.fr */ +/* Updated: 2025/09/16 16:07:09 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,43 +46,38 @@ void handle_shooting(t_cub3d_data *data) { if (data->keypresses.is_space_pressed) { - if (!data->player.weapon->is_auto) + if (!data->player.weapon.is_auto) data->keypresses.is_space_pressed = false; - if (data->last_since_shoot != 0 && data->player.weapon->is_auto) - { - if (get_milliseconds() - data->last_since_shoot < 50000) - return ; - } - if (data->player.weapon->clip <= 0 && data->player.weapon->remaining_ammos > 0) + 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) + if (data->player.weapon.remaining_ammos < 8) { - data->player.weapon->clip = data->player.weapon->remaining_ammos; - data->player.weapon->remaining_ammos = 0; + 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; + data->player.weapon.clip = 8; + data->player.weapon.remaining_ammos -= 8; } } - 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.aimed_zombie) { 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); + 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! %d/%d\n", data->player.weapon->clip, data->player.weapon->remaining_ammos); + ft_printf("Shoot! %d/%d\n", data->player.weapon.clip, data->player.weapon.remaining_ammos); } } @@ -101,10 +96,10 @@ int game_loop(t_cub3d_data *data) raycaster(data, &ray); sprite_caster(data); create_hud(data); - if (data->player.weapon->is_shooting) + if (data->player.weapon.is_shooting) { if (get_milliseconds() - data->last_since_shoot > 7000) - data->player.weapon->is_shooting = false; + data->player.weapon.is_shooting = false; } matrix_to_image(data); mlx_put_image_to_window(data->mlx, data->mlx_win, diff --git a/src/player/player.c b/src/player/player.c index 5b85e3f..e2db712 100644 --- a/src/player/player.c +++ b/src/player/player.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/08/06 11:29:14 by kcolin #+# #+# */ -/* Updated: 2025/09/17 16:56:50 by tchampio ### ########.fr */ +/* Updated: 2025/09/16 16:06:46 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,12 +64,11 @@ void init_player(t_cub3d_data *data, t_player *player, t_mapdata *map) player->health = 100; player->points = 500; ft_bzero(player->perk_order, 3); - player->weapon = ft_calloc(sizeof(t_weapon), 1); - player->weapon->clip = 8; - player->weapon->is_auto = true; - 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"); + 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 diff --git a/src/player/player.h b/src/player/player.h index 0ace102..3bc6bea 100644 --- a/src/player/player.h +++ b/src/player/player.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */ -/* Updated: 2025/09/17 16:52:41 by tchampio ### ########.fr */ +/* Updated: 2025/09/16 15:01:18 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,6 @@ # include "../map/mapdata.h" # include "../draw/img_data.h" # include "../sprites/sprite.h" -# include "weapon.h" typedef struct s_vec2 { @@ -32,6 +31,17 @@ typedef enum e_perks DOUBLETAP } t_perks; +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; + typedef struct s_player { double x; @@ -47,7 +57,7 @@ typedef struct s_player bool has_doubletap; t_perks perk_order[3]; t_vec2 movement; - t_weapon *weapon; + t_weapon weapon; t_sprite *aimed_zombie; } t_player; diff --git a/src/player/weapon.h b/src/player/weapon.h deleted file mode 100644 index 0317e4b..0000000 --- a/src/player/weapon.h +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* weapon.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tchampio +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/09/17 16:50:52 by tchampio #+# #+# */ -/* Updated: 2025/09/17 16:52:29 by tchampio ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef WEAPON_H -# define WEAPON_H - -# include "../draw/img_data.h" - -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; - int base_clip; - int base_ammos; -} t_weapon; - -#endif // WEAPON_H diff --git a/src/utils/destroy_utils.c b/src/utils/destroy_utils.c index 341d5ff..2d22873 100644 --- a/src/utils/destroy_utils.c +++ b/src/utils/destroy_utils.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/08/18 13:05:31 by kcolin #+# #+# */ -/* Updated: 2025/09/17 16:54:35 by tchampio ### ########.fr */ +/* Updated: 2025/09/16 16:08:40 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -79,6 +79,6 @@ void destroy_hud_textures(t_cub3d_data *data) i = 0; 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); + destroy_texture(data, data->player.weapon.texture); + destroy_texture(data, data->player.weapon.shoot_texture); } diff --git a/src/utils/frees.c b/src/utils/frees.c index 1d5fa68..ab6a19a 100644 --- a/src/utils/frees.c +++ b/src/utils/frees.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 13:59:27 by kcolin #+# #+# */ -/* Updated: 2025/09/17 16:57:32 by tchampio ### ########.fr */ +/* Updated: 2025/09/08 14:15:58 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,7 +75,6 @@ int destroy(t_cub3d_data *data, int exit_code) free(data->sprite_list); free(data->mlx); free(data->screen_matrix); - free(data->player.weapon); exit(exit_code); return (0); } diff --git a/src/utils/hooks.c b/src/utils/hooks.c index 278a96f..3be647e 100644 --- a/src/utils/hooks.c +++ b/src/utils/hooks.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:22:57 by kcolin #+# #+# */ -/* Updated: 2025/09/17 16:55:52 by tchampio ### ########.fr */ +/* Updated: 2025/09/14 15:57:54 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,8 +43,6 @@ int keypress_handler(int keycode, t_cub3d_data *data) data->player.points += 500; if (keycode == XK_u) data->round++; - if (keycode == XK_m) - data->player.weapon->remaining_ammos = 1337; return (0); }