The next little game in the series where I make a fancy rogue game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
roguish/main.cpp

84 lines
2.4 KiB

// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <chrono> // for operator""s, chrono_literals
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <iostream> // for cout, ostream
#include <memory> // for allocator, shared_ptr
#include <string> // for string, operator<<
#include <thread> // for sleep_for
#include <ftxui/dom/elements.hpp> // for hflow, paragraph, separator, hbox, vbox, filler, operator|, border, Element
#include <ftxui/dom/node.hpp> // for Render
#include <ftxui/screen/box.hpp> // for ftxui
#include <ftxui/component/component.hpp>
#include <ftxui/screen/color.hpp>
#include <fmt/core.h>
#include "map.hpp"
#include "dbc.hpp"
using std::string;
using namespace fmt;
using namespace std::chrono_literals;
int main() {
using namespace ftxui;
std::string reset_position;
auto c = Canvas(60 * 2, 27 * 4);
Map game_map(60, 27);
game_map.generate();
Matrix &input_map = game_map.input_map();
Matrix &walls = game_map.walls();
// place character
// input_map[10][10] = 0;
auto map = Renderer([&] {
Matrix &result = game_map.paths();
for(size_t x = 0; x < result[0].size(); ++x) {
for(size_t y = 0; y < result.size(); ++y) {
auto path = result[y][x];
if(path == 1000) {
// it's a wall or unreachable, use the wall_map
const string tile = walls[y][x] == 1 ? "#" : ".";
c.DrawText(x*2, y*4, tile, Color::Yellow);
} else {
// it's a path number, show it
const string tile = format("{}", path);
Color color = path == 0 ? Color::Red : Color::GrayDark;
c.DrawText(x*2, y*4, tile, color);
}
}
}
// draw the character
c.DrawText(10*2, 10*4, "@", Color::Blue);
return canvas(c);
});
auto document = hbox({
hflow(
vbox(
gauge(0.5) | border,
text("STATUS") | border
) | xflex_grow
),
separator(),
hbox(map->Render()),
}) | border;
auto screen = Screen::Create(Dimension::Full());
Render(screen, document);
std::cout << reset_position;
screen.Print();
reset_position = screen.ResetPosition();
return 0;
}