From be4d0d51de69a015a06bd6eb80953d9f5f563096 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Wed, 12 Feb 2025 17:55:21 -0500 Subject: [PATCH] Two main GUI elements are placed for the left side status and the bottom combat UIs. --- constants.hpp | 2 +- gui.cpp | 101 +++++++++++++++++++++++++++++++++++++++-------- gui.hpp | 33 ++++++++++++++++ worldbuilder.cpp | 14 +++---- 4 files changed, 123 insertions(+), 27 deletions(-) diff --git a/constants.hpp b/constants.hpp index 1c9b656..9f4172f 100644 --- a/constants.hpp +++ b/constants.hpp @@ -32,7 +32,7 @@ constexpr int WALL_LIGHT_LEVEL = 3; constexpr int WORLDBUILD_DIVISION = 4; constexpr int WORLDBUILD_SHRINK = 2; constexpr int WORLDBUILD_MAX_PATH = 200; -constexpr int UI_FONT_SIZE=30; +constexpr int UI_FONT_SIZE=20; constexpr int BASE_MAP_FONT_SIZE=90; constexpr int GAME_MAP_PIXEL_POS = 600; constexpr int MAX_FONT_SIZE = 140; diff --git a/gui.cpp b/gui.cpp index e8d0467..130f8fe 100644 --- a/gui.cpp +++ b/gui.cpp @@ -7,15 +7,71 @@ #include #include "systems.hpp" #include "map_view.hpp" +#include // for hflow, paragraph, separator, hbox, vbox, filler, operator|, border, Element +#include // for Render +#include // for ftxui +#include +#include +#include using namespace components; +using namespace ftxui; namespace gui { + + void StatusUI::create_render() { + auto player = $level.world->get_the(); + + auto status_rend = Renderer([&, player]{ + const auto& player_combat = $level.world->get(player.entity); + const auto& combat = $level.world->get(player.entity); + + std::vector log_list; + log_list.push_back(text("Log messages here.")); + + auto log_box = vbox(log_list) | yflex_grow; + + return hbox({ + hflow( + vbox( + text(fmt::format("HP: {: >3} DMG: {: >3}", + player_combat.hp, + combat.damage)), + separator(), + log_box + ) | flex_grow + ) + }); + }); + + set_renderer(status_rend); + } + + void CombatUI::create_render() { + auto player = $level.world->get_the(); + + auto combat_rend = Renderer([&, player]{ + const auto& player_combat = $level.world->get(player.entity); + const auto& combat = $level.world->get(player.entity); + + return hbox({ + text(fmt::format("HP: {: >3} DMG: {: >3}", + player_combat.hp, + combat.damage)) | flex_grow + }); + }); + + set_renderer(combat_rend); + } + + FSM::FSM() : $window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"), $renderer($window), $level($levels.current()), $map_view($level), + $combat_view($level), + $status_view($level), $font{FONT_FILE_NAME}, $text{$font}, $rayview($textures, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT) @@ -47,10 +103,14 @@ namespace gui { $rayview.set_position(RAY_VIEW_X, RAY_VIEW_Y); $rayview.position_camera($player.x + 0.5, $player.y + 0.5); + $status_view.create_render(); + $combat_view.create_render(); + $renderer.init_terminal(); $map_view.create_render(); $map_view.resize_canvas(); $renderer.resize_grid(MAX_FONT_SIZE, $map_view); + run_systems(); state(State::IDLE); } @@ -87,7 +147,6 @@ namespace gui { // just do 10 ticks if($rotation_count % 10 == 0) { run_systems(); - $rayview.$anim.play(false); $rotation = -10.0f; state(State::IDLE); } @@ -219,21 +278,7 @@ namespace gui { $window.draw(*weapon); } - void FSM::draw_gui() { - sf::RectangleShape rect({SCREEN_WIDTH - RAY_VIEW_WIDTH, SCREEN_HEIGHT}); - rect.setPosition({0,0}); - rect.setFillColor({30, 30, 30}); - $window.draw(rect); - - auto left_gui = $textures.sprite_textures.at("left_gui").sprite; - left_gui->setPosition({0,0}); - $window.draw(*left_gui); - - sf::RectangleShape lower({RAY_VIEW_WIDTH, SCREEN_HEIGHT - RAY_VIEW_HEIGHT}); - lower.setPosition({RAY_VIEW_X,RAY_VIEW_HEIGHT}); - lower.setFillColor({40, 40, 40}); - $window.draw(lower); - + void FSM::draw_stats() { auto player = $level.world->get_the(); auto player_combat = $level.world->get(player.entity); @@ -255,7 +300,29 @@ namespace gui { FRAME_LIMIT, DEBUG_BUILD, $rayview.$dir_x, $rayview.$dir_y, $rayview.$pos_x, $rayview.$pos_y)); - // $window.draw($text); + $window.draw($text); + } + + void FSM::draw_gui() { + sf::RectangleShape rect({SCREEN_WIDTH - RAY_VIEW_WIDTH, SCREEN_HEIGHT}); + rect.setPosition({0,0}); + rect.setFillColor({30, 30, 30}); + $window.draw(rect); + + auto left_gui = $textures.sprite_textures.at("left_gui").sprite; + left_gui->setPosition({0,0}); + $window.draw(*left_gui); + + sf::RectangleShape lower({RAY_VIEW_WIDTH, SCREEN_HEIGHT - RAY_VIEW_HEIGHT}); + lower.setPosition({RAY_VIEW_X,RAY_VIEW_HEIGHT}); + lower.setFillColor({30, 30, 30}); + $window.draw(lower); + + $status_view.render(); + $renderer.draw($status_view); + + $combat_view.render(); + $renderer.draw($combat_view); } void FSM::render() { diff --git a/gui.hpp b/gui.hpp index d034c7c..e58fcd5 100644 --- a/gui.hpp +++ b/gui.hpp @@ -9,6 +9,36 @@ #include "map_view.hpp" namespace gui { + class StatusUI : public Panel { + public: + GameLevel $level; + + StatusUI(GameLevel level) : + Panel(43, 200, 29, 25, false), + $level(level) + { + default_bg = sf::Color{30,30,30}; + } + + void create_render(); + void update_level(GameLevel &level) { $level = level; } + }; + + class CombatUI : public Panel { + public: + GameLevel $level; + + CombatUI(GameLevel level) : + Panel(RAY_VIEW_X, RAY_VIEW_HEIGHT, 89, 6, false), + $level(level) + { + default_bg = sf::Color{30,30,30}; + } + + void create_render(); + void update_level(GameLevel &level) { $level = level; } + }; + enum class State { START, MOVING, @@ -45,6 +75,8 @@ namespace gui { SFMLRender $renderer; GameLevel $level; MapViewUI $map_view; + CombatUI $combat_view; + StatusUI $status_view; CameraLOL $camera; sf::Font $font; sf::Text $text; @@ -67,6 +99,7 @@ namespace gui { void try_move(int dir, bool strafe); void keyboard(); void draw_weapon(); + void draw_stats(); void draw_gui(); void render(); void mouse(); diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 487e6bc..e7f36a3 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -336,21 +336,17 @@ inline void straight_path(Map &map, PointList &holes, Point src, Point target) { } void WorldBuilder::tunnel_doors(PointList &holes, Room &src, Room &target) { - int path_type = Random::uniform(0, 3); + int path_type = Random::uniform(0, 10); switch(path_type) { case 0: - // for now do 25% as simple straight paths - straight_path($map, holes, src.exit, target.entry); - break; - case 1: - // for now do 25% as simple straight paths - straight_path($map, holes, src.exit, target.entry); - break; - default: // then do the rest as random with fallback if(!random_path($map, holes, src.exit, target.entry)) { straight_path($map, holes, src.exit, target.entry); } + break; + default: + // for now do 25% as simple straight paths + straight_path($map, holes, src.exit, target.entry); } }