Introduce Phantom Platforms

master
rexim 2020-01-26 02:50:56 +07:00
parent 5cb28cec4a
commit 100d4dbc07
8 changed files with 94 additions and 1 deletions

View File

@ -42,3 +42,7 @@ box_1 -609.278137 -667.919678 112.500031 107.291695 9aa034
box_0 -3923.780518 452.429810 112.500031 107.291695 a05034
0
0
3
pp_0 -104.841812 -42.929047 55.225319 53.499516 ff0000
pp_1 30.632792 -131.375824 56.951111 62.559914 ff0000
pp_2 59.539791 -29.554169 44.870571 75.071899 ff0000

View File

@ -49,3 +49,4 @@
#include "src/dynarray.c"
#include "src/system/file.c"
#include "src/ring_buffer.c"
#include "src/game/level/phantom_platforms.h"

View File

@ -50,6 +50,7 @@ LevelEditor *create_level_editor(Memory *memory, Cursor *cursor)
level_editor->regions_layer = create_rect_layer(memory, "region", cursor);
level_editor->goals_layer = create_point_layer(memory, "goal");
level_editor->label_layer = create_label_layer(memory, "label");
level_editor->pp_layer = create_rect_layer(memory, "pp", cursor);
level_editor->layers[LAYER_PICKER_BOXES] = rect_layer_as_layer(level_editor->boxes_layer);
level_editor->layers[LAYER_PICKER_PLATFORMS] = rect_layer_as_layer(level_editor->platforms_layer);
@ -60,6 +61,7 @@ LevelEditor *create_level_editor(Memory *memory, Cursor *cursor)
level_editor->layers[LAYER_PICKER_REGIONS] = rect_layer_as_layer(level_editor->regions_layer);
level_editor->layers[LAYER_PICKER_BACKGROUND] = background_layer_as_layer(&level_editor->background_layer);
level_editor->layers[LAYER_PICKER_LABELS] = label_layer_as_layer(level_editor->label_layer);
level_editor->layers[LAYER_PICKER_PP] = rect_layer_as_layer(level_editor->pp_layer);
level_editor->notice = (FadingWigglyText) {
@ -363,7 +365,8 @@ static LayerPicker level_format_layer_order[LAYER_PICKER_N] = {
LAYER_PICKER_BACK_PLATFORMS,
LAYER_PICKER_BOXES,
LAYER_PICKER_LABELS,
LAYER_PICKER_REGIONS
LAYER_PICKER_REGIONS,
LAYER_PICKER_PP
};
/* TODO(#904): LevelEditor does not check that the saved level file is modified by external program */

View File

@ -36,6 +36,7 @@ struct LevelEditor
RectLayer *regions_layer;
BackgroundLayer background_layer;
LabelLayer *label_layer;
RectLayer *pp_layer;
LayerPtr layers[LAYER_PICKER_N];

View File

@ -25,6 +25,7 @@ static const Color LAYER_CELL_BACKGROUND_COLORS[LAYER_PICKER_N] = {
{0.2f, 1.0f, 0.6f, 1.0f}, // LAYER_PICKER_BOXES
{0.2f, 0.6f, 1.0f, 1.0f}, // LAYER_PICKER_LABELS
{0.2f, 1.0f, 0.6f, 1.0f}, // LAYER_PICKER_REGIONS
{0.2f, 1.0f, 0.6f, 1.0f}, // LAYER_PICKER_PP
};
static const char *LAYER_CELL_TITLES[LAYER_PICKER_N] = {
@ -37,6 +38,7 @@ static const char *LAYER_CELL_TITLES[LAYER_PICKER_N] = {
"Boxes", // LAYER_PICKER_BOXES
"Labels", // LAYER_PICKER_LABELS
"Regions", // LAYER_PICKER_REGIONS
"Phantom Platforms", // LAYER_PICKER_PP
};
inline static float layer_picker_max_width(void)

View File

@ -15,6 +15,7 @@ typedef enum {
LAYER_PICKER_BOXES,
LAYER_PICKER_LABELS,
LAYER_PICKER_REGIONS,
LAYER_PICKER_PP,
LAYER_PICKER_N
} LayerPicker;

View File

@ -0,0 +1,63 @@
#include "phantom_platforms.h"
Phantom_Platforms create_phantom_platforms(RectLayer *rect_layer)
{
Phantom_Platforms pp;
pp.size = rect_layer->rects.count;
pp.rects = malloc(sizeof(pp.rects[0]) * pp.size);
memcpy(pp.rects, rect_layer->rects.data, sizeof(pp.rects[0]) * pp.size);
pp.colors = malloc(sizeof(pp.colors[0]) * pp.size);
memcpy(pp.colors, rect_layer->colors.data, sizeof(pp.colors[0]) * pp.size);
pp.hiding = calloc(1, sizeof(pp.hiding[0]) * pp.size);
return pp;
}
void destroy_phantom_platforms(Phantom_Platforms pp)
{
free(pp.rects);
free(pp.colors);
free(pp.hiding);
}
void phantom_platforms_render(Phantom_Platforms *pp, Camera *camera)
{
trace_assert(pp);
trace_assert(camera);
for (size_t i = 0; i < pp->size; ++i) {
camera_fill_rect(camera, pp->rects[i], pp->colors[i]);
}
}
#define HIDING_SPEED 2.0f
void phantom_platforms_update(Phantom_Platforms *pp, float dt)
{
trace_assert(pp);
for (size_t i = 0; i < pp->size; ++i) {
if (pp->hiding[i]) {
if (pp->colors[i].a > 0.0f) {
pp->colors[i].a =
fmaxf(0.0f, pp->colors[i].a - HIDING_SPEED * dt);
} else {
pp->hiding[i] = 0;
}
}
}
}
void phantom_platforms_hide_at(Phantom_Platforms *pp, Vec2f position)
{
trace_assert(pp);
for (size_t i = 0; i < pp->size; ++i) {
if (rect_contains_point(pp->rects[i], position)) {
pp->hiding[i] = 1;
}
}
}

View File

@ -0,0 +1,18 @@
#ifndef PHANTOM_PLATFORMS_H_
#define PHANTOM_PLATFORMS_H_
typedef struct {
size_t size;
Rect *rects;
Color *colors;
int *hiding;
} Phantom_Platforms;
Phantom_Platforms create_phantom_platforms(RectLayer *rect_layer);
void destroy_phantom_platforms(Phantom_Platforms pp);
void phantom_platforms_render(Phantom_Platforms *pp, Camera *camera);
void phantom_platforms_update(Phantom_Platforms *pp, float dt);
void phantom_platforms_hide_at(Phantom_Platforms *pp, Vec2f position);
#endif // PHANTOM_PLATFORMS_H_