From 2802a44ba42c7a469c71d8fcca41aa7b19ef5d82 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 18 Jul 2025 13:25:32 -0400 Subject: [PATCH] Clean up System::render_map. --- constants.hpp | 1 + systems.cpp | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/constants.hpp b/constants.hpp index 8e9d7f6..474c198 100644 --- a/constants.hpp +++ b/constants.hpp @@ -17,6 +17,7 @@ constexpr const int LIGHT_MULTIPLIER=2.5; constexpr const float AIMED_AT_BRIGHTNESS=0.2f; constexpr const int MAP_TILE_DIM=64; constexpr const int ICONGEN_MAP_TILE_DIM=64; +constexpr const int PLAYER_SPRITE_DIR_CORRECTION=270; constexpr const int BOSS_VIEW_WIDTH=1080; constexpr const int BOSS_VIEW_HEIGHT=SCREEN_HEIGHT; diff --git a/systems.cpp b/systems.cpp index 5169a3e..268018e 100644 --- a/systems.cpp +++ b/systems.cpp @@ -569,10 +569,10 @@ void System::draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map) { void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display) { - sf::Vector2i size{MAP_TILE_DIM,MAP_TILE_DIM}; + sf::Vector2i tile_sprite_dim{MAP_TILE_DIM,MAP_TILE_DIM}; unsigned int width = matrix::width(tiles); unsigned int height = matrix::height(tiles); - sf::Vector2u dim{width * size.x, height * size.y}; + sf::Vector2u dim{width * tile_sprite_dim.x, height * tile_sprite_dim.y}; auto render_size = render.getSize(); if(render_size.x != width || render_size.y != height) { @@ -580,13 +580,13 @@ void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture dbc::check(worked, "Failed to resize map render target."); } - render.clear({0,0,0,0}); + render.clear({0,0,0,255}); for(matrix::each_row it{tiles}; it.next();) { wchar_t display = tiles[it.y][it.x]; if(display == L' ') continue; // skip for now auto& sprite = textures::get_map_sprite(display); - sprite.setPosition({float(it.x * size.x), float(it.y * size.y)}); + sprite.setPosition({float(it.x * tile_sprite_dim.x), float(it.y * tile_sprite_dim.y)}); render.draw(sprite); } @@ -594,15 +594,14 @@ void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture auto& sprite = textures::get_map_sprite(display); if(display == player_display) { - sf::Vector2f size = sprite.getLocalBounds().size; - sf::Vector2f center{size.x / 2, size.y / 2}; - float degrees = (((compass_dir * 45) + 270) % 360); + sf::Vector2f center{float(tile_sprite_dim.x / 2), float(tile_sprite_dim.y / 2)}; + float degrees = (((compass_dir * 45) + PLAYER_SPRITE_DIR_CORRECTION) % 360); sprite.setOrigin(center); sprite.setRotation(sf::degrees(degrees)); - sprite.setPosition({float(point.x * size.x) + center.x, float(point.y * size.y) + center.y}); + sprite.setPosition({float(point.x * tile_sprite_dim.x) + center.x, float(point.y * tile_sprite_dim.y) + center.y}); } else { - sprite.setPosition({float(point.x * size.x), float(point.y * size.y)}); + sprite.setPosition({float(point.x * tile_sprite_dim.x), float(point.y * tile_sprite_dim.y)}); } render.draw(sprite);