Skip to content

Commit

Permalink
sprite transparent pixel (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
pineman committed Aug 10, 2024
1 parent fb800a0 commit 38f57f4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
6 changes: 5 additions & 1 deletion fpt/src/ppu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
50 changes: 27 additions & 23 deletions fpt/src/ppu/sprite.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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]),
}
}
}

0 comments on commit 38f57f4

Please sign in to comment.