Time scaling with the Spell key
This commit is contained in:
parent
bef08f583f
commit
ac65fb1c06
4
app.c
4
app.c
@ -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
1
app.h
@ -27,6 +27,7 @@ typedef struct _App {
|
||||
System_GameTime *time;
|
||||
|
||||
char *switch_level;
|
||||
double timescale;
|
||||
uint32_t clear_color;
|
||||
bool wantQuit, debugOn;
|
||||
bool paused;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
6
input.c
6
input.c
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user