Initial idea for the boss fight UI but it's just a temporary holder for now.
This commit is contained in:
parent
a72d2879fd
commit
64807174c0
16 changed files with 165 additions and 36 deletions
|
@ -32,7 +32,8 @@
|
|||
"trash_button": "assets/trash_button.png",
|
||||
"axe_ranger": "assets/axe_ranger-256.png",
|
||||
"hairy_spider": "assets/hairy_spider-256.png",
|
||||
"down_the_well": "assets/down_the_well.jpg"
|
||||
"down_the_well": "assets/down_the_well.jpg",
|
||||
"boss_fight": "assets/rat-king-boss-fight-test-small.jpg"
|
||||
},
|
||||
"enemy": {
|
||||
"HEARING_DISTANCE": 5
|
||||
|
|
BIN
assets/rat-king-boss-fight-test-small.jpg
Normal file
BIN
assets/rat-king-boss-fight-test-small.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 211 KiB |
|
@ -7,7 +7,7 @@
|
|||
"display":"\u289e"
|
||||
},
|
||||
"WALL_PLAIN": {
|
||||
"texture": "assets/wall_simple-256.png",
|
||||
"texture": "assets/wall_texture_test-256.png",
|
||||
"foreground": [230, 20, 30],
|
||||
"background": [230, 20, 120],
|
||||
"collision": true,
|
||||
|
@ -19,12 +19,5 @@
|
|||
"background": [230, 20, 120],
|
||||
"collision": false,
|
||||
"display":"\u0799"
|
||||
},
|
||||
"WALL_PILLAR": {
|
||||
"texture": "assets/wall_with_pillars-256.png",
|
||||
"foreground": [230, 20, 30],
|
||||
"background": [230, 20, 120],
|
||||
"collision": false,
|
||||
"display":"\u2274"
|
||||
}
|
||||
}
|
||||
|
|
82
boss_fight_ui.cpp
Normal file
82
boss_fight_ui.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include "boss_fight_ui.hpp"
|
||||
#include "easings.hpp"
|
||||
|
||||
namespace gui {
|
||||
BossFightUI::BossFightUI() {
|
||||
$status.position(0, 0, 300, SCREEN_HEIGHT);
|
||||
$status.layout(
|
||||
"[(150)status_1|(150)status_2]"
|
||||
"[(150)status_3|(150)status_4]"
|
||||
"[(150)status_5|(150)status_6]"
|
||||
"[(150)status_7|(150)status_8]"
|
||||
);
|
||||
|
||||
$overlay.position(300, 0, SCREEN_WIDTH - 300, SCREEN_HEIGHT);
|
||||
$overlay.layout("[overlay_1|overlay_2|overlay_3|overlay_4]"
|
||||
"[overlay_5|overlay_6|overlay_7|overlay_8]"
|
||||
"[overlay_9|overlay_10|overlay_11|overlay_12]"
|
||||
"[overlay_13|overlay_14|overlay_15|overlay_16]");
|
||||
|
||||
$boss_image = textures::get("boss_fight");
|
||||
auto bounds = $boss_image.sprite->getLocalBounds();
|
||||
$boss_image.sprite->setPosition({300 + bounds.size.x / 2, bounds.size.y / 2});
|
||||
$boss_image.sprite->setOrigin({bounds.size.x / 2, bounds.size.y / 2});
|
||||
}
|
||||
|
||||
void BossFightUI::init() {
|
||||
$status.world().set_the<Background>({$status.$parser});
|
||||
|
||||
for(auto& [name, cell] : $status.cells()) {
|
||||
auto button = $status.entity(name);
|
||||
$status.set<Rectangle>(button, {});
|
||||
$status.set<Clickable>(button, {
|
||||
[this, name](auto, auto){ fmt::println("STATUS: {}", name); }
|
||||
});
|
||||
$status.set<Label>(button, {name});
|
||||
}
|
||||
$status.init();
|
||||
|
||||
for(auto& [name, cell] : $overlay.cells()) {
|
||||
auto region = $overlay.entity(name);
|
||||
$overlay.set<Clickable>(region, {
|
||||
[this, name](auto, auto){ fmt::println("OVERLAY: {}", name); }
|
||||
});
|
||||
}
|
||||
|
||||
auto region = $overlay.entity("overlay_2");
|
||||
$overlay.set<Label>(region, {"THE RAT KING!"});
|
||||
$overlay.init();
|
||||
}
|
||||
|
||||
void BossFightUI::bounce_boss(sf::RenderWindow& window) {
|
||||
auto time = $clock.getElapsedTime();
|
||||
float tick = ease::in_out_back(ease::sine(time.asSeconds()));
|
||||
float scale = std::lerp(1.1, 1.3, tick);
|
||||
$boss_image.sprite->setScale({scale, scale});
|
||||
window.draw(*$boss_image.sprite);
|
||||
}
|
||||
|
||||
void BossFightUI::render(sf::RenderWindow& window) {
|
||||
if($boss_hit) {
|
||||
bounce_boss(window);
|
||||
} else {
|
||||
window.draw(*$boss_image.sprite);
|
||||
}
|
||||
|
||||
$status.render(window);
|
||||
$overlay.render(window);
|
||||
}
|
||||
|
||||
bool BossFightUI::mouse(float x, float y) {
|
||||
if($status.mouse(x, y)) {
|
||||
fmt::println("STATUS");
|
||||
}
|
||||
|
||||
if($overlay.mouse(x, y)) {
|
||||
fmt::println("OVERLAY");
|
||||
$boss_hit = !$boss_hit;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
34
boss_fight_ui.hpp
Normal file
34
boss_fight_ui.hpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
#include "levelmanager.hpp"
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include "guecs.hpp"
|
||||
#include "textures.hpp"
|
||||
#include <SFML/System/Clock.hpp>
|
||||
|
||||
// aspect ratio of art is 3/2 so 1.5
|
||||
// possible sizes: 900/600; 1620/1080; 1800/1200
|
||||
// To calculate it do short side * 1.5 so 1080 * 1.5 == 1620
|
||||
//
|
||||
// Side panel = 300/1080
|
||||
|
||||
namespace gui {
|
||||
using namespace guecs;
|
||||
using std::string;
|
||||
|
||||
class BossFightUI {
|
||||
public:
|
||||
sf::Clock $clock;
|
||||
bool $boss_hit = false;
|
||||
guecs::UI $status;
|
||||
guecs::UI $overlay;
|
||||
textures::SpriteTexture $boss_image;
|
||||
|
||||
BossFightUI();
|
||||
|
||||
void init();
|
||||
void render(sf::RenderWindow& window);
|
||||
bool mouse(float x, float y);
|
||||
void bounce_boss(sf::RenderWindow& window);
|
||||
};
|
||||
}
|
|
@ -15,7 +15,7 @@ namespace gui {
|
|||
"[ >.%(100,50)label_hp | *%.(198,50)bar_hp | _ ]");
|
||||
}
|
||||
|
||||
void CombatUI::render() {
|
||||
void CombatUI::init() {
|
||||
auto& world = $gui.world();
|
||||
|
||||
world.set_the<Background>({$gui.$parser});
|
||||
|
@ -40,7 +40,7 @@ namespace gui {
|
|||
$gui.init();
|
||||
}
|
||||
|
||||
void CombatUI::draw(sf::RenderWindow& window) {
|
||||
void CombatUI::render(sf::RenderWindow& window) {
|
||||
auto& player_combat = $level.world->get<components::Combat>($level.player);
|
||||
set_damage(float(player_combat.hp) / float(player_combat.max_hp));
|
||||
$gui.render(window);
|
||||
|
@ -53,6 +53,6 @@ namespace gui {
|
|||
|
||||
void CombatUI::update_level(GameLevel &level) {
|
||||
$level = level;
|
||||
render();
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ namespace gui {
|
|||
|
||||
CombatUI(GameLevel level);
|
||||
|
||||
void render();
|
||||
void draw(sf::RenderWindow& window);
|
||||
void init();
|
||||
void render(sf::RenderWindow& window);
|
||||
void update_level(GameLevel &level);
|
||||
void set_damage(float percent);
|
||||
};
|
||||
|
|
28
gui_fsm.cpp
28
gui_fsm.cpp
|
@ -45,10 +45,11 @@ namespace gui {
|
|||
|
||||
$main_ui.init();
|
||||
|
||||
$combat_ui.render();
|
||||
$status_ui.render();
|
||||
$combat_ui.init();
|
||||
$status_ui.init();
|
||||
$status_ui.log("Welcome to the game!");
|
||||
$status_ui.update();
|
||||
$boss_fight_ui.init();
|
||||
|
||||
$renderer.init_terminal();
|
||||
$map_ui.create_render();
|
||||
|
@ -162,7 +163,7 @@ namespace gui {
|
|||
dbc::log("Nothing to close.");
|
||||
break;
|
||||
case STAIRS_DOWN:
|
||||
$main_ui.show_level();
|
||||
// $main_ui.show_level();
|
||||
state(State::NEXT_LEVEL);
|
||||
break;
|
||||
case STOP_COMBAT:
|
||||
|
@ -243,11 +244,15 @@ namespace gui {
|
|||
if(const auto* mouse = ev->getIf<sf::Event::MouseButtonPressed>()) {
|
||||
if(mouse->button == sf::Mouse::Button::Left) {
|
||||
sf::Vector2f pos = $window.mapPixelToCoords(mouse->position);
|
||||
if(in_state(State::NEXT_LEVEL)) {
|
||||
$boss_fight_ui.mouse(pos.x, pos.y);
|
||||
} else {
|
||||
$combat_ui.$gui.mouse(pos.x, pos.y);
|
||||
$status_ui.$gui.mouse(pos.x, pos.y);
|
||||
$main_ui.mouse(pos.x, pos.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(const auto* key = ev->getIf<sf::Event::KeyPressed>()) {
|
||||
using KEY = sf::Keyboard::Scan;
|
||||
|
@ -290,6 +295,9 @@ namespace gui {
|
|||
case KEY::O:
|
||||
autowalking = true;
|
||||
break;
|
||||
case KEY::L:
|
||||
event(Event::STAIRS_DOWN);
|
||||
break;
|
||||
default:
|
||||
break; // ignored
|
||||
}
|
||||
|
@ -298,9 +306,13 @@ namespace gui {
|
|||
}
|
||||
|
||||
void FSM::draw_gui() {
|
||||
$main_ui.draw();
|
||||
$status_ui.draw($window);
|
||||
$combat_ui.draw($window);
|
||||
if(in_state(State::NEXT_LEVEL)) {
|
||||
$boss_fight_ui.render($window);
|
||||
} else {
|
||||
$main_ui.render();
|
||||
$status_ui.render($window);
|
||||
$combat_ui.render($window);
|
||||
}
|
||||
}
|
||||
|
||||
void FSM::render() {
|
||||
|
@ -308,6 +320,10 @@ namespace gui {
|
|||
$window.clear();
|
||||
$map_ui.render();
|
||||
$renderer.draw($map_ui);
|
||||
} else if(in_state(State::NEXT_LEVEL)) {
|
||||
$window.clear();
|
||||
$boss_fight_ui.init();
|
||||
$boss_fight_ui.render($window);
|
||||
} else {
|
||||
draw_gui();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "combat_ui.hpp"
|
||||
#include "status_ui.hpp"
|
||||
#include "overlay_ui.hpp"
|
||||
#include "boss_fight_ui.hpp"
|
||||
|
||||
namespace gui {
|
||||
enum class State {
|
||||
|
@ -54,6 +55,7 @@ namespace gui {
|
|||
MapViewUI $map_ui;
|
||||
CombatUI $combat_ui;
|
||||
StatusUI $status_ui;
|
||||
BossFightUI $boss_fight_ui;
|
||||
sf::Font $font;
|
||||
|
||||
FSM();
|
||||
|
|
|
@ -84,14 +84,14 @@ namespace gui {
|
|||
RAY_VIEW_Y + bounds.size.y / 2});
|
||||
st.sprite->setOrigin({bounds.size.x / 2, bounds.size.y / 2});
|
||||
|
||||
$overlay_ui.render();
|
||||
$overlay_ui.init();
|
||||
}
|
||||
|
||||
void MainUI::show_level() {
|
||||
$show_level = true;
|
||||
}
|
||||
|
||||
void MainUI::draw() {
|
||||
void MainUI::render() {
|
||||
auto start = $stats.time_start();
|
||||
|
||||
if($show_level) {
|
||||
|
@ -110,7 +110,7 @@ namespace gui {
|
|||
|
||||
$stats.sample_time(start);
|
||||
|
||||
$overlay_ui.draw($window);
|
||||
$overlay_ui.render($window);
|
||||
|
||||
auto debug = $level.world->get_the<Debug>();
|
||||
if(debug.FPS) draw_stats();
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace gui {
|
|||
void update_level(GameLevel level);
|
||||
|
||||
void init();
|
||||
void draw();
|
||||
void render();
|
||||
void dirty();
|
||||
|
||||
void show_level();
|
||||
|
|
|
@ -54,6 +54,7 @@ endif
|
|||
sources = [
|
||||
'ansi_parser.cpp',
|
||||
'autowalker.cpp',
|
||||
'boss_fight_ui.cpp',
|
||||
'camera.cpp',
|
||||
'combat.cpp',
|
||||
'combat_ui.cpp',
|
||||
|
|
|
@ -19,11 +19,11 @@ namespace gui {
|
|||
);
|
||||
}
|
||||
|
||||
void OverlayUI::render() {
|
||||
void OverlayUI::init() {
|
||||
$gui.init();
|
||||
}
|
||||
|
||||
void OverlayUI::draw(sf::RenderWindow& window) {
|
||||
void OverlayUI::render(sf::RenderWindow& window) {
|
||||
$gui.render(window);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ namespace gui {
|
|||
|
||||
OverlayUI();
|
||||
|
||||
void render();
|
||||
void draw(sf::RenderWindow& window);
|
||||
void init();
|
||||
void render(sf::RenderWindow& window);
|
||||
void click(int x, int y);
|
||||
void show_sprite(string region, string sprite_name);
|
||||
void close_sprite(string region);
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
void StatusUI::render() {
|
||||
void StatusUI::init() {
|
||||
$gui.world().set_the<Background>({$gui.$parser});
|
||||
|
||||
for(auto& [name, cell] : $gui.cells()) {
|
||||
|
@ -112,7 +112,7 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
void StatusUI::draw(sf::RenderWindow &window) {
|
||||
void StatusUI::render(sf::RenderWindow &window) {
|
||||
$gui.render(window);
|
||||
}
|
||||
|
||||
|
@ -125,6 +125,6 @@ namespace gui {
|
|||
|
||||
void StatusUI::update_level(GameLevel &level) {
|
||||
$level = level;
|
||||
render();
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ namespace gui {
|
|||
void select_slot(DinkyECS::Entity ent, std::any data);
|
||||
void update_level(GameLevel &level);
|
||||
void log(std::string msg);
|
||||
void render();
|
||||
void draw(sf::RenderWindow &window);
|
||||
void init();
|
||||
void render(sf::RenderWindow &window);
|
||||
void update();
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue