Really crappy minimap now displays.

master
Zed A. Shaw 1 month ago
parent e85b5d998b
commit 25ad9b51f8
  1. 6
      assets/tiles.json
  2. 40
      gui.cpp
  3. 3
      gui.hpp
  4. 18
      tilemap.cpp
  5. 1
      tilemap.hpp

@ -11,20 +11,20 @@
"foreground": [230, 20, 30], "foreground": [230, 20, 30],
"background": [230, 20, 120], "background": [230, 20, 120],
"collision": true, "collision": true,
"display": "\ua5b8" "display": ""
}, },
"WALL_VINES": { "WALL_VINES": {
"texture": "assets/wall_with_vines-256.png", "texture": "assets/wall_with_vines-256.png",
"foreground": [40, 15, 125], "foreground": [40, 15, 125],
"background": [200, 29, 75], "background": [200, 29, 75],
"collision": false, "collision": false,
"display":"\u19f0" "display":"#"
}, },
"WALL_PILLAR": { "WALL_PILLAR": {
"texture": "assets/wall_with_pillars-256.png", "texture": "assets/wall_with_pillars-256.png",
"foreground": [40, 15, 125], "foreground": [40, 15, 125],
"background": [200, 29, 75], "background": [200, 29, 75],
"collision": false, "collision": false,
"display":"\u16de" "display":"%"
} }
} }

@ -14,12 +14,17 @@ namespace gui {
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"), $window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"),
$font{"./assets/text.otf"}, $font{"./assets/text.otf"},
$text{$font}, $text{$font},
$map_display{$font},
$rayview($textures, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT) $rayview($textures, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT)
{ {
$window.setVerticalSyncEnabled(VSYNC); $window.setVerticalSyncEnabled(VSYNC);
$window.setFramerateLimit(FRAME_LIMIT); $window.setFramerateLimit(FRAME_LIMIT);
$text.setFillColor({255,255,255});
$text.setPosition({10,10}); $text.setPosition({10,10});
$text.setFillColor({255,255,255});
$map_display.setPosition({10, SCREEN_HEIGHT-300});
$map_display.setFillColor({255,255,255});
$map_display.setLetterSpacing(0.5);
$map_display.setLineSpacing(0.9);
$textures.load_tiles(); $textures.load_tiles();
$textures.load_sprites(); $textures.load_sprites();
} }
@ -44,7 +49,7 @@ namespace gui {
void FSM::MOVING(Event ) { void FSM::MOVING(Event ) {
if($camera.play_move($rayview)) { if($camera.play_move($rayview)) {
System::plan_motion(*level.world, {size_t($camera.targetX), size_t($camera.targetY)}); System::plan_motion(*$level.world, {size_t($camera.targetX), size_t($camera.targetY)});
run_systems(); run_systems();
state(State::IDLE); state(State::IDLE);
} }
@ -95,7 +100,7 @@ namespace gui {
Point move_to{size_t($camera.targetX), size_t($camera.targetY)}; Point move_to{size_t($camera.targetX), size_t($camera.targetY)};
if(level.map->can_move(move_to) && !level.collision->occupied(move_to)) { if($level.map->can_move(move_to) && !$level.collision->occupied(move_to)) {
state(State::MOVING); state(State::MOVING);
} else { } else {
state(State::IDLE); state(State::IDLE);
@ -153,10 +158,15 @@ namespace gui {
void FSM::draw_gui() { void FSM::draw_gui() {
sf::RectangleShape rect({SCREEN_WIDTH - RAY_VIEW_WIDTH, SCREEN_HEIGHT}); sf::RectangleShape rect({SCREEN_WIDTH - RAY_VIEW_WIDTH, SCREEN_HEIGHT});
sf::RectangleShape map_rect({SCREEN_WIDTH - RAY_VIEW_WIDTH - 10, 300});
rect.setPosition({0,0}); rect.setPosition({0,0});
rect.setFillColor({50, 50, 50}); rect.setFillColor({50, 50, 50});
map_rect.setPosition({0, SCREEN_HEIGHT-300});
map_rect.setFillColor({20, 20, 20});
$window.draw(rect); $window.draw(rect);
$window.draw(map_rect);
$text.setString( $text.setString(
fmt::format("FPS\n" fmt::format("FPS\n"
@ -168,14 +178,18 @@ namespace gui {
"VSync? {}\n" "VSync? {}\n"
"FR Limit: {}\n" "FR Limit: {}\n"
"Debug? {}\n\n" "Debug? {}\n\n"
"Hit R to reset.\n\n"
"dir: {:>2.02},{:>2.02}\n" "dir: {:>2.02},{:>2.02}\n"
"pos: {:>2.02},{:>2.02}", "pos: {:>2.02},{:>2.02}\n\n",
$stats.mean(), $stats.stddev(), $stats.min, $stats.mean(), $stats.stddev(), $stats.min,
$stats.max, $stats.n, VSYNC, $stats.max, $stats.n, VSYNC,
FRAME_LIMIT, DEBUG_BUILD, $rayview.$dirX, FRAME_LIMIT, DEBUG_BUILD, $rayview.$dirX,
$rayview.$dirY, $rayview.$posX, $rayview.$posY)); $rayview.$dirY, $rayview.$posX, $rayview.$posY));
$window.draw($text); $window.draw($text);
std::wstring map = $level.map->tiles().minimap(int($rayview.$posX), int($rayview.$posY));
$map_display.setString(map);
$window.draw($map_display);
} }
void FSM::render() { void FSM::render() {
@ -199,18 +213,18 @@ namespace gui {
} }
void FSM::generate_map() { void FSM::generate_map() {
level = $levels.current(); $level = $levels.current();
auto& player = level.world->get_the<Player>(); auto& player = $level.world->get_the<Player>();
auto& player_position = level.world->get<Position>(player.entity); auto& player_position = $level.world->get<Position>(player.entity);
$player = player_position.location; $player = player_position.location;
$rayview.set_level(level); $rayview.set_level($level);
} }
void FSM::run_systems() { void FSM::run_systems() {
System::motion(level); System::motion($level);
System::enemy_pathing(level); System::enemy_pathing($level);
System::collision(level); System::collision($level);
System::death(level); System::death($level);
} }
bool FSM::active() { bool FSM::active() {

@ -29,7 +29,7 @@ namespace gui {
class FSM : public DeadSimpleFSM<State, Event> { class FSM : public DeadSimpleFSM<State, Event> {
public: public:
GameLevel level; GameLevel $level;
float $rotation = -30.0f; float $rotation = -30.0f;
Point $player{0,0}; Point $player{0,0};
LevelManager $levels; LevelManager $levels;
@ -37,6 +37,7 @@ namespace gui {
CameraLOL $camera; CameraLOL $camera;
sf::Font $font; sf::Font $font;
sf::Text $text; sf::Text $text;
sf::Text $map_display;
Stats $stats; Stats $stats;
TexturePack $textures; TexturePack $textures;
Raycaster $rayview; Raycaster $rayview;

@ -73,3 +73,21 @@ bool TileMap::INVARIANT() {
dbc::check(matrix::width($tile_ids) == $width, "$tile_ids has wrong width"); dbc::check(matrix::width($tile_ids) == $width, "$tile_ids has wrong width");
return true; return true;
} }
std::wstring TileMap::minimap(size_t x, size_t y) {
string result;
for(matrix::box it{$tile_ids, x, y, 5}; it.next();) {
const TileCell &cell = $display[it.y][it.x];
if(it.x == x && it.y == y) {
result += "@";
} else {
result += cell.display;
}
if(it.x == it.right - 1) result += "\n";
}
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
return $converter.from_bytes(result);
}

@ -43,4 +43,5 @@ public:
void dump(int show_x=-1, int show_y=-1); void dump(int show_x=-1, int show_y=-1);
bool INVARIANT(); bool INVARIANT();
std::wstring minimap(size_t x, size_t y);
}; };

Loading…
Cancel
Save