More cleanup then starting to sort out how to make systems extensible easily.
This commit is contained in:
parent
6a0c9e8d46
commit
cbff127b40
13 changed files with 106 additions and 769 deletions
|
|
@ -366,10 +366,6 @@ void System::device(World &world, Entity actor, Entity item) {
|
|||
for(auto event : device.events) {
|
||||
if(event == "STAIRS_DOWN") {
|
||||
world.send<game::Event>(game::Event::STAIRS_DOWN, actor, device);
|
||||
} else if(event == "STAIRS_UP") {
|
||||
world.send<game::Event>(game::Event::STAIRS_UP, actor, device);
|
||||
} else if(event == "TRAP") {
|
||||
world.send<game::Event>(game::Event::TRAP, actor, device);
|
||||
} else if(event == "LOOT_CONTAINER") {
|
||||
world.send<game::Event>(game::Event::LOOT_CONTAINER, actor, device);
|
||||
} else {
|
||||
|
|
@ -388,25 +384,6 @@ void System::move_player(Position move_to) {
|
|||
level.collision->move(old_pos.location, move_to.location, level.player);
|
||||
}
|
||||
|
||||
|
||||
void System::player_status() {
|
||||
auto& level = GameDB::current_level();
|
||||
auto& combat = level.world->get<Combat>(level.player);
|
||||
float percent = float(combat.hp) / float(combat.max_hp);
|
||||
|
||||
if(percent > 0.8) {
|
||||
sound::play("hp_status_80");
|
||||
} else if(percent > 0.6) {
|
||||
sound::play("hp_status_60");
|
||||
} else if(percent > 0.3) {
|
||||
sound::play("hp_status_30");
|
||||
} else if(percent > 0.1) {
|
||||
sound::play("hp_status_10");
|
||||
} else {
|
||||
sound::play("hp_status_00");
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<sf::Shader> System::sprite_effect(Entity entity) {
|
||||
auto world = GameDB::current_world();
|
||||
if(auto se = world->get_if<SpriteEffect>(entity)) {
|
||||
|
|
@ -497,96 +474,6 @@ bool System::inventory_occupied(Entity container_id, const std::string& name) {
|
|||
return inventory.has(name);
|
||||
}
|
||||
|
||||
|
||||
void System::draw_map(Matrix& grid, EntityGrid& entity_map) {
|
||||
auto& level = GameDB::current_level();
|
||||
auto& world = *level.world;
|
||||
Map &map = *level.map;
|
||||
Matrix &fow = level.lights->$fow;
|
||||
size_t view_x = matrix::width(grid) - 1;
|
||||
size_t view_y = matrix::height(grid) - 1;
|
||||
|
||||
entity_map.clear();
|
||||
|
||||
auto player_pos = world.get<Position>(level.player).location;
|
||||
Point cam_orig = map.center_camera(player_pos, view_x, view_y);
|
||||
auto &tiles = map.tiles();
|
||||
auto &tile_set = textures::get_map_tile_set();
|
||||
|
||||
/* I'm doing double tid->wchar_t conversion here, maybe just
|
||||
* render the tids into the grid then let someone else do this. */
|
||||
|
||||
// first fill it with the map cells
|
||||
for(shiterator::each_cell_t it{grid}; it.next();) {
|
||||
size_t tile_y = size_t(it.y) + cam_orig.y;
|
||||
size_t tile_x = size_t(it.x) + cam_orig.x;
|
||||
|
||||
if(matrix::inbounds(tiles, tile_x, tile_y) && fow[tile_y][tile_x]) {
|
||||
size_t tid = tiles[tile_y][tile_x];
|
||||
grid[it.y][it.x] = tile_set[tid];
|
||||
} else {
|
||||
grid[it.y][it.x] = L' ';
|
||||
}
|
||||
}
|
||||
|
||||
// then get the enemy/item/device tiles and fill those in
|
||||
world.query<Position, Tile>([&](auto, auto &pos, auto &entity_glyph) {
|
||||
// BUG: don't I have a within bounds macro somewhere?
|
||||
if(pos.location.x >= cam_orig.x
|
||||
&& pos.location.x <= cam_orig.x + view_x
|
||||
&& pos.location.y >= cam_orig.y
|
||||
&& pos.location.y <= cam_orig.y + view_y)
|
||||
{
|
||||
if(fow[pos.location.y][pos.location.x]) {
|
||||
Point view_pos = map.map_to_camera(pos.location, cam_orig);
|
||||
entity_map.insert_or_assign(view_pos, entity_glyph.display);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display) {
|
||||
sf::Vector2i tile_sprite_dim{MAP_TILE_DIM,MAP_TILE_DIM};
|
||||
unsigned int width = matrix::width(tiles);
|
||||
unsigned int height = matrix::height(tiles);
|
||||
sf::Vector2u dim{width * tile_sprite_dim.x, height * tile_sprite_dim.y};
|
||||
auto render_size = render.getSize();
|
||||
|
||||
if(render_size.x != width || render_size.y != height) {
|
||||
bool worked = render.resize(dim);
|
||||
dbc::check(worked, "Failed to resize map render target.");
|
||||
}
|
||||
|
||||
render.clear({0,0,0,255});
|
||||
|
||||
for(matrix::each_row it{tiles}; it.next();) {
|
||||
wchar_t display = tiles[it.y][it.x];
|
||||
if(display == L' ') continue; // skip for now
|
||||
auto& sprite = textures::get_map_sprite(display);
|
||||
sprite.setPosition({float(it.x * tile_sprite_dim.x), float(it.y * tile_sprite_dim.y)});
|
||||
render.draw(sprite);
|
||||
}
|
||||
|
||||
for(auto [point, display] : entity_map) {
|
||||
auto& sprite = textures::get_map_sprite(display);
|
||||
|
||||
if(display == player_display) {
|
||||
sf::Vector2f center{float(tile_sprite_dim.x / 2), float(tile_sprite_dim.y / 2)};
|
||||
float degrees = (((compass_dir * 45) + PLAYER_SPRITE_DIR_CORRECTION) % 360);
|
||||
|
||||
sprite.setOrigin(center);
|
||||
sprite.setRotation(sf::degrees(degrees));
|
||||
sprite.setPosition({float(point.x * tile_sprite_dim.x) + center.x, float(point.y * tile_sprite_dim.y) + center.y});
|
||||
} else {
|
||||
sprite.setPosition({float(point.x * tile_sprite_dim.x), float(point.y * tile_sprite_dim.y)});
|
||||
}
|
||||
|
||||
render.draw(sprite);
|
||||
}
|
||||
|
||||
render.display();
|
||||
}
|
||||
|
||||
bool System::use_item(const string& slot_name) {
|
||||
auto& level = GameDB::current_level();
|
||||
auto& world = *level.world;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue