changes made to make new game (#343)

- [x] Changelog updated / no changelog update needed
This commit is contained in:
Corwin 2022-10-31 22:49:41 +00:00 committed by GitHub
commit d4025638f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 5 deletions

View file

@ -336,7 +336,7 @@ impl<I: FixedWidthUnsignedInteger, const N: usize> Num<I, N> {
}
/// 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)
}
@ -819,7 +819,7 @@ impl<I: FixedWidthUnsignedInteger, const N: usize> From<Vector2D<I>> 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<T: Number> {
/// The position of the rectangle
@ -901,7 +901,7 @@ impl<T: Number> Rect<T> {
/// assert_eq!(r.overlapping_rect(r2), None);
/// ```
pub fn overlapping_rect(&self, other: Rect<T>) -> Option<Self> {
if !self.touches(other.clone()) {
if !self.touches(other) {
return None;
}

View file

@ -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<u16> = unsafe { MemoryMapped::new(0x0400_0000) };

View file

@ -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<T>(&self) -> Vector2D<T>
where
T: From<i32> + 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<T>(&self) -> Vector2D<T>
where
T: From<i32> + 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);