summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-11 13:26:24 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-11 13:26:24 -0500
commit7d25655735e7cf340c8c2dc9a943c30fbdbf08a1 (patch)
treefc6407befd6306928343d13dd482600172740d73
parentgraphics: zoom out map (diff)
downloadDungeonCrawl-7d25655735e7cf340c8c2dc9a943c30fbdbf08a1.tar.gz
DungeonCrawl-7d25655735e7cf340c8c2dc9a943c30fbdbf08a1.tar.bz2
DungeonCrawl-7d25655735e7cf340c8c2dc9a943c30fbdbf08a1.zip
fix render camera positioning, other minor changes
-rw-r--r--graphics/src/render.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/graphics/src/render.rs b/graphics/src/render.rs
index 7f5501c..78ff94d 100644
--- a/graphics/src/render.rs
+++ b/graphics/src/render.rs
@@ -57,9 +57,7 @@ macro_rules! load_texture {
macro_rules! load_texture {
($handle:expr, $thread:expr, $filepath:expr) => {{
let bytes = include_bytes!(concat!("../../", $filepath));
- let len = $filepath.len();
- let ext = &$filepath[len - 4..];
- let image = ::raylib::texture::Image::load_image_from_mem(ext, bytes)?;
+ let image = ::raylib::texture::Image::load_image_from_mem(".bmp", bytes)?;
$handle.load_texture_from_image($thread, &image)?
}};
}
@@ -390,6 +388,7 @@ impl Renderer {
let (x, y) = pos.xy();
let tile = floor.get(pos);
let idx = match tile {
+ Tile::Wall if y + 1 == MAP_SIZE => ATLAS_WALL_TOP,
Tile::Wall => ATLAS_WALL_SIDE,
Tile::Room if (x + y) % 2 == 0 => ATLAS_FLOOR_FULL,
Tile::Room if (x + y) % 2 == 1 => ATLAS_FLOOR_EMPTY,
@@ -748,14 +747,20 @@ trait DungeonExt {
impl DungeonExt for Dungeon {
/// Returns the Raylib Camera setup with needed 2D position/transforms
fn render_camera(&self) -> Camera2D {
+ /// The offset to apply
+ const OFFSET: Vector2 = vec2! {
+ RENDER_WIDTH/2 - TILE_SIZE/2,
+ RENDER_HEIGHT/2 - TILE_SIZE/2 + UI_HEIGHT/2,
+ };
/// The minimum position the camera is allowed to go
const CAMERA_MIN: Vector2 = vec2! {
- RENDER_WIDTH/2, RENDER_HEIGHT/2 - UI_HEIGHT/2,
+ RENDER_WIDTH/2 - TILE_SIZE/2,
+ RENDER_HEIGHT/2 - TILE_SIZE/2 - UI_HEIGHT/2,
};
/// The maximum position the camera is allowed to go
const CAMERA_MAX: Vector2 = vec2! {
MAP_SIZE * TILE_SIZE - RENDER_WIDTH/2 - TILE_SIZE/2,
- MAP_SIZE * TILE_SIZE - RENDER_HEIGHT/2 - TILE_SIZE/2,
+ MAP_SIZE * TILE_SIZE - RENDER_HEIGHT/2 - TILE_SIZE/2 + UI_HEIGHT/2,
};
let pos = self.camera();
@@ -764,10 +769,7 @@ impl DungeonExt for Dungeon {
.scale_by(TILE_SIZE.into())
.max(CAMERA_MIN)
.min(CAMERA_MAX),
- offset: vec2! {
- RENDER_WIDTH/2 - TILE_SIZE/2,
- RENDER_HEIGHT/2 - TILE_SIZE/2 + UI_HEIGHT/2,
- },
+ offset: OFFSET,
rotation: 0.0,
zoom: 1.0,
}