aboutsummaryrefslogtreecommitdiff
path: root/src/game.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-15 22:35:39 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-15 22:35:39 +0100
commit07e829e591394fa182e75ecab86051f1fb850ce7 (patch)
treee3b59887aaa463400392040ccf601eab862eba82 /src/game.c
parent671803751cc9487ea781eb264ab2d76575c345e8 (diff)
downloadgold-mine-run-07e829e591394fa182e75ecab86051f1fb850ce7.tar.gz
gold-mine-run-07e829e591394fa182e75ecab86051f1fb850ce7.zip
Started with the game
Added hud (WIP)
Diffstat (limited to 'src/game.c')
-rw-r--r--src/game.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/game.c b/src/game.c
new file mode 100644
index 0000000..70c3235
--- /dev/null
+++ b/src/game.c
@@ -0,0 +1,85 @@
+#include <stdint.h>
+#include <stdio.h>
+
+#include "keyb.h"
+#include "vga.h"
+#include "text.h"
+#include "map.h"
+#include "data.h"
+
+#include "game.h"
+
+static uint32_t hiscore = 15000;
+
+static uint8_t hud;
+
+/* game variables */
+static uint8_t lives;
+static uint32_t score;
+static uint8_t stage;
+static uint8_t gold;
+
+void hud_render()
+{
+ char b[32];
+
+ if (hud & HUD_ALL)
+ {
+ Rect src = { 128, 32, 144, 144};
+ Rect dst = { 0, 0, 16, 16};
+
+ /* lives */
+ blitrc(binary_sprites_start, &src, &dst);
+
+ put_text(132, 4, "TIME");
+ put_text(256, 4, "STAGE");
+ }
+
+ if (hud & HUD_LIVES)
+ {
+ sprintf(b, "%d", lives);
+ put_text(14, 4, b);
+ }
+
+ if (hud & HUD_SCORE)
+ {
+ sprintf(b, "%06li", score);
+ put_text(30, 4, b);
+ }
+
+ if (hud & HUD_TIME)
+ {
+ sprintf(b, "%02d", 0);
+ put_text(172, 4, b);
+ }
+
+ if (hud & HUD_STAGE)
+ {
+ sprintf(b, "%02d", stage);
+ put_text(304, 4, b);
+ }
+
+ hud = HUD_CLEAN;
+}
+
+void run_game()
+{
+ lives = GAME_LIVES_START;
+ score = 0;
+ stage = 0;
+ gold = 30;
+
+ hud = HUD_ALL;
+
+ map_init(binary_stage_start);
+ map_render();
+
+ while (!keys[KEY_ESC])
+ {
+ if (hud)
+ hud_render();
+
+ wait_vsync();
+ blit_update();
+ }
+}