|
|
@ -2,7 +2,6 @@ |
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// the LICENSE file.
|
|
|
|
// the LICENSE file.
|
|
|
|
#include <chrono> // for operator""s, chrono_literals |
|
|
|
#include <chrono> // for operator""s, chrono_literals |
|
|
|
#include <ftxui/screen/screen.hpp> // for Full, Screen |
|
|
|
|
|
|
|
#include <iostream> // for cout, ostream |
|
|
|
#include <iostream> // for cout, ostream |
|
|
|
#include <memory> // for allocator, shared_ptr |
|
|
|
#include <memory> // for allocator, shared_ptr |
|
|
|
#include <string> // for string, operator<< |
|
|
|
#include <string> // for string, operator<< |
|
|
@ -12,7 +11,9 @@ |
|
|
|
#include <ftxui/dom/node.hpp> // for Render |
|
|
|
#include <ftxui/dom/node.hpp> // for Render |
|
|
|
#include <ftxui/screen/box.hpp> // for ftxui |
|
|
|
#include <ftxui/screen/box.hpp> // for ftxui |
|
|
|
#include <ftxui/component/component.hpp> |
|
|
|
#include <ftxui/component/component.hpp> |
|
|
|
|
|
|
|
#include <ftxui/component/loop.hpp> |
|
|
|
#include <ftxui/screen/color.hpp> |
|
|
|
#include <ftxui/screen/color.hpp> |
|
|
|
|
|
|
|
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive |
|
|
|
|
|
|
|
|
|
|
|
#include <fmt/core.h> |
|
|
|
#include <fmt/core.h> |
|
|
|
#include "map.hpp" |
|
|
|
#include "map.hpp" |
|
|
@ -30,34 +31,25 @@ int main() { |
|
|
|
|
|
|
|
|
|
|
|
Map game_map(50, 27); |
|
|
|
Map game_map(50, 27); |
|
|
|
game_map.generate(); |
|
|
|
game_map.generate(); |
|
|
|
|
|
|
|
Matrix &walls = game_map.walls(); |
|
|
|
|
|
|
|
Room &start = game_map.room(0); |
|
|
|
|
|
|
|
Point me = {.x=start.x+1, .y=start.y+1}; |
|
|
|
|
|
|
|
|
|
|
|
auto map = Renderer([&] { |
|
|
|
auto map = Renderer([&] { |
|
|
|
Matrix &result = game_map.paths(); |
|
|
|
for(size_t x = 0; x < walls[0].size(); ++x) { |
|
|
|
Matrix &walls = game_map.walls(); |
|
|
|
for(size_t y = 0; y < walls.size(); ++y) { |
|
|
|
|
|
|
|
const string tile = walls[y][x] == 1 ? "#" : "."; |
|
|
|
for(size_t x = 0; x < result[0].size(); ++x) { |
|
|
|
c.DrawText(x*2, y*4, tile, Color::GrayDark); |
|
|
|
for(size_t y = 0; y < result.size(); ++y) { |
|
|
|
|
|
|
|
auto path = result[y][x]; |
|
|
|
|
|
|
|
if(path == 1000 || walls[y][x] == 1) { |
|
|
|
|
|
|
|
// 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::GrayDark); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// it's a path number, show it
|
|
|
|
|
|
|
|
const string tile = format("{}", path); |
|
|
|
|
|
|
|
auto color = Color::Palette16(path % 7 + 1); |
|
|
|
|
|
|
|
c.DrawText(x*2, y*4, tile, color); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// draw the character
|
|
|
|
c.DrawText(me.x*2, me.y*4, "@", Color::Blue); |
|
|
|
//c.DrawText(10*2, 10*4, "@", Color::Blue);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return canvas(c); |
|
|
|
return canvas(c); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
auto document = hbox({ |
|
|
|
auto document = Renderer([&]{ |
|
|
|
|
|
|
|
return hbox({ |
|
|
|
hflow( |
|
|
|
hflow( |
|
|
|
vbox( |
|
|
|
vbox( |
|
|
|
gauge(0.5) | border, |
|
|
|
gauge(0.5) | border, |
|
|
@ -67,13 +59,37 @@ int main() { |
|
|
|
separator(), |
|
|
|
separator(), |
|
|
|
hbox(map->Render()), |
|
|
|
hbox(map->Render()), |
|
|
|
}) | border; |
|
|
|
}) | border; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
auto screen = Screen::Create(Dimension::Full()); |
|
|
|
document |= CatchEvent([&](Event e) -> bool { |
|
|
|
Render(screen, document); |
|
|
|
size_t x = me.x; |
|
|
|
|
|
|
|
size_t y = me.y; |
|
|
|
|
|
|
|
|
|
|
|
std::cout << reset_position; |
|
|
|
if(e == Event::ArrowLeft) { |
|
|
|
screen.Print(); |
|
|
|
x -= 1; |
|
|
|
reset_position = screen.ResetPosition(); |
|
|
|
} else if(e == Event::ArrowRight) { |
|
|
|
|
|
|
|
x += 1; |
|
|
|
|
|
|
|
} else if(e == Event::ArrowDown) { |
|
|
|
|
|
|
|
y += 1; |
|
|
|
|
|
|
|
} else if(e == Event::ArrowUp) { |
|
|
|
|
|
|
|
y -= 1; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(game_map.inmap(x,y) && !game_map.iswall(x,y)) { |
|
|
|
|
|
|
|
me.x = x; |
|
|
|
|
|
|
|
me.y = y; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto screen = ScreenInteractive::Fullscreen(); |
|
|
|
|
|
|
|
Loop loop(&screen, document); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(!loop.HasQuitted()) { |
|
|
|
|
|
|
|
loop.RunOnceBlocking(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|