-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_loop.c
84 lines (77 loc) · 1.96 KB
/
main_loop.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
80
81
82
83
84
/*
** EPITECH PROJECT, 2022
** test init
** File description:
** test init
*/
#include <stdlib.h>
#include <SFML/Audio.h>
#include <SFML/Graphics.h>
#include <unistd.h>
#include "header.h"
void reset(games *game, chara *charac)
{
sfMusic_stop(game->music);
if (game->score > game->best_score)
game->best_score = game->score;
game->level = 0;
game->score = 0;
set_score(game);
game->ko = 0;
game->is_over = 0;
charac->bounce = 0;
repos_charac(charac, game);
set_best_score(game);
}
int game_pause(games *game, chara *charac, globaltime *structime)
{
while (sfRenderWindow_pollEvent(game->window, &game->event)) {
analyse_events(game, charac);
}
if (game->pause == 0)
sfClock_restart(structime->clock);
return 0;
}
int menu(games *game, chara *charac, globaltime *structime)
{
while (sfRenderWindow_pollEvent(game->window, &game->event)) {
analyse_events(game, charac);
}
if (game->level != 0) {
structime->clock = sfClock_create();
sfMusic_play(game->music);
set_score(game);
}
m_window_display(game);
return 0;
}
int main_loop(games *game,
chara *charac, globaltime *structime)
{
if (game->level == 0)
return menu(game, charac, structime);
if (game->pause == 1)
return game_pause(game, charac, structime);
get_time(structime);
animate(structime, charac, game);
while (sfRenderWindow_pollEvent(game->window, &game->event)) {
analyse_events(game, charac);
}
lv_window_display(game, charac);
if (game->is_over == 1)
reset(game, charac);
return 0;
}
int my_hunter(void)
{
games game;
chara charac;
globaltime structime;
if (create_window(&game) == 84 || create_charac(&charac, &game) == 84)
return 84;
while (sfRenderWindow_isOpen(game.window)) {
main_loop(&game, &charac, &structime);
}
clean_ress(&charac, &game, &structime);
return 0;
}