-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_map.c
72 lines (67 loc) · 2.35 KB
/
init_map.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
/*
** EPITECH PROJECT, 2022
** B-MUL-100-LYN-1-1-myradar-mael.rabot
** File description:
** init_map
*/
#include "include/my.h"
corner_t *init_mini_corner(sfIntRect area)
{
corner_t *mini_corner = malloc(sizeof(corner_t));
mini_corner->sub_corners = NULL;
mini_corner->objects = malloc(sizeof(launch_control_t));
mini_corner->objects->plane_list = malloc(sizeof(plane_t) * 10000);
mini_corner->objects->tower_list = NULL;
mini_corner->objects->plane_nb = 0;
mini_corner->objects->tower_nb = 0;
mini_corner->area = area;
mini_corner->rectangle = make_rectangle((sfVector2f){area.left, area.top},
(sfVector2f){area.width, area.height});
return (mini_corner);
}
corner_t *init_sub_corner(sfIntRect area, int parent_id)
{
sfIntRect *areas = init_areas(area);
corner_t *sub_corner = malloc(sizeof(corner_t));
sub_corner->sub_corners = malloc(sizeof(corner_t) * 4);
for (int i = 0; i < 4; i++) {
sub_corner->sub_corners[i] = init_mini_corner(areas[i]);
sub_corner->sub_corners[i]->ID = (id_couple_t){parent_id, i};
}
sub_corner->objects = malloc(sizeof(launch_control_t));
sub_corner->objects->plane_list = malloc(sizeof(plane_t) * 10000);
sub_corner->objects->tower_list = NULL;
sub_corner->objects->plane_nb = 0;
sub_corner->objects->tower_nb = 0;
sub_corner->area = area;
sub_corner->rectangle = make_rectangle((sfVector2f){area.left, area.top},
(sfVector2f){area.width, area.height});
return (sub_corner);
}
corner_t **init_corner_list(void)
{
corner_t **list = malloc(sizeof(corner_t) * 4);
sfIntRect *areas = init_areas((sfIntRect){0, 0,
STD_WINDOW_WIDTH, STD_WINDOW_HEIGHT});
for (int i = 0; i < 4; i++) {
list[i] = init_sub_corner(areas[i], i);
list[i]->ID = (id_couple_t){-1, i};
}
return (list);
}
map_t *init_map(settings_t *setting)
{
map_t *res = malloc(sizeof(map_t));
res->TIME = make_timers();
res->bg = make_background();
res->is_visible = setting->visible;
res->outline_visible = setting->outline;
res->paused = FALSE;
res->background_ = setting->bg;
res->grid_ = setting->grid;
res->boundary_color = (setting->bg == TRUE) ? sfBlack : sfYellow;
res->speed_mult = setting->speed;
res->map_ID = (id_couple_t){0, -1};
res->corners = init_corner_list();
return (res);
}