mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 09:31:34 +11:00
add sprite sizes
This commit is contained in:
parent
2d12408983
commit
9286378a36
|
@ -47,6 +47,25 @@ enum Mode {
|
||||||
AffineDouble = 3,
|
AffineDouble = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub enum Size {
|
||||||
|
// stored as attr0 attr1
|
||||||
|
S8x8 = 0b00_00,
|
||||||
|
S16x16 = 0b00_01,
|
||||||
|
S32x32 = 0b00_10,
|
||||||
|
S64x64 = 0b00_11,
|
||||||
|
|
||||||
|
S16x8 = 0b01_00,
|
||||||
|
S32x8 = 0b01_01,
|
||||||
|
S32x16 = 0b01_10,
|
||||||
|
S64x32 = 0b01_11,
|
||||||
|
|
||||||
|
S8x16 = 0b10_00,
|
||||||
|
S8x32 = 0b10_01,
|
||||||
|
S16x32 = 0b10_10,
|
||||||
|
S32x64 = 0b10_11,
|
||||||
|
}
|
||||||
|
|
||||||
impl ObjectStandard {
|
impl ObjectStandard {
|
||||||
/// Commits the object to OAM such that the updated version is displayed on
|
/// Commits the object to OAM such that the updated version is displayed on
|
||||||
/// screen. Recommend to do this during VBlank.
|
/// screen. Recommend to do this during VBlank.
|
||||||
|
@ -70,6 +89,10 @@ impl ObjectStandard {
|
||||||
pub fn set_hflip(&mut self, hflip: bool) {
|
pub fn set_hflip(&mut self, hflip: bool) {
|
||||||
self.attributes.set_hflip(hflip)
|
self.attributes.set_hflip(hflip)
|
||||||
}
|
}
|
||||||
|
/// Sets the sprite size, will read tiles in x major order to construct this.
|
||||||
|
pub fn set_sprite_size(&mut self, size: Size) {
|
||||||
|
self.attributes.set_size(size);
|
||||||
|
}
|
||||||
/// Show the object on screen.
|
/// Show the object on screen.
|
||||||
pub fn show(&mut self) {
|
pub fn show(&mut self) {
|
||||||
self.attributes.set_mode(Mode::Normal)
|
self.attributes.set_mode(Mode::Normal)
|
||||||
|
@ -99,6 +122,10 @@ impl ObjectAffine {
|
||||||
pub fn set_tile_id(&mut self, id: u16) {
|
pub fn set_tile_id(&mut self, id: u16) {
|
||||||
self.attributes.set_tile_id(id)
|
self.attributes.set_tile_id(id)
|
||||||
}
|
}
|
||||||
|
/// Sets the sprite size, will read tiles in x major order to construct this.
|
||||||
|
pub fn set_sprite_size(&mut self, size: Size) {
|
||||||
|
self.attributes.set_size(size);
|
||||||
|
}
|
||||||
|
|
||||||
/// Show the object on screen. Panics if affine matrix has not been set.
|
/// Show the object on screen. Panics if affine matrix has not been set.
|
||||||
pub fn show(&mut self) {
|
pub fn show(&mut self) {
|
||||||
|
@ -141,6 +168,14 @@ impl ObjectAttribute {
|
||||||
self.a1 = set_bits(self.a1, hflip as u16, 1, 0xC);
|
self.a1 = set_bits(self.a1, hflip as u16, 1, 0xC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_size(&mut self, size: Size) {
|
||||||
|
let lower = size as u16 & 0b11;
|
||||||
|
let upper = (size as u16 >> 2) & 0b11;
|
||||||
|
|
||||||
|
self.a0 = set_bits(self.a0, lower, 2, 0xE);
|
||||||
|
self.a1 = set_bits(self.a1, upper, 2, 0xE);
|
||||||
|
}
|
||||||
|
|
||||||
fn set_x(&mut self, x: u8) {
|
fn set_x(&mut self, x: u8) {
|
||||||
self.a1 = set_bits(self.a1, x as u16, 8, 0);
|
self.a1 = set_bits(self.a1, x as u16, 8, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue