agb/examples/the-dungeon-puzzlers-lament/src/backgrounds.rs
2023-08-29 15:17:50 +01:00

69 lines
1.9 KiB
Rust

use agb::{
display::tiled::{RegularMap, TileFormat, TileSet, VRamManager},
include_background_gfx,
};
include_background_gfx!(backgrounds, "1e151b",
ui => deduplicate "maps/ui_tiles.png",
level => deduplicate "maps/level.png",
ending => deduplicate "gfx/ending_page.aseprite",
);
mod tilemaps {
use super::backgrounds;
include!(concat!(env!("OUT_DIR"), "/tilemaps.rs"));
}
pub fn load_palettes(vram_manager: &mut VRamManager) {
vram_manager.set_background_palettes(backgrounds::PALETTES);
}
pub fn load_ui(map: &mut RegularMap, vram_manager: &mut VRamManager) {
let ui_tileset = TileSet::new(backgrounds::ui.tiles, TileFormat::FourBpp);
for y in 0..20u16 {
for x in 0..30u16 {
let tile_pos = y * 30 + x;
let tile_setting = tilemaps::UI_BACKGROUND_MAP[tile_pos as usize];
map.set_tile(vram_manager, (x, y).into(), &ui_tileset, tile_setting);
}
}
}
pub fn load_level_background(
map: &mut RegularMap,
vram_manager: &mut VRamManager,
level_number: usize,
) {
let level_map = &tilemaps::LEVELS_MAP[level_number];
let level_tileset = TileSet::new(backgrounds::level.tiles, TileFormat::FourBpp);
for y in 0..20u16 {
for x in 0..22u16 {
let tile_pos = y * 22 + x;
let tile_setting = level_map[tile_pos as usize];
map.set_tile(vram_manager, (x, y).into(), &level_tileset, tile_setting);
}
}
}
pub fn load_ending_page(map: &mut RegularMap, vram_manager: &mut VRamManager) {
let ending_tileset = TileSet::new(backgrounds::ending.tiles, TileFormat::FourBpp);
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],
);
}
}
}