Update the examples with the new tileset importing

This commit is contained in:
Gwilym Inzani 2023-08-30 17:07:14 +01:00
parent 2c556f9ce8
commit 4642a74a0f
6 changed files with 36 additions and 111 deletions

View file

@ -8,7 +8,7 @@ use alloc::boxed::Box;
use agb::{ use agb::{
display::{ display::{
tiled::{InfiniteScrolledMap, RegularBackgroundSize, TileFormat, TileSet}, tiled::{InfiniteScrolledMap, RegularBackgroundSize, TileFormat},
Priority, Priority,
}, },
fixnum::{Num, Vector2D}, fixnum::{Num, Vector2D},
@ -63,20 +63,12 @@ fn get_game(gba: &mut agb::Gba) -> Game {
let (tile, mut vram) = gba.display.video.tiled0(); let (tile, mut vram) = gba.display.video.tiled0();
let hat = TileSet::new(games::hat.tiles, TileFormat::EightBpp); let tiles = [
let purple = TileSet::new(games::purple.tiles, TileFormat::EightBpp); games::hat,
let hyperspace = TileSet::new(games::hyperspace.tiles, TileFormat::EightBpp); games::purple,
let dungeon_puzzler = TileSet::new(games::dungeon_puzzler.tiles, TileFormat::EightBpp); games::hyperspace,
let amplitude = TileSet::new(games::amplitude.tiles, TileFormat::EightBpp); games::dungeon_puzzler,
games::amplitude,
let tiles = [hat, purple, hyperspace, dungeon_puzzler, amplitude];
let tile_settings = &[
games::hat.tile_settings,
games::purple.tile_settings,
games::hyperspace.tile_settings,
games::dungeon_puzzler.tile_settings,
games::amplitude.tile_settings,
]; ];
vram.set_background_palettes(games::PALETTES); vram.set_background_palettes(games::PALETTES);
@ -93,7 +85,7 @@ fn get_game(gba: &mut agb::Gba) -> Game {
let game = (pos.x).rem_euclid(tiles.len() as i32 * 30) as usize / 30; let game = (pos.x).rem_euclid(tiles.len() as i32 * 30) as usize / 30;
let tile_id = (y * 30 + x) as usize; let tile_id = (y * 30 + x) as usize;
(&tiles[game], tile_settings[game][tile_id]) (&tiles[game].tiles, tiles[game].tile_settings[tile_id])
}), }),
); );

View file

@ -1,5 +1,5 @@
use agb::{ use agb::{
display::tiled::{RegularMap, TileFormat, TileSet, TileSetting, TiledMap, VRamManager}, display::tiled::{RegularMap, TileSet, TileSetting, TiledMap, VRamManager},
include_background_gfx, rng, include_background_gfx, rng,
}; };
@ -23,10 +23,7 @@ pub(crate) fn load_help_text(
help_text_line: u16, help_text_line: u16,
at_tile: (u16, u16), at_tile: (u16, u16),
) { ) {
let help_tileset = TileSet::new( let help_tiledata = backgrounds::help;
backgrounds::help.tiles,
agb::display::tiled::TileFormat::FourBpp,
);
for x in 0..16 { for x in 0..16 {
let tile_id = help_text_line * 16 + x; let tile_id = help_text_line * 16 + x;
@ -34,8 +31,8 @@ pub(crate) fn load_help_text(
background.set_tile( background.set_tile(
vram, vram,
(x + at_tile.0, at_tile.1).into(), (x + at_tile.0, at_tile.1).into(),
&help_tileset, &help_tiledata.tiles,
backgrounds::help.tile_settings[tile_id as usize], help_tiledata.tile_settings[tile_id as usize],
) )
} }
} }
@ -45,22 +42,10 @@ pub(crate) fn load_description(
descriptions_map: &mut RegularMap, descriptions_map: &mut RegularMap,
vram: &mut VRamManager, vram: &mut VRamManager,
) { ) {
let (tileset, tile_settings) = if face_id < 10 { let description_data = if face_id < 10 {
( backgrounds::descriptions1
TileSet::new(
backgrounds::descriptions1.tiles,
agb::display::tiled::TileFormat::FourBpp,
),
backgrounds::descriptions1.tile_settings,
)
} else { } else {
( backgrounds::descriptions2
TileSet::new(
backgrounds::descriptions2.tiles,
agb::display::tiled::TileFormat::FourBpp,
),
backgrounds::descriptions2.tile_settings,
)
}; };
for y in 0..11 { for y in 0..11 {
@ -69,8 +54,8 @@ pub(crate) fn load_description(
descriptions_map.set_tile( descriptions_map.set_tile(
vram, vram,
(x, y).into(), (x, y).into(),
&tileset, &description_data.tiles,
tile_settings[tile_id as usize], description_data.tile_settings[tile_id as usize],
) )
} }
} }
@ -83,7 +68,7 @@ fn create_background_map(map: &mut RegularMap, vram: &mut VRamManager, stars_til
let blank = rng::gen().rem_euclid(32) < 30; let blank = rng::gen().rem_euclid(32) < 30;
let tile_setting = if blank { let tile_setting = if blank {
TileSetting::new((1 << 10) - 1, false, false, 0) TileSetting::BLANK
} else { } else {
let tile_id = rng::gen().rem_euclid(64) as u16; let tile_id = rng::gen().rem_euclid(64) as u16;
backgrounds::stars.tile_settings[tile_id as usize] backgrounds::stars.tile_settings[tile_id as usize]
@ -99,26 +84,10 @@ fn create_background_map(map: &mut RegularMap, vram: &mut VRamManager, stars_til
pub fn show_title_screen(background: &mut RegularMap, vram: &mut VRamManager, sfx: &mut Sfx) { pub fn show_title_screen(background: &mut RegularMap, vram: &mut VRamManager, sfx: &mut Sfx) {
background.set_scroll_pos((0i16, 0).into()); background.set_scroll_pos((0i16, 0).into());
vram.set_background_palettes(backgrounds::PALETTES); vram.set_background_palettes(backgrounds::PALETTES);
let tile_set = TileSet::new(
backgrounds::title.tiles,
agb::display::tiled::TileFormat::FourBpp,
);
background.hide(); background.hide();
for x in 0..30u16 { background.fill_with(vram, &backgrounds::title);
for y in 0..20u16 {
let tile_id = y * 30 + x;
background.set_tile(
vram,
(x, y).into(),
&tile_set,
backgrounds::title.tile_settings[tile_id as usize],
);
}
sfx.frame();
}
background.commit(vram); background.commit(vram);
sfx.frame(); sfx.frame();
background.show(); background.show();
@ -138,9 +107,8 @@ impl<'a> StarBackground<'a> {
background2: &'a mut RegularMap, background2: &'a mut RegularMap,
vram: &'_ mut VRamManager, vram: &'_ mut VRamManager,
) -> Self { ) -> Self {
let stars_tileset = TileSet::new(backgrounds::stars.tiles, TileFormat::FourBpp); create_background_map(background1, vram, &backgrounds::stars.tiles);
create_background_map(background1, vram, &stars_tileset); create_background_map(background2, vram, &backgrounds::stars.tiles);
create_background_map(background2, vram, &stars_tileset);
Self { Self {
background1, background1,

View file

@ -1,5 +1,5 @@
use agb::{ use agb::{
display::tiled::{RegularMap, TileFormat, TileSet, VRamManager}, display::tiled::{RegularMap, VRamManager},
include_background_gfx, include_background_gfx,
}; };
@ -19,7 +19,7 @@ pub fn load_palettes(vram_manager: &mut VRamManager) {
} }
pub fn load_ui(map: &mut RegularMap, vram_manager: &mut VRamManager) { pub fn load_ui(map: &mut RegularMap, vram_manager: &mut VRamManager) {
let ui_tileset = TileSet::new(backgrounds::ui.tiles, TileFormat::FourBpp); let ui_tileset = backgrounds::ui.tiles;
for y in 0..20u16 { for y in 0..20u16 {
for x in 0..30u16 { for x in 0..30u16 {
@ -38,7 +38,7 @@ pub fn load_level_background(
) { ) {
let level_map = &tilemaps::LEVELS_MAP[level_number]; let level_map = &tilemaps::LEVELS_MAP[level_number];
let level_tileset = TileSet::new(backgrounds::level.tiles, TileFormat::FourBpp); let level_tileset = backgrounds::level.tiles;
for y in 0..20u16 { for y in 0..20u16 {
for x in 0..22u16 { for x in 0..22u16 {
@ -51,18 +51,5 @@ pub fn load_level_background(
} }
pub fn load_ending_page(map: &mut RegularMap, vram_manager: &mut VRamManager) { pub fn load_ending_page(map: &mut RegularMap, vram_manager: &mut VRamManager) {
let ending_tileset = TileSet::new(backgrounds::ending.tiles, TileFormat::FourBpp); map.fill_with(vram_manager, &backgrounds::ending);
for y in 0..20u16 {
for x in 0..30u16 {
let tile_pos = y * 30 + x;
map.set_tile(
vram_manager,
(x, y).into(),
&ending_tileset,
backgrounds::ending.tile_settings[tile_pos as usize],
);
}
}
} }

View file

@ -10,8 +10,8 @@ use agb::{
display::{ display::{
object::{Graphics, OamManaged, Object, Tag, TagMap}, object::{Graphics, OamManaged, Object, Tag, TagMap},
tiled::{ tiled::{
InfiniteScrolledMap, PartialUpdateStatus, RegularBackgroundSize, TileFormat, TileSet, InfiniteScrolledMap, PartialUpdateStatus, RegularBackgroundSize, TileFormat, TiledMap,
TiledMap, VRamManager, VRamManager,
}, },
Priority, HEIGHT, WIDTH, Priority, HEIGHT, WIDTH,
}, },
@ -793,7 +793,7 @@ pub fn main(mut agb: agb::Gba) -> ! {
TileFormat::FourBpp, TileFormat::FourBpp,
); );
let tileset = TileSet::new(tile_sheet::background.tiles, TileFormat::FourBpp); let tileset = tile_sheet::background.tiles;
for y in 0..32u16 { for y in 0..32u16 {
for x in 0..32u16 { for x in 0..32u16 {

View file

@ -1,5 +1,5 @@
use super::sfx::SfxPlayer; use super::sfx::SfxPlayer;
use agb::display::tiled::{RegularMap, TileFormat, TileSet, TiledMap, VRamManager}; use agb::display::tiled::{RegularMap, TiledMap, VRamManager};
agb::include_background_gfx!(splash_screens, agb::include_background_gfx!(splash_screens,
splash => deduplicate "gfx/splash.png", splash => deduplicate "gfx/splash.png",
@ -18,19 +18,9 @@ pub fn show_splash_screen(
vram: &mut VRamManager, vram: &mut VRamManager,
) { ) {
map.set_scroll_pos((0i16, 0i16).into()); map.set_scroll_pos((0i16, 0i16).into());
let (tileset, settings) = match which { let tile_data = match which {
SplashScreen::Start => ( SplashScreen::Start => splash_screens::splash,
TileSet::new(splash_screens::splash.tiles, TileFormat::FourBpp), SplashScreen::End => splash_screens::thanks_for_playing,
splash_screens::splash.tile_settings,
),
SplashScreen::End => (
TileSet::new(
splash_screens::thanks_for_playing.tiles,
TileFormat::FourBpp,
),
splash_screens::thanks_for_playing.tile_settings,
),
}; };
let vblank = agb::interrupt::VBlank::get(); let vblank = agb::interrupt::VBlank::get();
@ -40,19 +30,7 @@ pub fn show_splash_screen(
sfx.frame(); sfx.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
for y in 0..20u16 { map.fill_with(vram, &tile_data);
for x in 0..30u16 {
map.set_tile(
vram,
(x, y).into(),
&tileset,
settings[(y * 30 + x) as usize],
);
}
sfx.frame();
vblank.wait_for_vblank();
}
map.commit(vram); map.commit(vram);
vram.set_background_palettes(splash_screens::PALETTES); vram.set_background_palettes(splash_screens::PALETTES);

View file

@ -15,7 +15,7 @@ use alloc::{boxed::Box, vec::Vec};
use agb::{ use agb::{
display::{ display::{
object::{Graphics, OamManaged, Object, Sprite, Tag, TagMap}, object::{Graphics, OamManaged, Object, Sprite, Tag, TagMap},
tiled::{InfiniteScrolledMap, RegularBackgroundSize, TileFormat, TileSet, VRamManager}, tiled::{InfiniteScrolledMap, RegularBackgroundSize, TileFormat, VRamManager},
Priority, HEIGHT, WIDTH, Priority, HEIGHT, WIDTH,
}, },
fixnum::{num, FixedNum, Rect, Vector2D}, fixnum::{num, FixedNum, Rect, Vector2D},
@ -2191,7 +2191,7 @@ fn game_with_level(gba: &mut agb::Gba) {
let (background, mut vram) = gba.display.video.tiled0(); let (background, mut vram) = gba.display.video.tiled0();
vram.set_background_palettes(background::PALETTES); vram.set_background_palettes(background::PALETTES);
let tileset = TileSet::new(background::background.tiles, TileFormat::FourBpp); let tileset = background::background.tiles;
let object = gba.display.object.get_managed(); let object = gba.display.object.get_managed();
loop { loop {