summaryrefslogtreecommitdiff
path: root/src/engine/geometry.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-05-05 20:37:53 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-05-05 20:37:53 +0200
commit057a4fe886848322adf4e48ad9709a289434dc1b (patch)
tree5651d000fc642387d8c8e1ea410a26d4e7e7689f /src/engine/geometry.rs
Initial commit with sample bot and embedded game engine
Diffstat (limited to 'src/engine/geometry.rs')
-rw-r--r--src/engine/geometry.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/engine/geometry.rs b/src/engine/geometry.rs
new file mode 100644
index 0000000..f2a2522
--- /dev/null
+++ b/src/engine/geometry.rs
@@ -0,0 +1,24 @@
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct Point {
+ pub x: u8,
+ pub y: u8
+}
+
+impl Point {
+ pub fn move_left(&self) -> Option<Point> {
+ self.x.checked_sub(1).map(|x| Point {
+ x: x,
+ ..*self
+ })
+ }
+ pub fn move_right(&self, size: &Point) -> Option<Point> {
+ if self.x + 1 >= size.x {
+ None
+ } else {
+ Some(Point {
+ x: self.x + 1,
+ ..*self
+ })
+ }
+ }
+}