From: rexim Date: Sat, 25 Jan 2020 19:50:56 +0000 (+0700) Subject: Introduce Phantom Platforms X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=100d4dbc07e806f3d065e782040ef65f91b84b27;p=nothing.git Introduce Phantom Platforms --- diff --git a/assets/levels/level-02.txt b/assets/levels/level-02.txt index 6ef6ac53..449c114f 100644 --- a/assets/levels/level-02.txt +++ b/assets/levels/level-02.txt @@ -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 diff --git a/nothing.c b/nothing.c index ef13b378..7c45c8a3 100644 --- a/nothing.c +++ b/nothing.c @@ -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" diff --git a/src/game/level/level_editor.c b/src/game/level/level_editor.c index 24c44f1e..498f56ca 100644 --- a/src/game/level/level_editor.c +++ b/src/game/level/level_editor.c @@ -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 */ diff --git a/src/game/level/level_editor.h b/src/game/level/level_editor.h index afa2494d..4e5bd674 100644 --- a/src/game/level/level_editor.h +++ b/src/game/level/level_editor.h @@ -36,6 +36,7 @@ struct LevelEditor RectLayer *regions_layer; BackgroundLayer background_layer; LabelLayer *label_layer; + RectLayer *pp_layer; LayerPtr layers[LAYER_PICKER_N]; diff --git a/src/game/level/level_editor/layer_picker.c b/src/game/level/level_editor/layer_picker.c index 077a56b3..80287daa 100644 --- a/src/game/level/level_editor/layer_picker.c +++ b/src/game/level/level_editor/layer_picker.c @@ -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) diff --git a/src/game/level/level_editor/layer_picker.h b/src/game/level/level_editor/layer_picker.h index 074dd146..87da49a5 100644 --- a/src/game/level/level_editor/layer_picker.h +++ b/src/game/level/level_editor/layer_picker.h @@ -15,6 +15,7 @@ typedef enum { LAYER_PICKER_BOXES, LAYER_PICKER_LABELS, LAYER_PICKER_REGIONS, + LAYER_PICKER_PP, LAYER_PICKER_N } LayerPicker; diff --git a/src/game/level/phantom_platforms.c b/src/game/level/phantom_platforms.c new file mode 100644 index 00000000..6ed96ddc --- /dev/null +++ b/src/game/level/phantom_platforms.c @@ -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; + } + } +} diff --git a/src/game/level/phantom_platforms.h b/src/game/level/phantom_platforms.h new file mode 100644 index 00000000..710bc494 --- /dev/null +++ b/src/game/level/phantom_platforms.h @@ -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_