10 #include "./triangle.h"
12 #define GOAL_RADIUS 10.0f
23 goals_t *create_goals_from_stream(FILE *stream)
27 lt_t *const lt = create_lt();
32 goals_t *const goals = PUSH_LT(lt, malloc(sizeof(goals_t)), free);
34 throw_error(ERROR_TYPE_LIBC);
38 goals->goals_count = 0;
39 if (fscanf(stream, "%lu", &goals->goals_count) == EOF) {
40 throw_error(ERROR_TYPE_LIBC);
44 goals->points = PUSH_LT(lt, malloc(sizeof(point_t) * goals->goals_count), free);
45 if (goals->points == NULL) {
46 throw_error(ERROR_TYPE_LIBC);
50 goals->regions = PUSH_LT(lt, malloc(sizeof(rect_t) * goals->goals_count), free);
51 if (goals->regions == NULL) {
52 throw_error(ERROR_TYPE_LIBC);
56 for (size_t i = 0; i < goals->goals_count; ++i) {
57 if (fscanf(stream, "%f%f",
59 &goals->points[i].y) < 0) {
60 throw_error(ERROR_TYPE_LIBC);
64 if (fscanf(stream, "%f%f%f%f\n",
68 &goals->regions[i].h) < 0) {
69 throw_error(ERROR_TYPE_LIBC);
80 void destroy_goals(goals_t *goals)
83 RETURN_LT0(goals->lt);
86 static int goals_render_core(const goals_t *goals,
88 SDL_Renderer *renderer,
89 const camera_t *camera)
91 if (SDL_SetRenderDrawColor(renderer, 255, 255, 50, 255) < 0) {
92 throw_error(ERROR_TYPE_SDL2);
97 const point_t position =
99 goals->points[goal_index],
100 vec(0.0f, sinf(goals->angle) * 10.0f));
102 const triangle_t core = equilateral_triangle(position, GOAL_RADIUS, PI * -0.5f + goals->angle);
104 if (camera_fill_triangle(
116 int goals_render(const goals_t *goals,
117 SDL_Renderer *renderer,
118 const camera_t *camera)
125 for (size_t i = 0; i < goals->goals_count; ++i) {
126 if (!rects_overlap(goals->regions[i], goals->player_hitbox)) {
127 if (goals_render_core(goals, i, renderer, camera) < 0) {
136 void goals_update(goals_t *goals,
140 assert(delta_time > 0);
142 float d = (float) delta_time / 1000.0f;
144 goals->angle = fmodf(goals->angle + 2.0f * d, 2.0f * PI);
147 void goals_hide(goals_t *goals,
148 rect_t player_hitbox)
150 goals->player_hitbox = player_hitbox;