From 07e829e591394fa182e75ecab86051f1fb850ce7 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 15 Jun 2023 22:35:39 +0100 Subject: Started with the game Added hud (WIP) --- TODO.md | 17 +++++-------- src/game.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/game.h | 16 ++++++++++++ src/main.c | 10 ++------ 4 files changed, 109 insertions(+), 19 deletions(-) create mode 100644 src/game.c create mode 100644 src/game.h diff --git a/TODO.md b/TODO.md index 61a5fc5..4da9e0b 100644 --- a/TODO.md +++ b/TODO.md @@ -1,19 +1,12 @@ # TODO -- map - - collision detection - - deadly blocks - entity system - free/used lists - player -- hud - - lives - - score - - time - - stage - - hi-score - - gold left? - - pickaxe? +- timer + - clock +- map + - entities - pick ups - gold - extra time @@ -38,4 +31,6 @@ # REVIEW +- hud + - pickaxe? - use dosemu instead of dosbox? 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 +#include + +#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(); + } +} diff --git a/src/game.h b/src/game.h new file mode 100644 index 0000000..e8c270e --- /dev/null +++ b/src/game.h @@ -0,0 +1,16 @@ +#ifndef _GAME_H +#define _GAME_H + +#define GAME_LIVES_START 3 +#define GAME_LIVES_MAX 9 + +#define HUD_CLEAN 0 +#define HUD_LIVES 1 +#define HUD_SCORE 2 +#define HUD_STAGE 4 +#define HUD_TIME 8 +#define HUD_ALL 255 + +void run_game(); + +#endif /* _GAME_H */ diff --git a/src/main.c b/src/main.c index 9985159..306f5f1 100644 --- a/src/main.c +++ b/src/main.c @@ -6,9 +6,8 @@ #include "keyb.h" #include "vga.h" -#include "text.h" -#include "map.h" #include "data.h" +#include "game.h" /* disable paging because our int handlers are written in C */ int _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY; @@ -36,14 +35,9 @@ int main(int argc, char *argv[]) blit_erase(0); wait_vsync(); - - map_init(binary_stage_start); - map_render(); - blit_update(); - while (!keys[KEY_ESC]) - wait_vsync(); + run_game(); set_mode(3); close_framebuffer(); -- cgit v1.2.3