Make back platforms always hide when player touches them
This commit is contained in:
parent
40004db6af
commit
5cb28cec4a
@ -220,6 +220,10 @@ int level_update(Level *level, float delta_time)
|
||||
lava_update(level->lava, delta_time);
|
||||
labels_update(level->labels, delta_time);
|
||||
|
||||
Rect hitbox = player_hitbox(level->player);
|
||||
platforms_hide_platform_at(level->back_platforms, vec(hitbox.x, hitbox.y));
|
||||
platforms_update(level->back_platforms, delta_time);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ struct Platforms {
|
||||
|
||||
Rect *rects;
|
||||
Color *colors;
|
||||
int *hiding;
|
||||
size_t rects_size;
|
||||
};
|
||||
|
||||
@ -50,6 +51,12 @@ Platforms *create_platforms_from_rect_layer(const RectLayer *layer)
|
||||
}
|
||||
memcpy(platforms->colors, rect_layer_colors(layer), sizeof(Color) * platforms->rects_size);
|
||||
|
||||
platforms->hiding = PUSH_LT(lt, nth_calloc(1, sizeof(int) * platforms->rects_size), free);
|
||||
if (platforms->hiding == NULL) {
|
||||
RETURN_LT(lt, NULL);
|
||||
}
|
||||
memset(platforms->hiding, 0, sizeof(int) * platforms->rects_size);
|
||||
|
||||
return platforms;
|
||||
}
|
||||
|
||||
@ -141,3 +148,32 @@ Vec2f platforms_snap_rect(const Platforms *platforms,
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#define HIDING_SPEED 2.0f
|
||||
|
||||
void platforms_update(Platforms *platforms, float dt)
|
||||
{
|
||||
trace_assert(platforms);
|
||||
for (size_t i = 0; i < platforms->rects_size; ++i) {
|
||||
if (platforms->hiding[i]) {
|
||||
if (platforms->colors[i].a > 0.0f) {
|
||||
platforms->colors[i].a =
|
||||
fmaxf(0.0f, platforms->colors[i].a - HIDING_SPEED * dt);
|
||||
} else {
|
||||
platforms->hiding[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void platforms_hide_platform_at(const Platforms *platforms,
|
||||
Vec2f position)
|
||||
{
|
||||
trace_assert(platforms);
|
||||
|
||||
for (size_t i = 0; i < platforms->rects_size; ++i) {
|
||||
if (rect_contains_point(platforms->rects[i], position)) {
|
||||
platforms->hiding[i] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,15 @@ void destroy_platforms(Platforms *platforms);
|
||||
int platforms_render(const Platforms *platforms,
|
||||
const Camera *camera);
|
||||
|
||||
void platforms_update(Platforms *platforms, float dt);
|
||||
|
||||
void platforms_touches_rect_sides(const Platforms *platforms,
|
||||
Rect object,
|
||||
int sides[RECT_SIDE_N]);
|
||||
Vec2f platforms_snap_rect(const Platforms *platforms,
|
||||
Rect *object);
|
||||
|
||||
void platforms_hide_platform_at(const Platforms *platforms,
|
||||
Vec2f position);
|
||||
|
||||
#endif // PLATFORMS_H_
|
||||
|
Loading…
x
Reference in New Issue
Block a user