mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 09:31:34 +11:00
Update the games to use the new method
This commit is contained in:
parent
16ea04d012
commit
003c0d7e1a
|
@ -9,7 +9,7 @@ use crate::{
|
|||
|
||||
pub struct InfiniteScrolledMap<'a> {
|
||||
map: MapLoan<'a, RegularMap>,
|
||||
tile: Box<dyn Fn(Vector2D<i32>) -> (&'a TileSet<'a>, TileSetting)>,
|
||||
tile: Box<dyn Fn(Vector2D<i32>) -> (&'a TileSet<'a>, TileSetting) + 'a>,
|
||||
|
||||
current_pos: Vector2D<i32>,
|
||||
offset: Vector2D<i32>,
|
||||
|
@ -26,7 +26,7 @@ pub enum PartialUpdateStatus {
|
|||
impl<'a> InfiniteScrolledMap<'a> {
|
||||
pub fn new(
|
||||
map: MapLoan<'a, RegularMap>,
|
||||
tile: Box<dyn Fn(Vector2D<i32>) -> (&'a TileSet<'a>, TileSetting)>,
|
||||
tile: Box<dyn Fn(Vector2D<i32>) -> (&'a TileSet<'a>, TileSetting) + 'a>,
|
||||
) -> Self {
|
||||
Self {
|
||||
map,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use agb::display::{
|
||||
tiled::{RegularMap, TileSetReference, TileSetting, VRamManager},
|
||||
tiled::{RegularMap, TileSet, TileSetting, VRamManager},
|
||||
HEIGHT, WIDTH,
|
||||
};
|
||||
|
||||
|
@ -12,7 +12,7 @@ pub fn write_level(
|
|||
map: &mut RegularMap,
|
||||
world: u32,
|
||||
level: u32,
|
||||
tile_set_ref: TileSetReference,
|
||||
tileset: &'_ TileSet<'_>,
|
||||
vram: &mut VRamManager,
|
||||
) {
|
||||
for (i, &tile) in [
|
||||
|
@ -30,7 +30,7 @@ pub fn write_level(
|
|||
map.set_tile(
|
||||
vram,
|
||||
(i as u16, 0).into(),
|
||||
tile_set_ref,
|
||||
&tileset,
|
||||
TileSetting::from_raw(tile),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -783,17 +783,14 @@ fn main(mut agb: agb::Gba) -> ! {
|
|||
let mut splash_screen = tiled.background(Priority::P0);
|
||||
let mut world_display = tiled.background(Priority::P0);
|
||||
|
||||
let tile_set_ref = vram.add_tileset(TileSet::new(
|
||||
tile_sheet::background.tiles,
|
||||
TileFormat::FourBpp,
|
||||
));
|
||||
let tileset = TileSet::new(tile_sheet::background.tiles, TileFormat::FourBpp);
|
||||
|
||||
for y in 0..32u16 {
|
||||
for x in 0..32u16 {
|
||||
world_display.set_tile(
|
||||
&mut vram,
|
||||
(x, y).into(),
|
||||
tile_set_ref,
|
||||
&tileset,
|
||||
TileSetting::from_raw(level_display::BLANK),
|
||||
);
|
||||
}
|
||||
|
@ -837,7 +834,7 @@ fn main(mut agb: agb::Gba) -> ! {
|
|||
&mut world_display,
|
||||
current_level / 8 + 1,
|
||||
current_level % 8 + 1,
|
||||
tile_set_ref,
|
||||
&tileset,
|
||||
&mut vram,
|
||||
);
|
||||
|
||||
|
@ -849,12 +846,13 @@ fn main(mut agb: agb::Gba) -> ! {
|
|||
vblank.wait_for_vblank();
|
||||
mixer.after_vblank();
|
||||
|
||||
let map_current_level = current_level;
|
||||
let mut background = InfiniteScrolledMap::new(
|
||||
tiled.background(Priority::P2),
|
||||
Box::new(move |pos: Vector2D<i32>| {
|
||||
let level = &map_tiles::LEVELS[current_level as usize];
|
||||
Box::new(|pos: Vector2D<i32>| {
|
||||
let level = &map_tiles::LEVELS[map_current_level as usize];
|
||||
(
|
||||
tile_set_ref,
|
||||
&tileset,
|
||||
TileSetting::from_raw(
|
||||
*level
|
||||
.background
|
||||
|
@ -866,10 +864,10 @@ fn main(mut agb: agb::Gba) -> ! {
|
|||
);
|
||||
let mut foreground = InfiniteScrolledMap::new(
|
||||
tiled.background(Priority::P0),
|
||||
Box::new(move |pos: Vector2D<i32>| {
|
||||
let level = &map_tiles::LEVELS[current_level as usize];
|
||||
Box::new(|pos: Vector2D<i32>| {
|
||||
let level = &map_tiles::LEVELS[map_current_level as usize];
|
||||
(
|
||||
tile_set_ref,
|
||||
&tileset,
|
||||
TileSetting::from_raw(
|
||||
*level
|
||||
.foreground
|
||||
|
|
|
@ -19,22 +19,19 @@ pub fn show_splash_screen(
|
|||
vram: &mut VRamManager,
|
||||
) {
|
||||
map.set_scroll_pos((0u16, 0u16).into());
|
||||
let (tile_set_ref, palette) = match which {
|
||||
let (tileset, palette) = match which {
|
||||
SplashScreen::Start => {
|
||||
let tile_set_ref = vram.add_tileset(TileSet::new(
|
||||
splash_screens::splash.tiles,
|
||||
TileFormat::FourBpp,
|
||||
));
|
||||
let tileset = TileSet::new(splash_screens::splash.tiles, TileFormat::FourBpp);
|
||||
|
||||
(tile_set_ref, splash_screens::splash.palettes)
|
||||
(tileset, splash_screens::splash.palettes)
|
||||
}
|
||||
SplashScreen::End => {
|
||||
let tile_set_ref = vram.add_tileset(TileSet::new(
|
||||
let tileset = TileSet::new(
|
||||
splash_screens::thanks_for_playing.tiles,
|
||||
TileFormat::FourBpp,
|
||||
));
|
||||
);
|
||||
|
||||
(tile_set_ref, splash_screens::thanks_for_playing.palettes)
|
||||
(tileset, splash_screens::thanks_for_playing.palettes)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -60,7 +57,7 @@ pub fn show_splash_screen(
|
|||
map.set_tile(
|
||||
vram,
|
||||
(x, y).into(),
|
||||
tile_set_ref,
|
||||
&tileset,
|
||||
TileSetting::from_raw(y * 30 + x),
|
||||
);
|
||||
}
|
||||
|
@ -108,6 +105,4 @@ pub fn show_splash_screen(
|
|||
|
||||
map.hide();
|
||||
map.clear(vram);
|
||||
|
||||
vram.remove_tileset(tile_set_ref);
|
||||
}
|
||||
|
|
|
@ -2223,18 +2223,15 @@ fn game_with_level(gba: &mut agb::Gba) {
|
|||
|
||||
vram.set_background_palettes(background::background.palettes);
|
||||
|
||||
let tileset_ref = vram.add_tileset(TileSet::new(
|
||||
background::background.tiles,
|
||||
TileFormat::FourBpp,
|
||||
));
|
||||
let tileset = TileSet::new(background::background.tiles, TileFormat::FourBpp);
|
||||
|
||||
let object = gba.display.object.get();
|
||||
|
||||
let backdrop = InfiniteScrolledMap::new(
|
||||
background.background(Priority::P2),
|
||||
Box::new(move |pos| {
|
||||
Box::new(|pos| {
|
||||
(
|
||||
tileset_ref,
|
||||
&tileset,
|
||||
TileSetting::from_raw(
|
||||
*tilemap::BACKGROUND_MAP
|
||||
.get((pos.x + tilemap::WIDTH * pos.y) as usize)
|
||||
|
@ -2246,9 +2243,9 @@ fn game_with_level(gba: &mut agb::Gba) {
|
|||
|
||||
let foreground = InfiniteScrolledMap::new(
|
||||
background.background(Priority::P0),
|
||||
Box::new(move |pos| {
|
||||
Box::new(|pos| {
|
||||
(
|
||||
tileset_ref,
|
||||
&tileset,
|
||||
TileSetting::from_raw(
|
||||
*tilemap::FOREGROUND_MAP
|
||||
.get((pos.x + tilemap::WIDTH * pos.y) as usize)
|
||||
|
@ -2260,9 +2257,9 @@ fn game_with_level(gba: &mut agb::Gba) {
|
|||
|
||||
let clouds = InfiniteScrolledMap::new(
|
||||
background.background(Priority::P3),
|
||||
Box::new(move |pos| {
|
||||
Box::new(|pos| {
|
||||
(
|
||||
tileset_ref,
|
||||
&tileset,
|
||||
TileSetting::from_raw(
|
||||
*tilemap::CLOUD_MAP
|
||||
.get((pos.x + tilemap::WIDTH * pos.y) as usize)
|
||||
|
|
Loading…
Reference in a new issue