79 lines
2.0 KiB
C
79 lines
2.0 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* end_screen_utils.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/06/10 14:54:49 by qmennen #+# #+# */
|
|
/* Updated: 2025/06/11 16:24:05 by qmennen ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "game_menu.h"
|
|
|
|
char *get_score_prefix(int index)
|
|
{
|
|
const char *score_prefix[] = {
|
|
"Discovered area: ",
|
|
"Battery percentage: ",
|
|
"Batteries found: ",
|
|
"Enemies defeated: ",
|
|
"Play time: "
|
|
};
|
|
|
|
if (index < 0 || index >= 5)
|
|
return (NULL);
|
|
return ((char *)score_prefix[index]);
|
|
}
|
|
|
|
char *get_score_suffix(int index)
|
|
{
|
|
const char *score_suffix[] = {
|
|
"%",
|
|
"%",
|
|
NULL,
|
|
NULL,
|
|
" seconds"
|
|
};
|
|
|
|
if (index < 0 || index >= 5)
|
|
return (NULL);
|
|
return ((char *)score_suffix[index]);
|
|
}
|
|
|
|
void draw_score_line(
|
|
mlx_t *mlx, mlx_image_t **img, char *text, t_vec2_int pos
|
|
)
|
|
{
|
|
if (!text)
|
|
return ;
|
|
if (*img != NULL)
|
|
{
|
|
free(text);
|
|
return ;
|
|
}
|
|
*img = mlx_put_string(mlx, text, pos.x, pos.y);
|
|
free(text);
|
|
}
|
|
|
|
char *get_score_text(char *prefix, char *suffix, int score)
|
|
{
|
|
char *score_text;
|
|
char *score_complete;
|
|
char *score_value;
|
|
|
|
score_text = ft_itoa(score);
|
|
if (!score_text)
|
|
return (NULL);
|
|
score_value = ft_strjoin(prefix, score_text);
|
|
free(score_text);
|
|
if (!score_value)
|
|
return (NULL);
|
|
if (!suffix)
|
|
return (score_value);
|
|
score_complete = ft_strjoin(score_value, suffix);
|
|
free(score_value);
|
|
return (score_complete);
|
|
}
|