-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_handle_score.c
79 lines (72 loc) · 2.43 KB
/
game_handle_score.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
** EPITECH PROJECT, 2022
** my hunter
** File description:
** my hunter
*/
#include "include/my_hunter.h"
void display_player_h_score(sfRenderWindow *window,game_t *game)
{
char *str = score_to_str(game->h_score);
char *str2 = malloc(sizeof(char)*my_strlen(str)+ 22);
my_strcpy(str2,"High score : ");
char *str3 = my_strcat(str2, str);
sfText_setString(game->text_init[H_SCORE].text, str3);
sfRenderWindow_drawText(window, game->text_init[H_SCORE].text, NULL);
free(str);
free(str2);
}
void display_player_lives(sfRenderWindow *window,game_t *game)
{
char *str = score_to_str(game->lives);
char *str2 = malloc(sizeof(char)*my_strlen(str)+ 22);
my_strcpy(str2,"Lives : ");
char *str3 = my_strcat(str2, str);
sfText_setString(game->text_init[LIVES].text, str3);
sfRenderWindow_drawText(window, game->text_init[LIVES].text, NULL);
free(str);
free(str2);
}
void display_player_score(sfRenderWindow *window,game_t *game)
{
char *str = score_to_str(game->score);
char *str2 = malloc(sizeof(char)*my_strlen(str)+ 10);
my_strcpy(str2,"Score : ");
char *str3 = my_strcat(str2, str);
sfText_setString(game->text_init[SCORE].text, str3);
sfRenderWindow_drawText(window, game->text_init[SCORE].text, NULL);
free(str);
free(str2);
}
void get_player_score(game_t *game)
{
if (sfMouse_isButtonPressed(sfMouseLeft) && !game->shooted) {
if (shooted_monster(game)) {
game->score += 1;
save_hscore(game);
game->sprite_init[ANIMATED].pos.y = rand() % 900 ;
game->sprite_init[ANIMATED].pos.x = 0;
game->shooted = true;
}
} if (game->shooted) {
game->time = sfClock_getElapsedTime(game->clock);
game->miliseconds = game->time.microseconds / 1000.0;
if (game->miliseconds - game->time_ref[TIME_SCORE] > 500) {
game->shooted = false;
game->time_ref[TIME_SCORE] = game->miliseconds;
}
}
}
bool shooted_monster(game_t *game)
{
if ((game->sprite_init[ANIMATED].pos.x <
game->sprite_init[CURSOR].pos.x + 53
&& game->sprite_init[ANIMATED].pos.x + 73 >
game->sprite_init[CURSOR].pos.x + 53)
&& (game->sprite_init[ANIMATED].pos.y <
game->sprite_init[CURSOR].pos.y + 45
&& game->sprite_init[ANIMATED].pos.y + 73 >
game->sprite_init[CURSOR].pos.y + 45))
return true;
return false;
}