object priority

This commit is contained in:
Alex Janka 2023-02-10 09:55:58 +11:00
parent 8394b4d225
commit 76642194b1
2 changed files with 12 additions and 3 deletions

View file

@ -10,6 +10,8 @@ use crate::{
}; };
use minifb::{Window, WindowOptions}; use minifb::{Window, WindowOptions};
use super::SplitRegister;
mod tile_window; mod tile_window;
mod types; mod types;
@ -301,12 +303,18 @@ impl CPU {
x_flip: get_bit(flags, 5), x_flip: get_bit(flags, 5),
palette: byte_to_palette(self.memory.get(palette_addr)), palette: byte_to_palette(self.memory.get(palette_addr)),
}, },
oam_location: (i - 0xFE00) as u8,
}); });
if objs.len() >= 10 {
break;
}
} }
} }
objs.sort_by_key(|o| {
let mut v: u16 = 0x0;
v.set_high(o.x);
v.set_low(o.oam_location);
v
});
objs.reverse();
objs.truncate(10);
objs objs
} }

View file

@ -109,4 +109,5 @@ pub(super) struct Object {
pub(super) y: u8, pub(super) y: u8,
pub(super) tile_index: u8, pub(super) tile_index: u8,
pub(super) flags: ObjectFlags, pub(super) flags: ObjectFlags,
pub(super) oam_location: u8,
} }