changes made to make new game

This commit is contained in:
Corwin 2022-10-31 19:31:54 +00:00
parent 70f22b9255
commit 2efddfc342
3 changed files with 43 additions and 6 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)
}
@ -875,7 +875,7 @@ impl<T: Number> Rect<T> {
/// let r2 = Rect::new(Vector2D::new(-10,-10), Vector2D::new(3,3));
/// assert!(!r.touches(r2));
/// ```
pub fn touches(&self, other: Rect<T>) -> bool {
pub fn touches(&self, other: &Rect<T>) -> 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<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()) {
pub fn overlapping_rect(&self, other: &Rect<T>) -> Option<Self> {
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);