Time scaling with the Spell key

This commit is contained in:
Edgaru089 2024-04-22 05:46:05 +08:00
parent bef08f583f
commit ac65fb1c06
4 changed files with 18 additions and 0 deletions

4
app.c
View File

@ -29,6 +29,7 @@ App *app_NewApp() {
app->time = gametime_NewSystem(app);
app->switch_level = NULL;
app->timescale = 1.0;
app->clear_color = 0;
app->wantQuit = false;
app->paused = false;
@ -71,6 +72,9 @@ void app_Advance(App *app, Duration deltaTime) {
input_Advance(app->input);
if (1.0 - app->timescale > EPS)
deltaTime.microseconds = deltaTime.microseconds * app->timescale;
if (!app->paused) {
gametime_Advance(app->time, deltaTime);
particle_Advance(app->particle, deltaTime);

1
app.h
View File

@ -27,6 +27,7 @@ typedef struct _App {
System_GameTime *time;
char *switch_level;
double timescale;
uint32_t clear_color;
bool wantQuit, debugOn;
bool paused;

View File

@ -12,6 +12,7 @@
#include "render_util.h"
#include "util/vector.h"
#include <math.h>
#include <stdio.h>
#include <graphics.h>
@ -178,5 +179,11 @@ void app_Render(App *app) {
RECT rect = {.left = SCREEN_WIDTH / 2 - 10, .top = 100, .right = SCREEN_WIDTH / 2 + 10, .bottom = 200};
drawtext("Game Paused", &rect, DT_CENTER | DT_NOCLIP);
}
if (abs(app->timescale - 1.0) > EPS) {
RECT rect = {.left = SCREEN_WIDTH / 2 - 10, .top = 50, .right = SCREEN_WIDTH / 2 + 10, .bottom = 150};
char buf[128];
snprintf(buf, sizeof(buf), "*** TIMESCALE %.2lf ***", app->timescale);
drawtext(buf, &rect, DT_CENTER | DT_NOCLIP);
}
}
}

View File

@ -64,6 +64,12 @@ void input_Advance(System_Input *sys) {
}
}
if (input_IsPressed(sys->keys[input_Key_Spell])) {
sys->super->timescale = 0.25;
} else {
sys->super->timescale = 1.0;
}
if (sys->keys[input_Key_Escape] == JustPressed) {
if (!sys->super->paused)
fprintf(stderr, "[input_Advance] Pausing\n");