summaryrefslogtreecommitdiff
path: root/graphics/src/render.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-07 18:54:33 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-07 18:54:33 -0500
commit0119df49260bfa29157d959ff67af0f46419ca96 (patch)
tree495f14a20534ce9d349ec44b880a2a19761b950b /graphics/src/render.rs
parentdungeon: fix placeholder zombie from spawning in walls (diff)
downloadDungeonCrawl-0119df49260bfa29157d959ff67af0f46419ca96.tar.gz
DungeonCrawl-0119df49260bfa29157d959ff67af0f46419ca96.tar.bz2
DungeonCrawl-0119df49260bfa29157d959ff67af0f46419ca96.zip
graphics: switch font to NES (copyright?!), also fix crash when screen super duper small
Diffstat (limited to '')
-rw-r--r--graphics/src/render.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/graphics/src/render.rs b/graphics/src/render.rs
index 20ef41e..03e7f23 100644
--- a/graphics/src/render.rs
+++ b/graphics/src/render.rs
@@ -49,6 +49,9 @@ const WALL_HEIGHT: u16 = 7;
/// The (prefered) view distance of the game
const VIEW_DISTANCE: u16 = 5;
+/// The minimum width/height we will render to
+const MIN_RENDER_SIZE: u16 = BASE_TEXTURE_SIZE * (VIEW_DISTANCE + 2 + 2);
+
// Tile atlas.bmp textures
const ATLAS_WALL_SIDE: (u16, u16) = (0, 0);
const ATLAS_FLOOR_FULL: (u16, u16) = (1, 0);
@@ -81,20 +84,25 @@ struct Textures {
// Misc
error: Texture2D,
// Fonts
- pixantiqua: Font,
+ nes_font: Font,
}
impl Textures {
fn new(handle: &mut RaylibHandle, thread: &RaylibThread) -> crate::Result<Self> {
let atlas = handle.load_texture(thread, "assets/atlas.bmp")?;
let player = handle.load_texture(thread, "assets/player.bmp")?;
let error = handle.load_texture(thread, "assets/error.bmp")?;
- let pixantiqua = handle.load_font(thread, "assets/pixantiqua.fnt")?;
+ let nes_font = handle.load_font_ex(
+ thread,
+ "assets/nintendo-nes-font.otf",
+ BASE_TEXTURE_SIZE.into(),
+ None,
+ )?;
Ok(Self {
atlas,
player,
error,
- pixantiqua,
+ nes_font,
})
}
@@ -171,8 +179,8 @@ impl Renderer {
// Get last known fps
self.fps = handle.get_fps();
// Get size of framebuffer
- self.width = downcast!(handle.get_render_width(), u16);
- self.height = downcast!(handle.get_render_height(), u16);
+ self.width = downcast!(handle.get_render_width(), u16).max(MIN_RENDER_SIZE);
+ self.height = downcast!(handle.get_render_height(), u16).max(MIN_RENDER_SIZE);
// Get size (in pixels) to draw each tile
self.tile_size = {
let size = self.width.min(self.height);
@@ -630,7 +638,7 @@ impl Renderer {
where
R: RaylibDraw,
{
- let font = &self.textures.pixantiqua;
+ let font = &self.textures.nes_font;
let font_size = self.get_ui_font_size();
r.draw_text_ex(font, text, vec2! {x, y}, font_size.into(), 0.0, color);
}