set position with vector

This commit is contained in:
Corwin Kuiper 2021-06-08 19:08:45 +01:00
parent 8e50dc8bd8
commit a5f4673806

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 {