-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_loop.c
67 lines (61 loc) · 1.9 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
/*
** EPITECH PROJECT, 2022
** B-MUL-100-LYN-1-1-myradar-mael.rabot
** File description:
** main_loop
*/
#include "include/my.h"
int visibility_check(plane_t *plane)
{
if (plane->take_off == FALSE)
return (FALSE);
if (plane->destroyed == TRUE)
return (FALSE);
if (plane->landed == TRUE)
return (FALSE);
return (TRUE);
}
void plane_update_functions(sfRenderWindow *window, map_t *map,
launch_control_t *launch)
{
if (launch->plane_nb == 0)
return;
move_list(map, launch, -1);
animation(launch, map->TIME->animation, map->paused);
take_off(launch, map->TIME->global, map->paused);
update_position(launch, map->TIME->movement, map->paused, map->speed_mult);
check_tower(&(launch));
check_collision(launch);
render_plane(window, map, launch);
}
void plane_update(sfRenderWindow *window, map_t *map)
{
for (int i = 0; i < GRID_NUMBER; i++) {
plane_update_functions(window, map, map->corners[i]->objects);
for (int j = 0; j < GRID_NUMBER; j++) {
plane_update_functions(window, map,
map->corners[i]->sub_corners[j]->objects);
}
}
plane_update_functions(window, map, map->objects);
}
void function_call(sfRenderWindow *window, map_t *map)
{
time_text_upd(map);
speed_time_upd(map->ui_speed, map->speed_mult, map->background_);
update_render(window, map);
plane_update(window, map);
}
int main_loop(sfRenderWindow *window, map_t *map)
{
sfEvent evt;
map->ui_time = create_ui_text((sfVector2f){STD_WINDOW_WIDTH - 150, 40});
map->ui_speed = create_ui_text((sfVector2f){STD_WINDOW_WIDTH - 150, 80});
while (sfRenderWindow_isOpen(window)) {
while (sfRenderWindow_pollEvent(window, &evt))
event_selector(window, evt, &map, &(map->speed_mult));
function_call(window, map);
sfRenderWindow_display(window);
}
return (EXIT_SUCCESS);
}