speedrun timer
This commit is contained in:
parent
4f6ca567d4
commit
af856bb775
|
@ -18,6 +18,7 @@ set(SOURCES
|
|||
src/editor.c
|
||||
src/player.c
|
||||
src/polarity.c
|
||||
src/time.c
|
||||
)
|
||||
|
||||
set(ASSETS
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void time_draw(void);
|
|
@ -4,3 +4,6 @@ int sign(int);
|
|||
float absf(float);
|
||||
float minf(float, float);
|
||||
float maxf(float, float);
|
||||
int min(int, int);
|
||||
int max(int, int);
|
||||
void dputs_outline(int x, int y, int halign, int valign, const char *);
|
||||
|
|
15
src/level.c
15
src/level.c
|
@ -3,6 +3,7 @@
|
|||
#include "player.h"
|
||||
#include "polarity.h"
|
||||
#include "tile.h"
|
||||
#include "util.h"
|
||||
#include "vec.h"
|
||||
#include "visual_data.h"
|
||||
#include <gint/display.h>
|
||||
|
@ -125,18 +126,8 @@ level_draw(void)
|
|||
void
|
||||
level_draw_name(void)
|
||||
{
|
||||
const int dx = DWIDTH - 4;
|
||||
const int dy = DHEIGHT - 2;
|
||||
int x = 2;
|
||||
while (x-- > -1) {
|
||||
int y = 2;
|
||||
while (y-- > -1) {
|
||||
dprint_opt(dx + x, dy + y, C_WHITE, C_NONE, DTEXT_RIGHT,
|
||||
DTEXT_BOTTOM, "%s", levels[level.id].name);
|
||||
}
|
||||
}
|
||||
dprint_opt(dx, dy, C_BLACK, C_NONE, DTEXT_RIGHT, DTEXT_BOTTOM, "%s",
|
||||
levels[level.id].name);
|
||||
dputs_outline(DWIDTH - 4, DHEIGHT - 2, DTEXT_RIGHT, DTEXT_BOTTOM,
|
||||
levels[level.id].name);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "input.h"
|
||||
#include "level.h"
|
||||
#include "player.h"
|
||||
#include "time.h"
|
||||
#include <gint/cpu.h>
|
||||
#include <gint/display.h>
|
||||
#include <gint/timer.h>
|
||||
|
@ -10,6 +11,7 @@
|
|||
static struct Player player;
|
||||
static int timer;
|
||||
volatile int has_ticked;
|
||||
int time = 0;
|
||||
|
||||
static void init(void);
|
||||
static void deinit(void);
|
||||
|
@ -32,8 +34,10 @@ main(void)
|
|||
if (has_ticked > frameskip) frameskip = has_ticked;
|
||||
while (!has_ticked)
|
||||
sleep();
|
||||
while (has_ticked)
|
||||
while (has_ticked) {
|
||||
time += has_ticked;
|
||||
has_ticked = 0;
|
||||
}
|
||||
update();
|
||||
}
|
||||
} while (input_up(K_EXIT));
|
||||
|
@ -80,6 +84,7 @@ draw(void)
|
|||
level_draw();
|
||||
player_draw(&player);
|
||||
level_draw_name();
|
||||
time_draw();
|
||||
dupdate();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#include "time.h"
|
||||
#include "conf.h"
|
||||
#include "stdio.h"
|
||||
#include "util.h"
|
||||
#include <gint/display.h>
|
||||
|
||||
void
|
||||
time_draw(void)
|
||||
{
|
||||
extern int time;
|
||||
const int minutes = min(99, time / TARGET_FPS / 60);
|
||||
const int seconds =
|
||||
(time < 100 * TARGET_FPS * 60) ? (time / TARGET_FPS % 60) : (59);
|
||||
char buf[256];
|
||||
|
||||
sprintf(buf, "%02d : %02d", minutes, seconds);
|
||||
dputs_outline(4, 2, DTEXT_LEFT, DTEXT_TOP, buf);
|
||||
}
|
27
src/util.c
27
src/util.c
|
@ -1,4 +1,5 @@
|
|||
#include "util.h"
|
||||
#include <gint/display.h>
|
||||
|
||||
int
|
||||
sign(int x)
|
||||
|
@ -23,3 +24,29 @@ maxf(float x, float y)
|
|||
{
|
||||
return (x > y) ? (x) : (y);
|
||||
}
|
||||
|
||||
int
|
||||
min(int x, int y)
|
||||
{
|
||||
return (x < y) ? (x) : (y);
|
||||
}
|
||||
|
||||
int
|
||||
max(int x, int y)
|
||||
{
|
||||
return (x > y) ? (x) : (y);
|
||||
}
|
||||
|
||||
void
|
||||
dputs_outline(int x, int y, int halign, int valign, const char *text)
|
||||
{
|
||||
int rx = 2;
|
||||
while (rx-- > -1) {
|
||||
int ry = 2;
|
||||
while (ry-- > -1) {
|
||||
dprint_opt(x + rx, y + ry, C_WHITE, C_NONE, halign,
|
||||
valign, "%s", text);
|
||||
}
|
||||
}
|
||||
dprint_opt(x, y, C_BLACK, C_NONE, halign, valign, "%s", text);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue