From 2efddfc342946a4a758379118a7638269d37e338 Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 31 Oct 2022 19:31:54 +0000 Subject: [PATCH 1/2] changes made to make new game --- agb-fixnum/src/lib.rs | 8 ++++---- agb/src/display/mod.rs | 4 ++-- agb/src/input.rs | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/agb-fixnum/src/lib.rs b/agb-fixnum/src/lib.rs index 35eeed9..ad122fe 100644 --- a/agb-fixnum/src/lib.rs +++ b/agb-fixnum/src/lib.rs @@ -336,7 +336,7 @@ impl Num { } /// A bit for bit conversion from a number to a fixed num - pub fn from_raw(n: I) -> Self { + pub const fn from_raw(n: I) -> Self { Num(n) } @@ -875,7 +875,7 @@ impl Rect { /// let r2 = Rect::new(Vector2D::new(-10,-10), Vector2D::new(3,3)); /// assert!(!r.touches(r2)); /// ``` - pub fn touches(&self, other: Rect) -> bool { + pub fn touches(&self, other: &Rect) -> bool { self.position.x < other.position.x + other.size.x && self.position.x + self.size.x > other.position.x && self.position.y < other.position.y + other.size.y @@ -900,8 +900,8 @@ impl Rect { /// /// assert_eq!(r.overlapping_rect(r2), None); /// ``` - pub fn overlapping_rect(&self, other: Rect) -> Option { - if !self.touches(other.clone()) { + pub fn overlapping_rect(&self, other: &Rect) -> Option { + if !self.touches(other) { return None; } diff --git a/agb/src/display/mod.rs b/agb/src/display/mod.rs index ab0110e..fba3aaa 100644 --- a/agb/src/display/mod.rs +++ b/agb/src/display/mod.rs @@ -23,11 +23,11 @@ pub mod tiled; /// Giving out graphics mode. pub mod video; +pub mod affine; pub mod blend; pub mod window; -pub mod affine; -mod font; +pub mod font; pub use font::{Font, FontLetter}; const DISPLAY_CONTROL: MemoryMapped = unsafe { MemoryMapped::new(0x0400_0000) }; diff --git a/agb/src/input.rs b/agb/src/input.rs index 7c77fbd..c36866e 100644 --- a/agb/src/input.rs +++ b/agb/src/input.rs @@ -1,3 +1,4 @@ +use crate::fixnum::Vector2D; use bitflags::bitflags; use core::convert::From; @@ -77,6 +78,42 @@ impl ButtonController { (up, down).into() } + #[must_use] + pub fn vector(&self) -> Vector2D + where + T: From + crate::fixnum::FixedWidthUnsignedInteger, + { + (self.x_tri() as i32, self.y_tri() as i32).into() + } + + #[must_use] + pub fn just_pressed_x_tri(&self) -> Tri { + let left = self.is_just_pressed(Button::LEFT); + let right = self.is_just_pressed(Button::RIGHT); + + (left, right).into() + } + + #[must_use] + pub fn just_pressed_y_tri(&self) -> Tri { + let up = self.is_just_pressed(Button::UP); + let down = self.is_just_pressed(Button::DOWN); + + (up, down).into() + } + + #[must_use] + pub fn just_pressed_vector(&self) -> Vector2D + where + T: From + crate::fixnum::FixedWidthUnsignedInteger, + { + ( + self.just_pressed_x_tri() as i32, + self.just_pressed_y_tri() as i32, + ) + .into() + } + #[must_use] pub fn is_pressed(&self, keys: Button) -> bool { let currently_pressed = u32::from(self.current); From 44e0b633d945804ad0e97ed01e42fdfe72347b06 Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 31 Oct 2022 20:31:37 +0000 Subject: [PATCH 2/2] use copy implementation instead --- agb-fixnum/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agb-fixnum/src/lib.rs b/agb-fixnum/src/lib.rs index ad122fe..2accff3 100644 --- a/agb-fixnum/src/lib.rs +++ b/agb-fixnum/src/lib.rs @@ -819,7 +819,7 @@ impl From> for Vector2 } } -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone, Copy)] /// A rectangle with a position in 2d space and a 2d size pub struct Rect { /// The position of the rectangle @@ -875,7 +875,7 @@ impl Rect { /// let r2 = Rect::new(Vector2D::new(-10,-10), Vector2D::new(3,3)); /// assert!(!r.touches(r2)); /// ``` - pub fn touches(&self, other: &Rect) -> bool { + pub fn touches(&self, other: Rect) -> bool { self.position.x < other.position.x + other.size.x && self.position.x + self.size.x > other.position.x && self.position.y < other.position.y + other.size.y @@ -900,7 +900,7 @@ impl Rect { /// /// assert_eq!(r.overlapping_rect(r2), None); /// ``` - pub fn overlapping_rect(&self, other: &Rect) -> Option { + pub fn overlapping_rect(&self, other: Rect) -> Option { if !self.touches(other) { return None; }