diff --git a/assets/config.json b/assets/config.json index 41d4c80..12cd51f 100644 --- a/assets/config.json +++ b/assets/config.json @@ -39,7 +39,7 @@ "player": { }, "worldgen": { - "enemy_probability": 30, + "enemy_probability": 50, "empty_room_probability": 10, "device_probability": 10 } diff --git a/assets/down_the_well.jpg b/assets/down_the_well.jpg index 6208691..7630d93 100644 Binary files a/assets/down_the_well.jpg and b/assets/down_the_well.jpg differ diff --git a/constants.hpp b/constants.hpp index 52cb9b7..2bd01fa 100644 --- a/constants.hpp +++ b/constants.hpp @@ -42,7 +42,7 @@ constexpr int WORLDBUILD_DIVISION = 4; constexpr int WORLDBUILD_SHRINK = 2; constexpr int WORLDBUILD_MAX_PATH = 200; constexpr int UI_FONT_SIZE=20; -constexpr int BASE_MAP_FONT_SIZE=90; +constexpr int BASE_MAP_FONT_SIZE=80; constexpr int GAME_MAP_PIXEL_POS = 600; constexpr int MAX_FONT_SIZE = 140; constexpr int MIN_FONT_SIZE = 20; diff --git a/easings.hpp b/easings.hpp new file mode 100644 index 0000000..b17577c --- /dev/null +++ b/easings.hpp @@ -0,0 +1,40 @@ +#pragma once +#include + +namespace ease { + + inline double sine(double x) { + return (std::sin(x) + 1.0) / 2.0; + } + + inline double out_circ(double x) { + return std::sqrt(1.0f - std::pow(x - 1.0f, 2.0f)); + } + + inline double out_bounce(double x) { + constexpr const double n1 = 7.5625; + constexpr const double d1 = 2.75; + + if (x < 1 / d1) { + return n1 * x * x; + } else if (x < 2 / d1) { + x -= 1.5; + return n1 * (x / d1) * x + 0.75; + } else if (x < 2.5 / d1) { + x -= 2.25; + return n1 * (x / d1) * x + 0.9375; + } else { + x -= 2.625; + return n1 * (x / d1) * x + 0.984375; + } + } + + inline double in_out_back(double x) { + constexpr const double c1 = 1.70158; + constexpr const double c2 = c1 * 1.525; + + return x < 0.5 + ? (std::pow(2.0 * x, 2.0) * ((c2 + 1.0) * 2.0 * x - c2)) / 2.0 + : (std::pow(2.0 * x - 2.0, 2.0) * ((c2 + 1.0) * (x * 2.0 - 2.0) + c2) + 2.0) / 2.0; + } +} diff --git a/gui_fsm.cpp b/gui_fsm.cpp index bb5db2f..d2cc9dc 100644 --- a/gui_fsm.cpp +++ b/gui_fsm.cpp @@ -53,7 +53,7 @@ namespace gui { $renderer.init_terminal(); $map_ui.create_render(); $map_ui.resize_canvas(); - $renderer.resize_grid(MAX_FONT_SIZE, $map_ui); + $renderer.resize_grid(BASE_MAP_FONT_SIZE, $map_ui); run_systems(); state(State::IDLE); @@ -133,21 +133,21 @@ namespace gui { try_move(-1, false); break; case MOVE_LEFT: - try_move(1, true); + try_move(-1, true); break; case MOVE_RIGHT: - try_move(-1, true); + try_move(1, true); break; case ROTATE_LEFT: - $main_ui.plan_rotate(1); + $main_ui.plan_rotate(-1); state(State::ROTATING); break; case ROTATE_RIGHT: - $main_ui.plan_rotate(-1); + $main_ui.plan_rotate(1); state(State::ROTATING); break; case MAP_OPEN: - $renderer.resize_grid(MAX_FONT_SIZE, $map_ui); + $renderer.resize_grid(BASE_MAP_FONT_SIZE, $map_ui); $map_ui.resize_canvas(); state(State::MAPPING); break; @@ -196,11 +196,11 @@ namespace gui { state(State::ATTACKING); break; case ROTATE_LEFT: - $main_ui.plan_rotate(1); + $main_ui.plan_rotate(-1); state(State::COMBAT_ROTATE); break; case ROTATE_RIGHT: - $main_ui.plan_rotate(-1); + $main_ui.plan_rotate(1); state(State::COMBAT_ROTATE); break; case STOP_COMBAT: diff --git a/levelmanager.cpp b/levelmanager.cpp index 76893fa..fe72a1c 100644 --- a/levelmanager.cpp +++ b/levelmanager.cpp @@ -16,8 +16,8 @@ LevelManager::LevelManager() { LevelScaling LevelManager::scale_level() { return { - 30 + (5 * int($current_level)), - 20 + (5 * int($current_level)) + 20 + (5 * int($current_level)), + 15 + (5 * int($current_level)) }; } diff --git a/main_ui.cpp b/main_ui.cpp index c01d61f..c395a21 100644 --- a/main_ui.cpp +++ b/main_ui.cpp @@ -1,5 +1,6 @@ #include "main_ui.hpp" #include "components.hpp" +#include "easings.hpp" namespace gui { using namespace components; @@ -43,13 +44,15 @@ namespace gui { "sdev: {:>8.5}\n" "min: {:>8.5}\n" "max: {:>8.5}\n" - "count:{:<10}\n\n" + "count:{:<10}\n" "level: {} size: {}x{}\n\n" + "dir: {:0.2},{:0.2}\n\n" "VSync? {}\n" "FR Limit: {}\n" "Debug? {}\n\n", player_combat.hp, $stats.mean(), $stats.stddev(), $stats.min, $stats.max, $stats.n, $level.index, map->width(), map->height(), + $rayview.$dir_x, $rayview.$dir_y, VSYNC, FRAME_LIMIT, DEBUG_BUILD); $overlay_ui.update_text("top_left", stats); @@ -70,9 +73,13 @@ namespace gui { $rayview.set_position(RAY_VIEW_X, RAY_VIEW_Y); $rayview.position_camera($player.x + 0.5, $player.y + 0.5); + $overlay_ui.show_label("top", $compass[$compass_dir]); + auto st = textures::get("down_the_well"); - st.sprite->setPosition({RAY_VIEW_X, RAY_VIEW_Y}); - st.sprite->setScale({0.5, 0.5}); + auto bounds = st.sprite->getLocalBounds(); + st.sprite->setPosition({RAY_VIEW_X + bounds.size.x / 2, + RAY_VIEW_Y + bounds.size.y / 2}); + st.sprite->setOrigin({bounds.size.x / 2, bounds.size.y / 2}); $overlay_ui.render(); } @@ -81,11 +88,18 @@ namespace gui { $show_level = true; } + + void MainUI::draw() { - auto start = std::chrono::high_resolution_clock::now(); + auto start = $stats.time_start(); if($show_level) { + auto time = $clock.getElapsedTime(); auto st = textures::get("down_the_well"); + float tick = ease::in_out_back(ease::sine(time.asSeconds())); + float scale = std::lerp(1.0, 1.3, tick); + st.sprite->setScale({scale, scale}); + $window.draw(*st.sprite); $overlay_ui.show_label("middle", "INTO THE WELL YOU GO..."); } else { @@ -93,9 +107,7 @@ namespace gui { $rayview.draw($window); } - auto end = std::chrono::high_resolution_clock::now(); - auto elapsed = std::chrono::duration(end - start); - $stats.sample(1/elapsed.count()); + $stats.sample_time(start); $overlay_ui.draw($window); @@ -125,6 +137,9 @@ namespace gui { } void MainUI::plan_rotate(int dir) { + // -1 is left, 1 is right + $compass_dir = ($compass_dir + dir) % $compass.size(); + $overlay_ui.update_label("top", $compass[$compass_dir]); $camera.plan_rotate($rayview, dir); } @@ -151,9 +166,12 @@ namespace gui { } void MainUI::mouse(int x, int y) { - $show_level = false; - $level.world->send(Events::GUI::STAIRS_DOWN, $level.player, {}); - $overlay_ui.close_label("middle"); - $overlay_ui.$gui.mouse(x, y); + if($show_level) { + $show_level = false; + $level.world->send(Events::GUI::STAIRS_DOWN, $level.player, {}); + $overlay_ui.close_label("middle"); + } else { + $overlay_ui.$gui.mouse(x, y); + } } } diff --git a/main_ui.hpp b/main_ui.hpp index f0bd2f9..184e034 100644 --- a/main_ui.hpp +++ b/main_ui.hpp @@ -1,6 +1,7 @@ #pragma once #include "levelmanager.hpp" #include +#include #include "stats.hpp" #include "overlay_ui.hpp" #include "raycaster.hpp" @@ -11,10 +12,15 @@ namespace gui { class MainUI { public: + int $compass_dir = 0; + std::array $compass{ + "E", "SE", "S", "SW", "W", "NW", "N", "NE" + }; bool $show_level = false; bool $needs_render = true; Point $player{0,0}; Stats $stats; + sf::Clock $clock; sf::RenderWindow& $window; GameLevel $level; OverlayUI $overlay_ui; diff --git a/map_view.cpp b/map_view.cpp index 074066a..fbd1bec 100644 --- a/map_view.cpp +++ b/map_view.cpp @@ -10,7 +10,8 @@ namespace gui { MapViewUI::MapViewUI(GameLevel &level) : Panel(0, 0, 0, 0, true), $level(level) - {} + { + } void MapViewUI::update_level(GameLevel &level) { $level = level; diff --git a/meson.build b/meson.build index c908058..45b95d8 100644 --- a/meson.build +++ b/meson.build @@ -40,7 +40,7 @@ dependencies = [ ] if build_machine.system() == 'windows' -sfml_main = dependency('sfml_main') + sfml_main = dependency('sfml_main') opengl32 = cc.find_library('opengl32', required: true) winmm = cc.find_library('winmm', required: true) gdi32 = cc.find_library('gdi32', required: true) diff --git a/overlay_ui.cpp b/overlay_ui.cpp index 2c1233a..24ccf4b 100644 --- a/overlay_ui.cpp +++ b/overlay_ui.cpp @@ -56,6 +56,13 @@ namespace gui { } } + void OverlayUI::update_label(string region, string content) { + auto ent = $gui.entity(region); + if(auto text = $gui.get_if