1 #include "phantom_platforms.h"
3 Phantom_Platforms create_phantom_platforms(RectLayer *rect_layer)
7 pp.size = rect_layer->rects.count;
8 pp.rects = malloc(sizeof(pp.rects[0]) * pp.size);
9 memcpy(pp.rects, rect_layer->rects.data, sizeof(pp.rects[0]) * pp.size);
11 pp.colors = malloc(sizeof(pp.colors[0]) * pp.size);
12 memcpy(pp.colors, rect_layer->colors.data, sizeof(pp.colors[0]) * pp.size);
14 pp.hiding = calloc(1, sizeof(pp.hiding[0]) * pp.size);
19 void destroy_phantom_platforms(Phantom_Platforms pp)
26 void phantom_platforms_render(const Phantom_Platforms *pp, const Camera *camera)
31 for (size_t i = 0; i < pp->size; ++i) {
32 camera_fill_rect(camera, pp->rects[i], pp->colors[i]);
36 #define HIDING_SPEED 4.0f
38 // TODO(#1247): phantom_platforms_update is O(N) even when nothing is animated
39 void phantom_platforms_update(Phantom_Platforms *pp, float dt)
43 for (size_t i = 0; i < pp->size; ++i) {
45 if (pp->colors[i].a > 0.0f) {
47 fmaxf(0.0f, pp->colors[i].a - HIDING_SPEED * dt);
55 // TODO(#1248): phantom_platforms_hide_at is O(N)
56 void phantom_platforms_hide_at(Phantom_Platforms *pp, Vec2f position)
60 for (size_t i = 0; i < pp->size; ++i) {
61 if (rect_contains_point(pp->rects[i], position)) {