summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hogenson <rhogenson@posteo.net>2018-08-18 08:35:38 -0400
committerRaymond Hogenson <rhogenson@posteo.net>2018-08-18 08:37:05 -0400
commit8b239f55d1c08584f7ba8a735657d4ef6c915626 (patch)
tree4a8706f3f22e7b4b80e173891fe9fc5b672fc8fa
parent7ba26044a78df1f87604d74754da3d28393607f7 (diff)
downloadstallman-shooter-8b239f55d1c08584f7ba8a735657d4ef6c915626.tar.zst
Stop the player from going off the side
Oh wait I haven't tested this yet. I'll be right back. Yeah it works
-rw-r--r--src/player.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/player.rs b/src/player.rs
index 97c98f6..efd396e 100644
--- a/src/player.rs
+++ b/src/player.rs
@@ -2,6 +2,7 @@ extern crate sdl2;
extern crate std;
use super::state;
+use super::constants;
pub struct Player {
pub x: i32,
@@ -76,6 +77,20 @@ impl Player {
} else {
self.y_d = 0;
}
+ /* Don't go off the side */
+ if self.x_d < 0 && self.x <= 0 {
+ self.x_d = 0;
+ }
+ else if self.x >= constants::X_DIM as i32 && self.x_d > 0 {
+ self.x_d = 0;
+ }
+ if self.y <= 0 && self.y_d < 0 {
+ self.y_d = 0;
+ }
+ else if self.y >= constants::Y_DIM as i32 && self.y_d > 0 {
+ self.y_d = 0;
+ }
+
self.x += self.x_d;
self.y += self.y_d;
}