Added a basic gamestate with a controlled mario
[kaka/rust-sdl-test.git] / src / common.rs
index 283640e..52b7324 100644 (file)
@@ -1,5 +1,7 @@
 use std::ops::{Add, AddAssign, Mul};
 
+pub type Nanoseconds = u64;
+
 #[macro_export]
 macro_rules! point {
     ( $x:expr, $y:expr ) => {
@@ -7,7 +9,7 @@ macro_rules! point {
     };
 }
 
-#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Default, Copy, Clone, PartialEq)]
 pub struct Point2D<T> {
     pub x: T,
     pub y: T,
@@ -37,6 +39,22 @@ impl<T: AddAssign> AddAssign for Point2D<T> {
     }
 }
 
+impl<T> From<(T, T)> for Point2D<T> {
+    fn from(item: (T, T)) -> Self {
+        Point2D {
+            x: item.0,
+            y: item.1,
+        }
+    }
+}
+
+#[macro_export]
+macro_rules! rect {
+    ( $x:expr, $y:expr ) => {
+        Rect { x: $x, y: $y }
+    };
+}
+
 #[derive(Default)]
 pub struct Rect<T> {
     pub width: T,