mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 08:41:34 +11:00
Add API for setting tile data from just a number
This commit is contained in:
parent
1286a58511
commit
cf72a9331a
|
@ -56,14 +56,14 @@ fn main(mut gba: agb::Gba) -> ! {
|
|||
|
||||
let mut background = gfx.background();
|
||||
|
||||
for (i, tile) in MAP_MAP.iter().enumerate() {
|
||||
for (i, &tile) in MAP_MAP.iter().enumerate() {
|
||||
let i = i as u16;
|
||||
background.set_tile(
|
||||
&mut gfx.vram,
|
||||
(i % 32, i / 32).into(),
|
||||
tileset_ref,
|
||||
tile & ((1 << 10) - 1),
|
||||
TileSetting::default(),
|
||||
TileSetting::from_raw(tile),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -220,10 +220,7 @@ struct Tile(u16);
|
|||
|
||||
impl Tile {
|
||||
fn new(tid: TileIndex, setting: TileSetting) -> Self {
|
||||
let hflip = setting.hflip;
|
||||
let vflip = setting.vflip;
|
||||
let palette_id = setting.palette_id as u16;
|
||||
Self(tid.0 | ((hflip as u16) << 10) | ((vflip as u16) << 11) | (palette_id << 12))
|
||||
Self(tid.0 | setting.as_raw())
|
||||
}
|
||||
|
||||
fn tile_index(self) -> TileIndex {
|
||||
|
@ -246,6 +243,22 @@ impl TileSetting {
|
|||
palette_id,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_raw(raw: u16) -> Self {
|
||||
let hflip = raw & (1 << 10) != 0;
|
||||
let vflip = raw & (1 << 11) != 0;
|
||||
let palette_id = raw >> 12;
|
||||
|
||||
Self {
|
||||
hflip,
|
||||
vflip,
|
||||
palette_id: palette_id as u8,
|
||||
}
|
||||
}
|
||||
|
||||
fn as_raw(self) -> u16 {
|
||||
((self.hflip as u16) << 10) | ((self.vflip as u16) << 11) | ((self.palette_id as u16) << 12)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RegularMap {
|
||||
|
|
Loading…
Reference in a new issue