#include <stdio.h>
#include <stddef.h>
#include <raylib.h>
-#include <stdlib.h>
+#include <sys/param.h>
+#include <string.h>
#if POSIX_BC==1
#define RAYMATH_IMPLEMENTATION
Rectangle minimap_dest = {.width = 64.0f*img_export_scale.x, .height = 64.0f*img_export_scale.y, .x = 0.0f, .y = 0.0f};
Rectangle minimap_src = {.width = barrow_texture.width, .height = barrow_texture.height, .x = 0.0f, .y = 0.0f};
- if(map_visible)
+ if (timers[E_TEXT_FADE_TIME].time > 0.0f)
+ {
+ const char* text = text_places[E_STATUS_TEXT_PLACE];
+ DrawText(TextFormat("%s", text), 0, screen_dims.y - 32, 32, GREEN);
+ }
+
+ if (map_visible)
{
const int line_height = 32;
DrawFPS(fscreen_dims.x - 80, 10);
if (IsKeyReleased(KEY_F4))
{
+ processes[E_SAVE_FILE_SAVE].progress = 0.0;
+ processes[E_SAVE_FILE_SAVE].state = E_WAITING;
+
const int success = save_game(playtime);
+ timers[E_TEXT_FADE_TIME].time = timers[E_TEXT_FADE_TIME].max;
+
+ if (success == 0 && timers[E_TEXT_FADE_TIME].time == 0.0f)
+ {
+ processes[E_SAVE_FILE_SAVE].state = E_FINISHED;
+ }
+ else if (success != 0)
+ {
+ processes[E_SAVE_FILE_SAVE].state = E_BAD;
+ }
}
if (IsKeyReleased(KEY_F5))
{
+ ProcessInfo* process = &processes[E_SAVE_FILE_LOAD];
+ process->progress = 0.0;
+ process->state = E_WAITING;
+
const int success = load_game();
+ timers[E_TEXT_FADE_TIME].time = timers[E_TEXT_FADE_TIME].max;
+
+ if (success == 0 && timers[E_TEXT_FADE_TIME].time == 0.0f)
+ {
+ process->state = E_FINISHED;
+ }
+ else if (success != 0)
+ {
+ process->state = E_BAD;
+ }
+
+ memcpy(text_places[E_STATUS_TEXT_PLACE], process->info_text[process->state], 64);
}
if (IsKeyReleased(KEY_ONE))
if (player_collision.hit && player_collision.distance < 1.30f)
{
-
playtime.player_velocity.x *= -1.05;
}
else
}
}
+void update_timers()
+{
+ for (int t = 0; t < E_STATUS_TIMERS; t++)
+ {
+ if (timers[t].time > 0.0f)
+ {
+ timers[t].time = MAX(timers[t].time - (((float)1.0/target_fps) * 1000.0f), 0.0f);
+ }
+ }
+}
+
void start_render_loop()
{
initialize_prerenderer();
SetTargetFPS(target_fps);
while (!WindowShouldClose())
{
+ update_timers();
+
int func_idx = resource_state;
player_collide_point = playtime.cam.position;
PlaytimeData playtime;
+TimedStatus timers[E_STATUS_TIMERS] =
+{
+ /* timer time max */
+ /* E_TEXT_FADE_TIME */ { 0.0f, 4000.0f }
+};
+
+ProcessInfo processes[E_PROCESSES] =
+{
+ /* Process { STATE Progress, { E_UNKNOWN, E_GOOD, E_BAD, E_WAITING, E_FINISHED } } */
+ /* E_SAVE_FILE_LOAD */ { E_UNKNOWN, 0.0f, { "", "", "Failed to load save.", "Loading...", "Loaded" } },
+ /* E_SAVE_FILE_SAVE */ { E_UNKNOWN, 0.0f, { "", "", "Failed to create save.", "Saving...", "Saved" } }
+};
+
+char text_places[E_TEXT_PLACES][64];
+
const char chars[6] = {' ', ' ', ' ', '+', '#', '@'};
const int max_chars = sizeof(chars) / sizeof(chars[0]) - 1;
} PlaytimeData;
+typedef struct
+{
+ float time;
+ float max;
+} TimedStatus;
+
+typedef enum
+{
+ E_TEXT_FADE_TIME = 0,
+ E_STATUS_TIMERS
+} eTimerStatus;
+
+typedef enum
+{
+ E_UNKNOWN = 0,
+ E_GOOD,
+ E_BAD,
+ E_WAITING,
+ E_FINISHED,
+ E_STATES
+} eState;
+
+typedef enum
+{
+ E_SAVE_FILE_LOAD = 0,
+ E_SAVE_FILE_SAVE,
+
+ /* Resource load and generation here eventually too */
+
+ E_PROCESSES
+} eProcess;
+
+typedef struct
+{
+ eState state;
+ float progress;
+ char info_text[E_STATES][64];
+} ProcessInfo;
+
+typedef enum
+{
+ E_STATUS_TEXT_PLACE = 0,
+ E_TEXT_PLACES,
+} eTextPlaces;
+
extern PlaytimeData playtime;
+extern ProcessInfo processes[E_PROCESSES];
+extern TimedStatus timers[E_STATUS_TIMERS];
+extern char text_places[E_TEXT_PLACES][64];
+
extern RD_Opts barrow;
extern RD_Opts puffer;
extern RD_Opts worms;