diff options
Diffstat (limited to 'src/scenes/puzzleScene.c')
| -rw-r--r-- | src/scenes/puzzleScene.c | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/src/scenes/puzzleScene.c b/src/scenes/puzzleScene.c index 48e1238..c3e48c1 100644 --- a/src/scenes/puzzleScene.c +++ b/src/scenes/puzzleScene.c @@ -1,5 +1,7 @@ #include <raylib.h> +#include <stddef.h> #include <stdlib.h> +#include <string.h> #include "scenes.h" #include "../resources/resources.h" #include "../ui_elements/UI.h" @@ -9,14 +11,20 @@ typedef struct { TextArea *EditorInfo; Button *submitButton; int scroll; + // Time until the next distraction puzzle in seconds + size_t distraction_timer; + // Miliseconds elapsed + float time_acc; } puzzleSceneData; const int HEADER_FONT_SIZE = 50; -const int PADDING = 10; const int EDITOR_PADDING = 3; const int BORDER = 2; const int FOOTER_HEIGHT = 30; +// Time in seconds +const size_t BASE_TIME_LEFT = 1; // 5 * 60; + void DrawPuzzleName(char *name) { Vector2 width = MeasureTextEx(*GetMainFont(), name, 50, 1); int screen_width = GetScreenWidth(); @@ -60,33 +68,6 @@ Rectangle GetBodyRect() { return outp; } -void GetPanesSplit(Rectangle *pane1, Rectangle *pane2, Rectangle body, float proportion_h, float proportion_v) { - if (body.height >= body.width) { - // vertical split - pane1->x = body.x; - pane1->y = body.y; - pane1->width = body.width; - pane1->height = (body.height - PADDING) * proportion_v; - - pane2->x = body.x; - pane2->y = body.y + pane1->height + PADDING; - pane2->width = body.width; - pane2->height = (body.height - PADDING) * (1 - proportion_v); - return; - } - - // horizontal split - pane1->x = body.x; - pane1->y = body.y; - pane1->height = body.height; - pane1->width = (body.width - PADDING) * proportion_h; - - pane2->y = body.y; - pane2->x = body.x + pane1->width + PADDING; - pane2->height = body.height; - pane2->width = (body.width - PADDING) * (1 - proportion_h); -} - bool drawPuzzleScene(void *self) { puzzleSceneData *data = ((Scene *)self)->data; DrawBackground(); @@ -133,6 +114,15 @@ void SubmitPuzzle(Scene *self) { AddScene(CreateResultView(res)); } +void AddTime(Scene *self, size_t additionalTime) { + puzzleSceneData *data = ((Scene *)self)->data; + data->distraction_timer += additionalTime; +} + +void createDistraction() { + AddScene(CreateDistractionScene(GetRandomDistraction(), AddTime)); +} + bool updatePuzzleScene(void *self) { puzzleSceneData *data = ((Scene *)self)->data; @@ -147,6 +137,17 @@ bool updatePuzzleScene(void *self) { if (data->submitButton != NULL) UpdateButton(data->submitButton); + data->time_acc += GetFrameTime(); + while (data->time_acc >= 1) { + data->distraction_timer -= 1; + data->time_acc -= 1; + // TraceLog(LOG_INFO, "Time left: %u", data->distraction_timer); + if (data->distraction_timer == 0) { + createDistraction(); + return true; + } + } + return true; } @@ -193,6 +194,9 @@ Scene *CreatePuzzleScene(Puzzle *puzzle) { } data->submitButton = submitButton; + data->distraction_timer = BASE_TIME_LEFT; + data->time_acc = 0; + if (puzzle->InitialCode != NULL) { data->EditorInfo = CreateTextAreaFromText(EditorDisplayParams, puzzle->InitialCode); } else { |
