From 6f1c351b5fc61de14d091cc725831de9d31b6521 Mon Sep 17 00:00:00 2001 From: crumblingstatue Date: Mon, 3 Apr 2023 12:29:31 +0200 Subject: [PATCH] Use saturating arithmetic for keyboard camera movement --- src/app.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index 9ce233c..4f38a0a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -69,16 +69,16 @@ impl App { 2 }; if self.kb_input.down(Key::Left) { - self.game.camera_offset.x -= spd; + self.game.camera_offset.x = self.game.camera_offset.x.saturating_sub(spd); } if self.kb_input.down(Key::Right) { - self.game.camera_offset.x += spd; + self.game.camera_offset.x = self.game.camera_offset.x.saturating_add(spd); } if self.kb_input.down(Key::Up) { - self.game.camera_offset.y -= spd; + self.game.camera_offset.y = self.game.camera_offset.y.saturating_sub(spd); } if self.kb_input.down(Key::Down) { - self.game.camera_offset.y += spd; + self.game.camera_offset.y = self.game.camera_offset.y.saturating_add(spd); } let tp = self.game.camera_offset.tile_pos(); imm_dbg!(tp);