audio assets and scratch and mouse
This commit is contained in:
parent
849d5c2cf7
commit
483dca8711
BIN
assets/audio/birdwing-close-92442.mp3
Normal file
BIN
assets/audio/birdwing-close-92442.mp3
Normal file
Binary file not shown.
BIN
assets/audio/mixkit-crunchy-road-fast-walking-loop-1274.wav
Normal file
BIN
assets/audio/mixkit-crunchy-road-fast-walking-loop-1274.wav
Normal file
Binary file not shown.
BIN
assets/audio/mixkit-electricity-intense-hum-2138.wav
Normal file
BIN
assets/audio/mixkit-electricity-intense-hum-2138.wav
Normal file
Binary file not shown.
BIN
assets/audio/mixkit-footsteps-in-a-tunnel-loop-543.wav
Normal file
BIN
assets/audio/mixkit-footsteps-in-a-tunnel-loop-543.wav
Normal file
Binary file not shown.
BIN
assets/audio/mixkit-game-ball-tap-2073.wav
Normal file
BIN
assets/audio/mixkit-game-ball-tap-2073.wav
Normal file
Binary file not shown.
BIN
assets/audio/mixkit-industrial-hum-loop-2139.wav
Normal file
BIN
assets/audio/mixkit-industrial-hum-loop-2139.wav
Normal file
Binary file not shown.
BIN
assets/audio/mixkit-mechanical-crate-pick-up-3154.wav
Normal file
BIN
assets/audio/mixkit-mechanical-crate-pick-up-3154.wav
Normal file
Binary file not shown.
BIN
assets/audio/mixkit-screechy-electified-item-3213.wav
Normal file
BIN
assets/audio/mixkit-screechy-electified-item-3213.wav
Normal file
Binary file not shown.
BIN
assets/audio/mixkit-ship-engine-loop-3077.wav
Normal file
BIN
assets/audio/mixkit-ship-engine-loop-3077.wav
Normal file
Binary file not shown.
BIN
assets/audio/ravenwhoosh1a-101659.mp3
Normal file
BIN
assets/audio/ravenwhoosh1a-101659.mp3
Normal file
Binary file not shown.
37
audio/Makefile
Normal file
37
audio/Makefile
Normal file
@ -0,0 +1,37 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# :::::::: #
|
||||
# Makefile :+: :+: #
|
||||
# +:+ #
|
||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||
# +#+ #
|
||||
# Created: 2025/06/02 13:18:45 by whaffman #+# #+# #
|
||||
# Updated: 2025/06/02 14:29:42 by whaffman ######## odam.nl #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME := audio
|
||||
CC := cc
|
||||
SRCS := $(wildcard *.c)
|
||||
OBJS := $(SRCS:.c=.o)
|
||||
CFLAGS := -Wall -Wextra -Werror -I../include
|
||||
LDLIBS := -lm -ldl -lpthread
|
||||
RM := rm -f
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
$(CC) $(CFLAGS) $(LDLIBS) -o $@ $^
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS)
|
||||
|
||||
fclean: clean
|
||||
$(RM) $(NAME)
|
||||
|
||||
re: fclean all
|
||||
137
audio/audio.c
Normal file
137
audio/audio.c
Normal file
@ -0,0 +1,137 @@
|
||||
#include <miniaudio.h>
|
||||
|
||||
#include "audio.h"
|
||||
|
||||
t_audio *audio_init(void)
|
||||
{
|
||||
t_audio *audio;
|
||||
ma_engine_config config;
|
||||
|
||||
audio = (t_audio *)malloc(sizeof(t_audio));
|
||||
if (!audio)
|
||||
return (NULL);
|
||||
ft_memset(audio, 0, sizeof(t_audio));
|
||||
config = ma_engine_config_init();
|
||||
config.pUserData = audio;
|
||||
config.pLogCallback = NULL;
|
||||
config.logLevel = MA_LOG_LEVEL_INFO;
|
||||
if (ma_engine_init(&config, &audio->engine) != MA_SUCCESS)
|
||||
{
|
||||
free(audio);
|
||||
return (NULL);
|
||||
}
|
||||
return (audio);
|
||||
}
|
||||
|
||||
void audio_uninit(t_audio *audio)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!audio)
|
||||
return ;
|
||||
i = 0;
|
||||
while (i < SND_SIZE)
|
||||
{
|
||||
if (audio->sounds[i])
|
||||
{
|
||||
ma_sound_uninit(&audio->sounds[i]);
|
||||
audio->sounds[i] = NULL;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
ma_engine_uninit(&audio->engine);
|
||||
free(audio);
|
||||
}
|
||||
|
||||
int audio_load_sounds(t_audio *audio)
|
||||
{
|
||||
int i;
|
||||
const char *sound_files[SND_SIZE] = {
|
||||
"assets/sounds/walk.wav",
|
||||
"assets/sounds/flash.wav",
|
||||
"assets/sounds/damage.wav",
|
||||
"assets/sounds/death.wav",
|
||||
"assets/sounds/enemy.wav",
|
||||
"assets/sounds/pickup.wav",
|
||||
"assets/sounds/hum.wav",
|
||||
"assets/sounds/noise.wav"};
|
||||
|
||||
if (!audio)
|
||||
return ();
|
||||
i = 0;
|
||||
while (i < SND_SIZE)
|
||||
{
|
||||
if (ma_sound_init_from_file(&audio->engine, sound_files[i],
|
||||
0, NULL, NULL, &audio->sounds[i]) != MA_SUCCESS)
|
||||
{
|
||||
audio_uninit(audio);
|
||||
return (FAILURE);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int audio_play(t_audio *audio, t_sound sound)
|
||||
{
|
||||
if (!audio || sound < 0 || sound >= SND_SIZE || !audio->sounds[sound])
|
||||
return (FAILURE);
|
||||
ma_sound_seek_to_pcm_frame(audio->sound[sound], 0);
|
||||
if (ma_sound_start(&audio->sounds[sound]) != MA_SUCCESS)
|
||||
return (FAILURE);
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int audio_stop(t_audio *audio, t_sound sound)
|
||||
{
|
||||
if (!audio || sound < 0 || sound >= SND_SIZE || !audio->sounds[sound])
|
||||
return (FAILURE);
|
||||
ma_sound_seek_to_pcm_frame(audio->sound[sound], 0);
|
||||
if (ma_sound_stop(&audio->sounds[sound]) != MA_SUCCESS)
|
||||
return (FAILURE);
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int audio_is_playing(t_audio *audio, t_sound sound)
|
||||
{
|
||||
if (!audio || sound < 0 || sound >= SND_SIZE || !audio->sounds[sound])
|
||||
return (FAILURE);
|
||||
if (ma_sound_is_playing(&audio->sounds[sound]))
|
||||
return (SUCCESS);
|
||||
return (FAILURE);
|
||||
}
|
||||
|
||||
int audio_loop(t_audio *audio, t_sound sound)
|
||||
{
|
||||
if (!audio || sound < 0 || sound >= SND_SIZE || !audio->sounds[sound])
|
||||
return (FAILURE);
|
||||
if (ma_sound_set_looping(&audio->sounds[sound], loop) != MA_SUCCESS)
|
||||
return (FAILURE);
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int audio_handle_queues(t_audio *audio)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!audio)
|
||||
return (FAILURE);
|
||||
i = 0;
|
||||
while (i < SND_SIZE)
|
||||
{
|
||||
if (audio->play_queue[i])
|
||||
{
|
||||
audio_play(audio, i);
|
||||
audio->play_queue[i] = 0;
|
||||
}
|
||||
if (audio->stop_queue[i])
|
||||
{
|
||||
audio_stop(audio, i);
|
||||
audio->stop_queue[i] = 0;
|
||||
}
|
||||
audio->is_playing[i] = ma_sound_is_playing(&audio->sounds[i]);
|
||||
i++;
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
37
audio/audio.h
Normal file
37
audio/audio.h
Normal file
@ -0,0 +1,37 @@
|
||||
#include "miniaudio.h"
|
||||
|
||||
#define SND_SIZE 8
|
||||
#define SUCCESS 1
|
||||
#define FAILURE 0
|
||||
|
||||
typedef enum s_sound {
|
||||
SND_WALK,
|
||||
SND_FLASH,
|
||||
SND_DAMAGE,
|
||||
SND_DEATH,
|
||||
SND_ENEMY,
|
||||
SND_PICKUP,
|
||||
SND_HUM,
|
||||
SND_NOISE
|
||||
} t_sound;
|
||||
|
||||
typedef struct s_audio {
|
||||
ma_engine engine; // The audio engine instance
|
||||
ma_sound *sounds[SND_SIZE]; // Array of sounds
|
||||
char play_queue[SND_SIZE]; // Queue for playing sounds
|
||||
char stop_queue[SND_SIZE]; // Queue for stopping sounds
|
||||
char is_playing[SND_SIZE]; // Array to check if sounds are playing
|
||||
|
||||
} t_audio;
|
||||
|
||||
t_audio *audio_init(void);
|
||||
int audio_load_sounds(t_audio *audio);
|
||||
void audio_destroy(void);
|
||||
void audio_play(t_sound sound);
|
||||
|
||||
|
||||
// typedef struct s_audio {
|
||||
// ma_engine_config config; // Configuration for the audio engine
|
||||
// ma_engine engine; // The audio engine instance
|
||||
|
||||
// } t_audio;
|
||||
84
audio/main.c
Normal file
84
audio/main.c
Normal file
@ -0,0 +1,84 @@
|
||||
|
||||
#include "audio.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
ma_data_source_read_pcm_frames((ma_data_source*)pDevice->pUserData, pOutput, frameCount, NULL);
|
||||
|
||||
(void)pInput;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
ma_device_config deviceConfig;
|
||||
ma_device device;
|
||||
ma_resource_manager_config resourceManagerConfig;
|
||||
ma_resource_manager resourceManager;
|
||||
ma_resource_manager_data_source dataSource;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("No input file.");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Device */
|
||||
deviceConfig = ma_device_config_init(ma_device_type_playback);
|
||||
deviceConfig.dataCallback = data_callback;
|
||||
deviceConfig.pUserData = &dataSource;
|
||||
result = ma_device_init(NULL, &deviceConfig, &device);
|
||||
if (result != MA_SUCCESS)
|
||||
{
|
||||
printf("Failed to initialize device.");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* ResourceManager */
|
||||
resourceManagerConfig = ma_resource_manager_config_init();
|
||||
resourceManagerConfig.decodedFormat = device.playback.format;
|
||||
resourceManagerConfig.decodedChannels = device.playback.channels;
|
||||
resourceManagerConfig.decodedSampleRate = device.sampleRate;
|
||||
result = ma_resource_manager_init(&resourceManagerConfig, &resourceManager);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_device_uninit(&device);
|
||||
printf("Failed to initialize the resource manager.");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Load the sound. */
|
||||
result = ma_resource_manager_data_source_init(
|
||||
&resourceManager,
|
||||
argv[1],
|
||||
MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_DECODE | MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_ASYNC | MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_STREAM,
|
||||
NULL, /* Async notification. */
|
||||
&dataSource);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to load sound \"%s\".", argv[1]);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Looping. */
|
||||
ma_data_source_set_looping(&dataSource, MA_TRUE);
|
||||
|
||||
/* Start the device. */
|
||||
result = ma_device_start(&device);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_device_uninit(&device);
|
||||
printf("Failed to start device.");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
printf("Press Enter to quit...\n");
|
||||
getchar();
|
||||
|
||||
/* Teardown. */
|
||||
ma_device_uninit(&device);
|
||||
ma_resource_manager_data_source_uninit(&dataSource);
|
||||
ma_resource_manager_uninit(&resourceManager);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
2
audio/miniaudio.c
Normal file
2
audio/miniaudio.c
Normal file
@ -0,0 +1,2 @@
|
||||
#define MINIAUDIO_IMPLEMENTATION
|
||||
#include "miniaudio.h"
|
||||
93468
audio/miniaudio.h
Normal file
93468
audio/miniaudio.h
Normal file
File diff suppressed because it is too large
Load Diff
15
inc/hooks.h
15
inc/hooks.h
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* hooks.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 17:51:44 by qmennen #+# #+# */
|
||||
/* Updated: 2025/04/17 19:51:48 by qmennen ### ########.fr */
|
||||
/* :::::::: */
|
||||
/* hooks.h :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 17:51:44 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/04 16:42:43 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,5 +16,6 @@
|
||||
# include "cub3d.h"
|
||||
|
||||
void keyhandle(mlx_key_data_t keydata, void *param);
|
||||
void handle_mouse(t_game *game);
|
||||
|
||||
#endif
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 18:53:27 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/22 18:48:50 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/04 16:39:57 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,5 +18,6 @@
|
||||
int player_create(t_game **game);
|
||||
void player_update(t_game *game, double delta_time);
|
||||
void visit_area(t_game *game);
|
||||
void rotate(t_player *player, double rot_speed, double delta);
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* game.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/03 22:09:28 by qmennen ### ########.fr */
|
||||
/* :::::::: */
|
||||
/* game.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/04 16:43:14 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -57,10 +57,11 @@ void game_run(t_game *game)
|
||||
}
|
||||
handle_battery(game);
|
||||
handle_record(game);
|
||||
handle_mouse(game);
|
||||
collision_sprite(game, 0, 0);
|
||||
if (game->player->battery <= 0 || count_tiles(game->map, TILE_EMPTY) == 0)
|
||||
game_over(game->manager);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void game_free(t_game *game)
|
||||
@ -80,6 +81,18 @@ void game_free(t_game *game)
|
||||
map_free(game->map);
|
||||
if (game->keyboard)
|
||||
free(game->keyboard);
|
||||
if (game->scoreboard)
|
||||
{
|
||||
if (game->scoreboard->tiles_text)
|
||||
mlx_delete_image(game->screen->mlx, game->scoreboard->tiles_text);
|
||||
if (game->scoreboard->collectibles_text)
|
||||
mlx_delete_image(game->screen->mlx, game->scoreboard->collectibles_text);
|
||||
if (game->scoreboard->battery_text)
|
||||
mlx_delete_image(game->screen->mlx, game->scoreboard->battery_text);
|
||||
if (game->scoreboard->enemies_text)
|
||||
mlx_delete_image(game->screen->mlx, game->scoreboard->enemies_text);
|
||||
free(game->scoreboard);
|
||||
}
|
||||
}
|
||||
|
||||
void game_terminate(t_game *game)
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* moves.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */
|
||||
/* Updated: 2025/06/03 22:13:43 by qmennen ### ########.fr */
|
||||
/* :::::::: */
|
||||
/* moves.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */
|
||||
/* Updated: 2025/06/04 16:39:34 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -50,7 +50,7 @@ static void strave(t_map *map, t_player *player, int dir, double delta)
|
||||
}
|
||||
}
|
||||
|
||||
static void rotate(t_player *player, double rot_speed, double delta)
|
||||
void rotate(t_player *player, double rot_speed, double delta)
|
||||
{
|
||||
player->dir = rot(player->dir, rot_speed * delta);
|
||||
player->camera = rot(player->camera, rot_speed * delta);
|
||||
@ -96,6 +96,6 @@ void player_update(t_game *game, double delta_time)
|
||||
game->screen->flash = 3;
|
||||
game->player->battery -= 0.1f;
|
||||
}
|
||||
if (game->player->hit_timer > 0)
|
||||
if (game->player->hit_timer > 0)
|
||||
game->player->hit_timer -= .1f;
|
||||
}
|
||||
|
||||
14
src/main.c
14
src/main.c
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/03 19:30:56 by qmennen ### ########.fr */
|
||||
/* :::::::: */
|
||||
/* main.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/04 17:08:16 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* game_manager_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/27 15:22:15 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/03 20:35:05 by qmennen ### ########.fr */
|
||||
/* :::::::: */
|
||||
/* game_manager_utils.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/27 15:22:15 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/04 17:51:00 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* end_screen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/06/03 16:20:35 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/03 22:07:06 by qmennen ### ########.fr */
|
||||
/* :::::::: */
|
||||
/* end_screen.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/06/03 16:20:35 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/04 15:48:54 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -52,7 +52,7 @@ char *get_score_text(char *prefix, char *suffix, int score)
|
||||
static mlx_image_t *draw_score_line(mlx_t *mlx, char *text, int x, int y)
|
||||
{
|
||||
mlx_image_t *image;
|
||||
|
||||
|
||||
if (!text)
|
||||
return (NULL);
|
||||
image = mlx_put_string(mlx, text, x, y);
|
||||
@ -81,8 +81,9 @@ void draw_end_screen(t_game_manager *manager, t_menu *menu)
|
||||
+ menu->selected_option * 50;
|
||||
tiles_score = get_score_text("Discovered area: ", "%",
|
||||
(double) game->scoreboard->tiles_visited / game->scoreboard->total_tiles * 100);
|
||||
game->scoreboard->tiles_text = draw_score_line(game->screen->mlx,
|
||||
tiles_score, 100, game->screen->height / 2 - 50);
|
||||
if (! game->scoreboard->tiles_text)
|
||||
game->scoreboard->tiles_text = draw_score_line(game->screen->mlx,
|
||||
tiles_score, 100, game->screen->height / 2 - 50);
|
||||
battery_percentage = get_score_text("Battery percentage: ",
|
||||
"%", (double) game->player->battery * 100);
|
||||
game->scoreboard->battery_text = draw_score_line(game->screen->mlx,
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* hooks.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 17:51:26 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/03 16:11:46 by qmennen ### ########.fr */
|
||||
/* :::::::: */
|
||||
/* hooks.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 17:51:26 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/04 16:48:57 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,3 +20,15 @@ void keyhandle(mlx_key_data_t keydata, void *param)
|
||||
if (keydata.key == MLX_KEY_ESCAPE)
|
||||
game_manager_destroy(manager);
|
||||
}
|
||||
|
||||
void handle_mouse(t_game *game)
|
||||
{
|
||||
t_vec2_int mouse_pos;
|
||||
mlx_t *mlx;
|
||||
|
||||
mlx = game->screen->mlx;
|
||||
mlx_set_cursor_mode(mlx, MLX_MOUSE_HIDDEN);
|
||||
mlx_get_mouse_pos(mlx, &mouse_pos.x, &mouse_pos.y);
|
||||
rotate(game->player, 0.1 * (mouse_pos.x - mlx->width / 2), mlx->delta_time);
|
||||
mlx_set_mouse_pos(mlx, mlx->width / 2, mlx->height / 2);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user