Add battery management constants and update related calculations

This commit is contained in:
whaffman 2025-06-10 19:39:52 +02:00
parent c87ff10b57
commit b965b9e5f5
4 changed files with 29 additions and 25 deletions

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */ /* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */
/* Updated: 2025/06/10 19:29:49 by whaffman ######## odam.nl */ /* Updated: 2025/06/10 19:36:23 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,6 +19,10 @@
# define WIDTH 1920 # define WIDTH 1920
# define HEIGHT 1080 # define HEIGHT 1080
# define TITLE "Cub3D" # define TITLE "Cub3D"
# define ATTACK_DAMAGE 0.05f
# define INITIAL_BATTERY 0.5f
# define BATTERY_RATE 0.01f
# define FLASH_BATTERY 0.05f
# ifndef FULLSCREEN # ifndef FULLSCREEN
# define FULLSCREEN 1 # define FULLSCREEN 1

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* collision.c :+: :+: :+: */ /* collision.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */ /* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */
/* Updated: 2025/06/10 14:41:31 by qmennen ### ########.fr */ /* Updated: 2025/06/10 19:34:32 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -51,7 +51,7 @@ int collision_sprite(t_game *game, double xa, double ya)
&& fabs(player->pos.y + ya - sprites[i].pos.y) < 0.5)) && fabs(player->pos.y + ya - sprites[i].pos.y) < 0.5))
{ {
if (sprites[i].type == SPRITE_TYPE_ENEMY) if (sprites[i].type == SPRITE_TYPE_ENEMY)
damage_player(player, 0.05f); damage_player(player, ATTACK_DAMAGE);
else else
collect(game, &sprites[i]); collect(game, &sprites[i]);
return (1); return (1);

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* game_hud.c :+: :+: :+: */ /* game_hud.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/05/28 14:26:29 by qmennen #+# #+# */ /* Created: 2025/05/28 14:26:29 by qmennen #+# #+# */
/* Updated: 2025/06/05 18:41:43 by qmennen ### ########.fr */ /* Updated: 2025/06/10 19:37:31 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -53,7 +53,7 @@ static void draw_battery(mlx_image_t *img, float battery)
void handle_battery(t_game *game) void handle_battery(t_game *game)
{ {
game->player->battery -= game->screen->mlx->delta_time / 50; game->player->battery -= game->screen->mlx->delta_time * BATTERY_RATE;
if (game->player->battery < 0) if (game->player->battery < 0)
{ {
game->player->battery = 0; game->player->battery = 0;

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* moves.c :+: :+: :+: */ /* moves.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */ /* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */
/* Updated: 2025/06/04 18:42:35 by qmennen ### ########.fr */ /* Updated: 2025/06/10 19:38:49 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -94,7 +94,7 @@ void player_update(t_game *game, double delta_time)
if (get_key(game, MLX_KEY_SPACE)) if (get_key(game, MLX_KEY_SPACE))
{ {
game->screen->flash = 3; game->screen->flash = 3;
game->player->battery -= 0.1f; game->player->battery -= FLASH_BATTERY;
interact_door(game); interact_door(game);
} }
if (game->player->hit_timer > 0) if (game->player->hit_timer > 0)