Clear the backgrounds once they aren't used any more

This commit is contained in:
Gwilym Kuiper 2022-02-14 22:23:02 +00:00
parent bdcd5b5e6d
commit d896adfad5
3 changed files with 15 additions and 8 deletions

View file

@ -649,6 +649,10 @@ impl<'a> InfiniteScrolledMap<'a> {
pub fn commit(&mut self) { pub fn commit(&mut self) {
self.map.commit(); self.map.commit();
} }
pub fn clear(&mut self, vram: &mut VRamManager) {
self.map.clear(vram);
}
} }
fn div_floor(x: i32, y: i32) -> i32 { fn div_floor(x: i32, y: i32) -> i32 {

View file

@ -660,6 +660,11 @@ impl<'a, 'b, 'c> PlayingLevel<'a, 'b> {
self.background.background.hide(); self.background.background.hide();
} }
fn clear_backgrounds(&mut self, vram: &mut VRamManager) {
self.background.background.clear(vram);
self.background.foreground.clear(vram);
}
fn dead_start(&mut self) { fn dead_start(&mut self) {
self.player.wizard.velocity = (0, -1).into(); self.player.wizard.velocity = (0, -1).into();
self.player.wizard.sprite.set_priority(Priority::P0); self.player.wizard.sprite.set_priority(Priority::P0);
@ -812,7 +817,7 @@ fn main(mut agb: agb::Gba) -> ! {
let mut music_box = sfx::MusicBox::new(); let mut music_box = sfx::MusicBox::new();
let vblank = agb::interrupt::VBlank::get(); let vblank = agb::interrupt::VBlank::get();
let mut current_level = 10; let mut current_level = 11;
loop { loop {
if current_level == map_tiles::LEVELS.len() as u32 { if current_level == map_tiles::LEVELS.len() as u32 {
@ -934,6 +939,7 @@ fn main(mut agb: agb::Gba) -> ! {
} }
level.hide_backgrounds(); level.hide_backgrounds();
level.clear_backgrounds(&mut vram);
} }
splash_screen::show_splash_screen( splash_screen::show_splash_screen(

View file

@ -19,16 +19,14 @@ pub fn show_splash_screen(
vram: &mut VRamManager, vram: &mut VRamManager,
) { ) {
map.set_scroll_pos((0u16, 0u16).into()); map.set_scroll_pos((0u16, 0u16).into());
let tile_set_ref = match which { let (tile_set_ref, palette) = match which {
SplashScreen::Start => { SplashScreen::Start => {
let tile_set_ref = vram.add_tileset(TileSet::new( let tile_set_ref = vram.add_tileset(TileSet::new(
splash_screens::splash.tiles, splash_screens::splash.tiles,
TileFormat::FourBpp, TileFormat::FourBpp,
)); ));
vram.set_background_palettes(splash_screens::splash.palettes); (tile_set_ref, splash_screens::splash.palettes)
tile_set_ref
} }
SplashScreen::End => { SplashScreen::End => {
let tile_set_ref = vram.add_tileset(TileSet::new( let tile_set_ref = vram.add_tileset(TileSet::new(
@ -36,9 +34,7 @@ pub fn show_splash_screen(
TileFormat::FourBpp, TileFormat::FourBpp,
)); ));
vram.set_background_palettes(splash_screens::thanks_for_playing.palettes); (tile_set_ref, splash_screens::thanks_for_playing.palettes)
tile_set_ref
} }
}; };
@ -71,6 +67,7 @@ pub fn show_splash_screen(
} }
map.commit(); map.commit();
vram.set_background_palettes(palette);
map.show(); map.show();
loop { loop {