Merge pull request #66 from corwinkuiper/number-methods

Number methods
This commit is contained in:
Corwin 2021-06-08 19:16:01 +01:00 committed by GitHub
commit 1357e1254f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View file

@ -3,6 +3,7 @@ use core::cell::RefCell;
use super::DISPLAY_CONTROL;
use crate::bitarray::Bitarray;
use crate::memory_mapped::MemoryMapped1DArray;
use crate::number::Vector2D;
const OBJECT_ATTRIBUTE_MEMORY: MemoryMapped1DArray<u16, 512> =
unsafe { MemoryMapped1DArray::new(0x0700_0000) };
@ -114,6 +115,15 @@ impl ObjectStandard<'_> {
pub fn hide(&mut self) {
self.attributes.set_mode(Mode::Hidden)
}
/// Sets the x and y position of the object, performing casts as nessesary
/// to fit within the bits allocated for this purpose.
pub fn set_position(&mut self, position: Vector2D<i32>) {
let x = position.x as u16;
let y = position.y as u16;
self.attributes.set_x(x);
self.attributes.set_y(y);
}
}
impl<'a> ObjectAffine<'a> {
@ -157,6 +167,15 @@ impl<'a> ObjectAffine<'a> {
self.attributes.set_affine(aff.loan.index);
self.aff_id = Some(aff.loan.index);
}
/// Sets the x and y position of the object, performing casts as nessesary
/// to fit within the bits allocated for this purpose.
pub fn set_position(&mut self, position: Vector2D<i32>) {
let x = position.x as u16;
let y = position.y as u16;
self.attributes.set_x(x);
self.attributes.set_y(y);
}
}
fn set_bits(current: u16, value: u16, length: u16, shift: u16) -> u16 {

View file

@ -126,12 +126,10 @@ pub fn affine_matrix(
rotation: u16,
}
let rotation_for_input = (rotation as u16) << 8;
let input = Input {
y_scale: x_scale.to_raw(),
x_scale: y_scale.to_raw(),
rotation: rotation_for_input,
rotation: rotation as u16,
};
unsafe {