diff options
author | quou <quou@disroot.org> | 2023-05-06 15:50:31 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2023-05-06 15:50:31 +1000 |
commit | ec51d32ea0a30c138e690f637f38d83c086e02b9 (patch) | |
tree | 95570a567cc34ef5255a845391178d8649cd56a4 /game.c | |
parent | 9e28af25b8fb5c9474ccbec2bd4dff26f1871075 (diff) |
Add the main mechanic.
Diffstat (limited to 'game.c')
-rw-r--r-- | game.c | 91 |
1 files changed, 68 insertions, 23 deletions
@@ -96,47 +96,76 @@ static void menu_deinit(Game* game) { } static void gameplay_init(Game* game) { + World* world; + + world = &game->world; + seed_rng(500); init_world(&game->world); - init_map(&game->world.map, &game->world); - init_player(&game->world.player, &game->world); - new_skull(&game->world, 0, 0); + init_map(&world->map, world); + init_player(&world->player, world); + new_skull(world, 0, 0); + + world->gmemory = gmemory_max; } static void render_hud(Game* game) { - int i; - const Sprite* heart_sprite; - const Bitmap* heart_bitmap; + int i, g; + const Sprite* sprite; + const Bitmap* bitmap; World* world; Player* player; world = &game->world; player = &world->player; - heart_sprite = get_sprite(sprite_heart_full); - heart_bitmap = get_bitmap(heart_sprite->bitmap); + sprite = get_sprite(sprite_heart_full); + bitmap = get_bitmap(sprite->bitmap); for (i = 0; i < player->hp; i++) { render_bitmap( - heart_bitmap, - 1 + i * (heart_sprite->rect.w + 1), + bitmap, + 1 + i * (sprite->rect.w + 1), 1, - &heart_sprite->rect + &sprite->rect ); } - heart_sprite = get_sprite(sprite_heart_empty); - heart_bitmap = get_bitmap(heart_sprite->bitmap); + sprite = get_sprite(sprite_heart_empty); + bitmap = get_bitmap(sprite->bitmap); for (; i < player_max_hp; i++) { render_bitmap( - heart_bitmap, - 1 + i * (heart_sprite->rect.w + 1), + bitmap, + 1 + i * (sprite->rect.w + 1), 1, - &heart_sprite->rect + &sprite->rect + ); + } + + sprite = get_sprite(sprite_ram_full); + bitmap = get_bitmap(sprite->bitmap); + g = world->gmemory / gmemory_units; + for (i = 0; i < g; i++) { + render_bitmap( + bitmap, + 1 + i * (sprite->rect.w + 1), + 8, + &sprite->rect + ); + } + sprite = get_sprite(sprite_ram_empty); + bitmap = get_bitmap(sprite->bitmap); + g = gmemory_max / gmemory_units; + for (; i < g; i++) { + render_bitmap( + bitmap, + 1 + i * (sprite->rect.w + 1), + 8, + &sprite->rect ); } } static void gameplay_update(Game* game) { - int cx, cy, i; + int cx, cy; World* world; Player* player; cx = game->world.cam_x; @@ -155,6 +184,11 @@ static void gameplay_update(Game* game) { sprite_system(world); render_hud(game); + + if (world->gmemory <= 0) { + world->oom = 1; + game_change_state(game, game_state_dead); + } } static void gameplay_deinit(Game* game) { @@ -183,8 +217,10 @@ static void dead_init(Game* game) { static void dead_update(Game* game) { const BM_Font* font; int cx, cy; + World* world; font = get_default_font(); + world = &game->world; update_menu(&game->menu); @@ -193,12 +229,21 @@ static void dead_update(Game* game) { render_map(&game->world.map, cx, cy); sprite_system(&game->world); - rfont_text( - font, - renderer_w / 2 - 40, - game->menu.y - 15, - "You died" - ); + if (world->oom) { + rfont_text( + font, + renderer_w / 2 - 65, + game->menu.y - 15, + "Out of Memory" + ); + } else { + rfont_text( + font, + renderer_w / 2 - 40, + game->menu.y - 15, + "You died" + ); + } render_menu(&game->menu, get_default_font()); } |