diff --git a/fpt/src/ppu.rs b/fpt/src/ppu.rs index 77ea8b6..f638637 100644 --- a/fpt/src/ppu.rs +++ b/fpt/src/ppu.rs @@ -128,7 +128,11 @@ impl Ppu { let tile = self.tilemap.get_tile(sprite.tile_index as usize, true); let tile_x = (x - sprite_x) as usize; let tile_y = (y - sprite_y) as usize; - pixel = tile.get_pixel(tile_y, tile_x); + let sprite_pixel = tile.get_pixel(tile_y, tile_x); + // Color 0 means transparent + if sprite_pixel != 0 { + pixel = sprite_pixel; + } } } self.frame[WIDTH * y + x] = pixel; diff --git a/fpt/src/ppu/sprite.rs b/fpt/src/ppu/sprite.rs index 58edd9d..c81a427 100644 --- a/fpt/src/ppu/sprite.rs +++ b/fpt/src/ppu/sprite.rs @@ -1,32 +1,36 @@ -//#[derive(Debug)] -//pub struct Flags { -// pub priority: bool, -// pub y_flip: bool, -// pub x_flip: bool, -// pub dmg_palette: u8, -// pub bank: bool, -// pub cgb_palette: u8, -//} +use crate::bw::*; -//impl Flags { -// pub fn from(memory: u8) -> Flags { -// Flags { -// //priority: test_bit8::<7>(memory), -// x_flip: test_bit8::<6>(memory), -// y_flip: test_bit8::<5>(memory), -// //dmg_palette: (memory >> 4) & 0b11, -// //bank: test_bit8::<3>(memory), -// //cgb_palette: memory & 0b111, -// } -// } -//} +#[derive(Debug)] +#[allow(unused)] +pub struct Flags { + pub priority: bool, + pub y_flip: bool, + pub x_flip: bool, + pub dmg_palette: u8, + pub bank: bool, + pub cgb_palette: u8, +} + +impl Flags { + pub fn from(memory: u8) -> Flags { + Flags { + priority: test_bit8::<7>(memory), + x_flip: test_bit8::<6>(memory), + y_flip: test_bit8::<5>(memory), + dmg_palette: (memory >> 4) & 0b11, + bank: test_bit8::<3>(memory), + cgb_palette: memory & 0b111, + } + } +} #[derive(Debug)] pub struct Sprite { pub y: u8, pub x: u8, pub tile_index: u8, - //pub flags: Flags, + #[allow(unused)] + pub flags: Flags, } impl Sprite { @@ -35,7 +39,7 @@ impl Sprite { y: memory[0], x: memory[1], tile_index: memory[2], - //flags: Flags::from(memory[3]), + flags: Flags::from(memory[3]), } } }