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
34
gui.cpp
34
gui.cpp
|
@ -49,10 +49,10 @@ sf::Color GUI::color(Value val) {
|
|||
}
|
||||
|
||||
GUI::GUI() : $game_map(GAME_MAP_X, GAME_MAP_Y),
|
||||
$canvas(GAME_MAP_X * 2, GAME_MAP_Y * 4),
|
||||
$canvas(VIEW_PORT_X * 2, VIEW_PORT_Y * 4),
|
||||
$window(sf::VideoMode(VIDEO_X,VIDEO_Y), "Roguish"),
|
||||
$screen(SCREEN_X, SCREEN_Y),
|
||||
$map_screen(GAME_MAP_X, GAME_MAP_Y)
|
||||
$map_screen(VIEW_PORT_X, VIEW_PORT_Y)
|
||||
{
|
||||
int res = $hit_buf.loadFromFile("./assets/hit.wav");
|
||||
dbc::check(res, "failed to load hit.wav");
|
||||
|
@ -77,27 +77,7 @@ void GUI::create_renderer() {
|
|||
auto player = $world.get<Player>();
|
||||
|
||||
$map_view = Renderer([&, player] {
|
||||
const auto& player_position = $world.component<Position>(player.entity);
|
||||
Matrix &walls = $game_map.walls();
|
||||
$game_map.set_target(player_position.location);
|
||||
$game_map.make_paths();
|
||||
Matrix &paths = $game_map.paths();
|
||||
|
||||
for(size_t x = 0; x < walls[0].size(); ++x) {
|
||||
for(size_t y = 0; y < walls.size(); ++y) {
|
||||
string tile = walls[y][x] == 1 ? WALL_TILE : format("{}", paths[y][x]);
|
||||
if(tile == WALL_TILE) {
|
||||
$canvas.DrawText(x*2, y*4, tile);
|
||||
} else if($show_paths) {
|
||||
//int pnum = paths[y][x];
|
||||
$canvas.DrawText(x*2, y*4, tile);
|
||||
} else {
|
||||
$canvas.DrawText(x*2, y*4, FLOOR_TILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System::draw_entities($world, $canvas);
|
||||
System::draw_map($world, $game_map, $canvas, VIEW_PORT_X, VIEW_PORT_Y);
|
||||
return canvas($canvas);
|
||||
});
|
||||
|
||||
|
@ -118,13 +98,15 @@ void GUI::create_renderer() {
|
|||
|
||||
void GUI::handle_events() {
|
||||
sf::Event event;
|
||||
auto player = $world.get<Player>();
|
||||
auto& player_motion = $world.component<Motion>(player.entity);
|
||||
|
||||
while($window.pollEvent(event)) {
|
||||
if(event.type == sf::Event::Closed) {
|
||||
$window.close();
|
||||
} else if(event.type == sf::Event::KeyPressed) {
|
||||
auto player = $world.get<Player>();
|
||||
auto& player_motion = $world.component<Motion>(player.entity);
|
||||
auto& player_position = $world.component<Position>(player.entity);
|
||||
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
|
||||
player_motion.dx = -1;
|
||||
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
|
||||
|
@ -135,6 +117,8 @@ void GUI::handle_events() {
|
|||
player_motion.dy = 1;
|
||||
}
|
||||
|
||||
$game_map.set_target(player_position.location);
|
||||
$game_map.make_paths();
|
||||
// COMPOSE system? You create a bunch of callbacks and then combine them into
|
||||
// a single run over the data?
|
||||
System::enemy_pathing($world, $game_map, player);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue