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