From cc7a0d8b9b4dc0fb26a8feffc81184dba1c5d387 Mon Sep 17 00:00:00 2001 From: crumblingstatue Date: Mon, 3 Apr 2023 10:37:02 +0200 Subject: [PATCH] Fix screen offset calculation when drawing tiles --- src/game.rs | 6 +++--- src/graphics.rs | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/game.rs b/src/game.rs index a5f7453..3302013 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,7 +1,7 @@ use sfml::graphics::{Rect, RenderTarget, RenderWindow, Sprite, Transformable}; use crate::{ - graphics::{ScreenPos, NATIVE_RESOLUTION}, + graphics::{ScreenPos, ScreenPosScalar, NATIVE_RESOLUTION}, math::{wp_to_tp, WorldPos, WorldPosScalar}, res::Res, world::{TilePos, World}, @@ -32,8 +32,8 @@ fn for_each_tile(camera_offset: WorldPos, mut f: impl FnMut(TilePos, ScreenPos)) y: wp_to_tp(camera_offset.y.saturating_add(y as WorldPosScalar)), }, ScreenPos { - x: ((x as WorldPosScalar).saturating_sub(camera_offset.x % 32)) as i16, - y: ((y as WorldPosScalar).saturating_sub(camera_offset.y % 32)) as i16, + x: ((x as i64) - ((camera_offset.x as i64) % 32)) as ScreenPosScalar, + y: ((y as i64) - ((camera_offset.y as i64) % 32)) as ScreenPosScalar, }, ) } diff --git a/src/graphics.rs b/src/graphics.rs index 0fcc9bf..b607ac1 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -22,10 +22,12 @@ impl ScreenRes { // We assume this game won't be played above 32767*32767 resolution pub struct ScreenPos { - pub x: i16, - pub y: i16, + pub x: ScreenPosScalar, + pub y: ScreenPosScalar, } +pub type ScreenPosScalar = i16; + impl ScreenPos { pub fn to_sf_vec(&self) -> Vector2f { Vector2f::new(self.x.into(), self.y.into())