Systems now control most of the game's operations and a lot of the rendering logic, this now brings in a camera so maps can be larger than the viewport.
This commit is contained in:
parent
e42647d727
commit
da64e526c4
5 changed files with 62 additions and 36 deletions
33
systems.cpp
33
systems.cpp
|
@ -1,4 +1,9 @@
|
|||
#include "systems.hpp"
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
using namespace fmt;
|
||||
|
||||
void System::enemy_pathing(DinkyECS::World &world, Map &game_map, Player &player) {
|
||||
// move enemies system
|
||||
|
@ -38,9 +43,31 @@ void System::combat(DinkyECS::World &world, Player &player) {
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
void System::draw_entities(DinkyECS::World &world, ftxui::Canvas &canvas) {
|
||||
void System::draw_entities(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y) {
|
||||
world.system<Position, Tile>([&](const auto &ent, auto &pos, auto &tile) {
|
||||
canvas.DrawText(pos.location.x*2, pos.location.y*4, tile.chr);
|
||||
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) {
|
||||
Point loc = game_map.map_to_camera(pos.location, cam_orig);
|
||||
canvas.DrawText(loc.x*2, loc.y*4, tile.chr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void System::draw_map(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canvas, size_t view_x, size_t view_y) {
|
||||
const auto& player = world.get<Player>();
|
||||
const auto& player_position = world.component<Position>(player.entity);
|
||||
Point start = game_map.center_camera(player_position.location, view_x, view_y);
|
||||
Matrix &walls = game_map.walls();
|
||||
|
||||
size_t end_x = std::min(view_x, game_map.width() - start.x);
|
||||
size_t end_y = std::min(view_y, game_map.height() - start.y);
|
||||
|
||||
for(size_t x = 0; x < end_x; ++x) {
|
||||
for(size_t y = 0; y < end_y; ++y) {
|
||||
string tile = walls[start.y+y][start.x+x] == 1 ? WALL_TILE : FLOOR_TILE;
|
||||
canvas.DrawText(x * 2, y * 4, tile);
|
||||
}
|
||||
}
|
||||
|
||||
System::draw_entities(world, game_map, canvas, start, view_x, view_y);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue