You can now go down stairs to new levels, but when you do you become stairs or a random monster.
This commit is contained in:
parent
c14efee9ea
commit
2825faf038
7 changed files with 100 additions and 49 deletions
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
},
|
},
|
||||||
"worldgen": {
|
"worldgen": {
|
||||||
"enemy_probability": 10,
|
"enemy_probability": 20,
|
||||||
"empty_room_probability": 60,
|
"empty_room_probability": 10,
|
||||||
"device_probability": 100
|
"device_probability": 100
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,13 +58,20 @@ namespace DinkyECS {
|
||||||
template <typename Comp>
|
template <typename Comp>
|
||||||
Comp &get_the() {
|
Comp &get_the() {
|
||||||
auto comp_id = std::type_index(typeid(Comp));
|
auto comp_id = std::type_index(typeid(Comp));
|
||||||
dbc::check($facts.contains(comp_id), "!!!! ATTEMPT to access world fact that hasn't been set yet.");
|
dbc::check($facts.contains(comp_id),
|
||||||
|
fmt::format("!!!! ATTEMPT to access world fact that hasn't been set yet: {}", typeid(Comp).name()));
|
||||||
|
|
||||||
// use .at to get std::out_of_range if fact not set
|
// use .at to get std::out_of_range if fact not set
|
||||||
std::any &res = $facts.at(comp_id);
|
std::any &res = $facts.at(comp_id);
|
||||||
return std::any_cast<Comp&>(res);
|
return std::any_cast<Comp&>(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Comp>
|
||||||
|
bool has_the() {
|
||||||
|
auto comp_id = std::type_index(typeid(Comp));
|
||||||
|
return $facts.contains(comp_id);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Comp>
|
template <typename Comp>
|
||||||
void set(Entity ent, Comp val) {
|
void set(Entity ent, Comp val) {
|
||||||
EntityMap &map = entity_map_for<Comp>();
|
EntityMap &map = entity_map_for<Comp>();
|
||||||
|
|
58
gui.cpp
58
gui.cpp
|
@ -69,8 +69,8 @@ void InventoryUI::create_render() {
|
||||||
$inventory_box = Menu(&$menu_list, &$selected, option);
|
$inventory_box = Menu(&$menu_list, &$selected, option);
|
||||||
|
|
||||||
$inventory_render = Renderer([&] {
|
$inventory_render = Renderer([&] {
|
||||||
auto &player = $world.get_the<Player>();
|
auto &player = $level.world->get_the<Player>();
|
||||||
auto &inventory = $world.get<Inventory>(player.entity);
|
auto &inventory = $level.world->get<Inventory>(player.entity);
|
||||||
update_menu_list(inventory);
|
update_menu_list(inventory);
|
||||||
|
|
||||||
return hbox({
|
return hbox({
|
||||||
|
@ -101,12 +101,12 @@ void InventoryUI::update_menu_list(Inventory& inventory) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusUI::create_render() {
|
void StatusUI::create_render() {
|
||||||
auto player = $world.get_the<Player>();
|
auto player = $level.world->get_the<Player>();
|
||||||
|
|
||||||
auto status_rend = Renderer([&, player]{
|
auto status_rend = Renderer([&, player]{
|
||||||
const auto& player_combat = $world.get<Combat>(player.entity);
|
const auto& player_combat = $level.world->get<Combat>(player.entity);
|
||||||
const auto& inventory = $world.get<Inventory>(player.entity);
|
const auto& inventory = $level.world->get<Inventory>(player.entity);
|
||||||
const auto& combat = $world.get<Combat>(player.entity);
|
const auto& combat = $level.world->get<Combat>(player.entity);
|
||||||
$status_text = player_combat.hp > 0 ? "NOT DEAD" : "DEAD!!!!!!";
|
$status_text = player_combat.hp > 0 ? "NOT DEAD" : "DEAD!!!!!!";
|
||||||
|
|
||||||
std::vector<Element> log_list;
|
std::vector<Element> log_list;
|
||||||
|
@ -136,23 +136,27 @@ void StatusUI::create_render() {
|
||||||
set_renderer(status_rend);
|
set_renderer(status_rend);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapViewUI::MapViewUI(DinkyECS::World& world, LightRender& lights, Map& game_map) :
|
MapViewUI::MapViewUI(GameLevel &level) :
|
||||||
Panel(GAME_MAP_PIXEL_POS, 0, 0, 0, true),
|
Panel(GAME_MAP_PIXEL_POS, 0, 0, 0, true),
|
||||||
$world(world), $lights(lights), $game_map(game_map)
|
$level(level)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
void MapViewUI::update_level(GameLevel &level) {
|
||||||
|
$level = level;
|
||||||
|
}
|
||||||
|
|
||||||
void MapViewUI::draw_map() {
|
void MapViewUI::draw_map() {
|
||||||
const auto& debug = $world.get_the<Debug>();
|
const auto& debug = $level.world->get_the<Debug>();
|
||||||
const auto& player = $world.get_the<Player>();
|
const auto& player = $level.world->get_the<Player>();
|
||||||
const auto& player_position = $world.get<Position>(player.entity);
|
const auto& player_position = $level.world->get<Position>(player.entity);
|
||||||
Point start = $game_map.center_camera(player_position.location, width, height);
|
Point start = $level.map->center_camera(player_position.location, width, height);
|
||||||
auto &tiles = $game_map.tiles();
|
auto &tiles = $level.map->tiles();
|
||||||
auto &paths = $game_map.paths();
|
auto &paths = $level.map->paths();
|
||||||
auto &lighting = $lights.lighting();
|
auto &lighting = $level.lights->lighting();
|
||||||
|
|
||||||
// WARN: this is exploiting that -1 in size_t becomes largest
|
// WARN: this is exploiting that -1 in size_t becomes largest
|
||||||
size_t end_x = std::min(size_t(width), $game_map.width() - start.x);
|
size_t end_x = std::min(size_t(width), $level.map->width() - start.x);
|
||||||
size_t end_y = std::min(size_t(height), $game_map.height() - start.y);
|
size_t end_y = std::min(size_t(height), $level.map->height() - start.y);
|
||||||
|
|
||||||
for(size_t y = 0; y < end_y; ++y) {
|
for(size_t y = 0; y < end_y; ++y) {
|
||||||
for(size_t x = 0; x < end_x; ++x)
|
for(size_t x = 0; x < end_x; ++x)
|
||||||
|
@ -178,7 +182,7 @@ void MapViewUI::draw_map() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System::draw_entities($world, $game_map, lighting, $canvas, start, width, height);
|
System::draw_entities(*$level.world, *$level.map, lighting, $canvas, start, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapViewUI::create_render() {
|
void MapViewUI::create_render() {
|
||||||
|
@ -195,9 +199,9 @@ void MapViewUI::resize_canvas() {
|
||||||
|
|
||||||
GUI::GUI() :
|
GUI::GUI() :
|
||||||
$level($level_manager.current()),
|
$level($level_manager.current()),
|
||||||
$status_ui(*$level.world),
|
$status_ui($level),
|
||||||
$map_view(*$level.world, *$level.lights, *$level.map),
|
$map_view($level),
|
||||||
$inventory_ui(*$level.world),
|
$inventory_ui($level),
|
||||||
$sounds("./assets")
|
$sounds("./assets")
|
||||||
{
|
{
|
||||||
// this needs a config file soon
|
// this needs a config file soon
|
||||||
|
@ -291,7 +295,7 @@ void GUI::handle_world_events() {
|
||||||
|
|
||||||
$status_ui.log(format("Up stairs has test {}.",
|
$status_ui.log(format("Up stairs has test {}.",
|
||||||
(bool)device.config["test"]));
|
(bool)device.config["test"]));
|
||||||
toggle_modal(&$next_level_ui, $next_level);
|
// toggle_modal(&$next_level_ui, $next_level);
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
$status_ui.log(format("INVALID EVENT! {},{}", evt, entity));
|
$status_ui.log(format("INVALID EVENT! {},{}", evt, entity));
|
||||||
|
@ -502,5 +506,15 @@ int GUI::main(bool run_once) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::next_level() {
|
void GUI::next_level() {
|
||||||
|
size_t index = $level_manager.create_level($level.world);
|
||||||
|
fmt::println("LEVEL manager returned index: {}", index);
|
||||||
|
|
||||||
|
auto &level = $level_manager.next();
|
||||||
|
$status_ui.update_level(level);
|
||||||
|
$inventory_ui.update_level(level);
|
||||||
|
$map_view.update_level(level);
|
||||||
|
$level = level;
|
||||||
|
|
||||||
|
render_scene();
|
||||||
|
run_systems();
|
||||||
}
|
}
|
||||||
|
|
27
gui.hpp
27
gui.hpp
|
@ -79,16 +79,19 @@ class InventoryUI : public Panel {
|
||||||
Component $inventory_box;
|
Component $inventory_box;
|
||||||
Component $inventory_render;
|
Component $inventory_render;
|
||||||
Component $inventory_table;
|
Component $inventory_table;
|
||||||
DinkyECS::World& $world;
|
GameLevel $level;
|
||||||
std::vector<std::string> $menu_list;
|
std::vector<std::string> $menu_list;
|
||||||
std::string $item_text = "No item selected.";
|
std::string $item_text = "No item selected.";
|
||||||
|
|
||||||
InventoryUI(DinkyECS::World& world) :
|
InventoryUI(GameLevel level) :
|
||||||
Panel(INVENTORY_PIXEL_X, INVENTORY_PIXEL_Y, INVENTORY_WIDTH, INVENTORY_HEIGHT),
|
Panel(INVENTORY_PIXEL_X, INVENTORY_PIXEL_Y, INVENTORY_WIDTH, INVENTORY_HEIGHT),
|
||||||
$world(world)
|
$level(level)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void create_render();
|
void create_render();
|
||||||
|
|
||||||
|
void update_level(GameLevel &level) { $level = level; }
|
||||||
|
|
||||||
void update_menu_list(components::Inventory& inventory);
|
void update_menu_list(components::Inventory& inventory);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -96,40 +99,42 @@ class StatusUI : public Panel {
|
||||||
public:
|
public:
|
||||||
ActionLog $log;
|
ActionLog $log;
|
||||||
string $status_text = "NOT DEAD";
|
string $status_text = "NOT DEAD";
|
||||||
DinkyECS::World& $world;
|
GameLevel $level;
|
||||||
|
|
||||||
StatusUI(DinkyECS::World& world) :
|
StatusUI(GameLevel level) :
|
||||||
Panel(0, 0, STATUS_UI_WIDTH, STATUS_UI_HEIGHT),
|
Panel(0, 0, STATUS_UI_WIDTH, STATUS_UI_HEIGHT),
|
||||||
$log({{"Welcome to the game!"}}),
|
$log({{"Welcome to the game!"}}),
|
||||||
$world(world) {}
|
$level(level) {}
|
||||||
|
|
||||||
void create_render();
|
void create_render();
|
||||||
void log(string msg) {
|
void log(string msg) {
|
||||||
$log.log(msg);
|
$log.log(msg);
|
||||||
}
|
}
|
||||||
|
void update_level(GameLevel &level) { $level = level; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class MapViewUI : public Panel {
|
class MapViewUI : public Panel {
|
||||||
public:
|
public:
|
||||||
Canvas $canvas;
|
Canvas $canvas;
|
||||||
DinkyECS::World& $world;
|
GameLevel $level;
|
||||||
LightRender& $lights;
|
|
||||||
Map& $game_map;
|
|
||||||
|
|
||||||
MapViewUI(DinkyECS::World& world, LightRender& lights, Map& game_map);
|
MapViewUI(GameLevel &level);
|
||||||
void create_render();
|
void create_render();
|
||||||
void resize_canvas();
|
void resize_canvas();
|
||||||
void draw_map();
|
void draw_map();
|
||||||
|
void update_level(GameLevel &level);
|
||||||
};
|
};
|
||||||
|
|
||||||
class GUI {
|
class GUI {
|
||||||
LevelManager $level_manager;
|
LevelManager $level_manager;
|
||||||
GameLevel &$level;
|
GameLevel $level;
|
||||||
|
|
||||||
StatusUI $status_ui;
|
StatusUI $status_ui;
|
||||||
MapViewUI $map_view;
|
MapViewUI $map_view;
|
||||||
InventoryUI $inventory_ui;
|
InventoryUI $inventory_ui;
|
||||||
DeathUI $death_ui;
|
DeathUI $death_ui;
|
||||||
NextLevelUI $next_level_ui;
|
NextLevelUI $next_level_ui;
|
||||||
|
|
||||||
Canvas $canvas;
|
Canvas $canvas;
|
||||||
bool $inventory_open = false;
|
bool $inventory_open = false;
|
||||||
bool $player_died = false;
|
bool $player_died = false;
|
||||||
|
|
|
@ -3,20 +3,40 @@
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "save.hpp"
|
#include "save.hpp"
|
||||||
#include "systems.hpp"
|
#include "systems.hpp"
|
||||||
|
#include "components.hpp"
|
||||||
|
|
||||||
using lighting::LightRender;
|
using lighting::LightRender;
|
||||||
using std::shared_ptr, std::make_shared;
|
using std::shared_ptr, std::make_shared;
|
||||||
|
using namespace components;
|
||||||
|
|
||||||
LevelManager::LevelManager() {
|
LevelManager::LevelManager() {
|
||||||
create_level();
|
create_level();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t LevelManager::create_level(shared_ptr<DinkyECS::World> prev_world) {
|
||||||
size_t LevelManager::create_level() {
|
|
||||||
auto world = make_shared<DinkyECS::World>();
|
auto world = make_shared<DinkyECS::World>();
|
||||||
save::load_configs(*world);
|
save::load_configs(*world);
|
||||||
|
|
||||||
auto map = make_shared<Map>(GAME_MAP_X, GAME_MAP_Y);
|
auto map = make_shared<Map>(GAME_MAP_X, GAME_MAP_Y);
|
||||||
|
|
||||||
|
if(prev_world != nullptr) {
|
||||||
|
auto player = prev_world->get_the<Player>();
|
||||||
|
world->set_the<Player>(player);
|
||||||
|
|
||||||
|
auto inventory = prev_world->get<Inventory>(player.entity);
|
||||||
|
world->set<Inventory>(player.entity, inventory);
|
||||||
|
|
||||||
|
world->set_the<Debug>(prev_world->get_the<Debug>());
|
||||||
|
auto& combat = prev_world->get<Combat>(player.entity);
|
||||||
|
world->set<Combat>(player.entity, combat);
|
||||||
|
|
||||||
|
auto& motion = prev_world->get<Motion>(player.entity);
|
||||||
|
world->set<Motion>(player.entity, motion);
|
||||||
|
|
||||||
|
auto& tile = prev_world->get<Tile>(player.entity);
|
||||||
|
world->set<Tile>(player.entity, tile);
|
||||||
|
}
|
||||||
|
|
||||||
WorldBuilder builder(*map);
|
WorldBuilder builder(*map);
|
||||||
builder.generate(*world);
|
builder.generate(*world);
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,14 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "spatialmap.hpp"
|
#include "spatialmap.hpp"
|
||||||
|
|
||||||
|
using std::shared_ptr;
|
||||||
|
|
||||||
struct GameLevel {
|
struct GameLevel {
|
||||||
size_t index;
|
size_t index;
|
||||||
std::shared_ptr<Map> map;
|
shared_ptr<Map> map;
|
||||||
std::shared_ptr<DinkyECS::World> world;
|
shared_ptr<DinkyECS::World> world;
|
||||||
std::shared_ptr<lighting::LightRender> lights;
|
shared_ptr<lighting::LightRender> lights;
|
||||||
std::shared_ptr<SpatialMap> collision;
|
shared_ptr<SpatialMap> collision;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LevelManager {
|
class LevelManager {
|
||||||
|
@ -23,7 +24,7 @@ class LevelManager {
|
||||||
|
|
||||||
LevelManager();
|
LevelManager();
|
||||||
|
|
||||||
size_t create_level();
|
size_t create_level(shared_ptr<DinkyECS::World> prev_world = nullptr);
|
||||||
GameLevel &next();
|
GameLevel &next();
|
||||||
GameLevel &previous();
|
GameLevel &previous();
|
||||||
GameLevel ¤t();
|
GameLevel ¤t();
|
||||||
|
|
|
@ -226,12 +226,16 @@ void WorldBuilder::place_entities(DinkyECS::World &world) {
|
||||||
auto &config = world.get_the<GameConfig>();
|
auto &config = world.get_the<GameConfig>();
|
||||||
// configure a player as a fact of the world
|
// configure a player as a fact of the world
|
||||||
|
|
||||||
auto player_data = config.enemies["PLAYER_TILE"];
|
if(world.has_the<Player>()) {
|
||||||
auto player_ent = configure_entity_in_map(world, $map, player_data, 0);
|
fmt::println("PLAYER ALREADY EXISTS LEAVING ALONE");
|
||||||
// configure player in the world
|
} else {
|
||||||
Player player{player_ent};
|
auto player_data = config.enemies["PLAYER_TILE"];
|
||||||
world.set_the<Player>(player);
|
auto player_ent = configure_entity_in_map(world, $map, player_data, 0);
|
||||||
world.set<Inventory>(player.entity, {5});
|
// configure player in the world
|
||||||
|
Player player{player_ent};
|
||||||
|
world.set_the<Player>(player);
|
||||||
|
world.set<Inventory>(player.entity, {5});
|
||||||
|
}
|
||||||
|
|
||||||
randomize_entities(world, config);
|
randomize_entities(world, config);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue