2022-12-02 04:16:53 +11:00
|
|
|
#![no_std]
|
|
|
|
#![cfg_attr(test, feature(custom_test_frameworks))]
|
|
|
|
#![cfg_attr(test, reexport_test_harness_main = "test_main")]
|
|
|
|
#![cfg_attr(test, test_runner(agb::test_runner::test_runner))]
|
|
|
|
|
|
|
|
extern crate alloc;
|
|
|
|
use alloc::boxed::Box;
|
|
|
|
|
|
|
|
use agb::{
|
|
|
|
display::{
|
2023-10-25 08:04:50 +11:00
|
|
|
tile_data::TileData,
|
2023-08-31 02:07:14 +10:00
|
|
|
tiled::{InfiniteScrolledMap, RegularBackgroundSize, TileFormat},
|
2022-12-02 04:16:53 +11:00
|
|
|
Priority,
|
|
|
|
},
|
|
|
|
fixnum::{Num, Vector2D},
|
2023-04-19 05:29:45 +10:00
|
|
|
include_background_gfx,
|
2022-12-02 04:16:53 +11:00
|
|
|
input::Button,
|
|
|
|
};
|
|
|
|
|
2023-10-25 07:38:52 +11:00
|
|
|
type Game = fn(agb::Gba) -> !;
|
2022-12-02 04:16:53 +11:00
|
|
|
|
2023-10-25 08:04:50 +11:00
|
|
|
struct GameWithTiles {
|
|
|
|
game: fn(agb::Gba) -> !,
|
2023-12-11 03:35:15 +11:00
|
|
|
tiles: &'static TileData,
|
2023-10-25 08:04:50 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
impl GameWithTiles {
|
2023-12-11 03:35:15 +11:00
|
|
|
const fn new(tiles: &'static TileData, game: fn(agb::Gba) -> !) -> Self {
|
2023-10-25 08:04:50 +11:00
|
|
|
GameWithTiles { game, tiles }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-11 03:35:15 +11:00
|
|
|
static GAMES: &[GameWithTiles] = &[
|
|
|
|
GameWithTiles::new(&games::hat, the_hat_chooses_the_wizard::main),
|
|
|
|
GameWithTiles::new(&games::purple, the_purple_night::main),
|
|
|
|
GameWithTiles::new(&games::hyperspace, hyperspace_roll::main),
|
|
|
|
GameWithTiles::new(&games::dungeon_puzzler, the_dungeon_puzzlers_lament::entry),
|
|
|
|
GameWithTiles::new(&games::amplitude, amplitude::main),
|
2023-10-25 07:38:52 +11:00
|
|
|
];
|
2022-12-02 04:16:53 +11:00
|
|
|
|
2023-04-19 05:29:45 +10:00
|
|
|
include_background_gfx!(
|
|
|
|
games, "121105",
|
2023-08-30 01:07:50 +10:00
|
|
|
hat => 256 deduplicate "gfx/hat.png",
|
|
|
|
purple => 256 deduplicate "gfx/purple.png",
|
|
|
|
hyperspace => 256 deduplicate "gfx/hyperspace.png",
|
2023-08-30 01:17:14 +10:00
|
|
|
dungeon_puzzler => 256 deduplicate "gfx/dungeon_puzzler.png",
|
|
|
|
amplitude => 256 deduplicate "gfx/amplitude.png",
|
2023-04-19 05:29:45 +10:00
|
|
|
);
|
2022-12-02 04:16:53 +11:00
|
|
|
|
|
|
|
fn get_game(gba: &mut agb::Gba) -> Game {
|
|
|
|
let mut input = agb::input::ButtonController::new();
|
|
|
|
let vblank = agb::interrupt::VBlank::get();
|
|
|
|
|
|
|
|
let (tile, mut vram) = gba.display.video.tiled0();
|
|
|
|
|
|
|
|
vram.set_background_palettes(games::PALETTES);
|
|
|
|
|
|
|
|
let mut bg = InfiniteScrolledMap::new(
|
2023-02-24 19:55:02 +11:00
|
|
|
tile.background(
|
|
|
|
Priority::P0,
|
|
|
|
RegularBackgroundSize::Background32x32,
|
2023-08-30 01:07:50 +10:00
|
|
|
TileFormat::EightBpp,
|
2023-02-24 19:55:02 +11:00
|
|
|
),
|
2022-12-02 04:16:53 +11:00
|
|
|
Box::new(|pos| {
|
|
|
|
let y = pos.y.rem_euclid(20);
|
|
|
|
let x = pos.x.rem_euclid(30);
|
|
|
|
|
2023-10-25 08:04:50 +11:00
|
|
|
let game = (pos.x).rem_euclid(GAMES.len() as i32 * 30) as usize / 30;
|
2022-12-02 04:16:53 +11:00
|
|
|
let tile_id = (y * 30 + x) as usize;
|
2023-10-25 08:04:50 +11:00
|
|
|
(
|
|
|
|
&GAMES[game].tiles.tiles,
|
|
|
|
GAMES[game].tiles.tile_settings[tile_id],
|
|
|
|
)
|
2022-12-02 04:16:53 +11:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
bg.init(&mut vram, (0, 0).into(), &mut || {});
|
|
|
|
|
|
|
|
bg.set_pos(&mut vram, (0, 0).into());
|
|
|
|
bg.commit(&mut vram);
|
2024-02-16 21:15:38 +11:00
|
|
|
bg.set_visible(true);
|
2022-12-02 04:16:53 +11:00
|
|
|
|
|
|
|
let mut position: Vector2D<Num<i32, 8>> = (0, 0).into();
|
|
|
|
let mut game_idx = 0;
|
|
|
|
let game = loop {
|
|
|
|
let lr: agb::input::Tri = (
|
|
|
|
input.is_just_pressed(Button::LEFT),
|
|
|
|
input.is_just_pressed(Button::RIGHT),
|
|
|
|
)
|
|
|
|
.into();
|
|
|
|
|
|
|
|
game_idx += lr as i32;
|
|
|
|
|
|
|
|
if (position.x - game_idx * 30 * 8).abs() < Num::new(1) / 2 {
|
|
|
|
position.x = Num::new(game_idx * 30 * 8);
|
|
|
|
}
|
|
|
|
|
2024-04-05 10:43:19 +11:00
|
|
|
position.x += (Num::new(game_idx * 30 * 8) - position.x) / 8;
|
2022-12-02 04:16:53 +11:00
|
|
|
|
|
|
|
bg.set_pos(&mut vram, position.floor());
|
|
|
|
|
|
|
|
vblank.wait_for_vblank();
|
|
|
|
bg.commit(&mut vram);
|
|
|
|
input.update();
|
|
|
|
|
|
|
|
if input.is_just_pressed(Button::A) {
|
2023-10-25 08:04:50 +11:00
|
|
|
break GAMES[game_idx.rem_euclid(GAMES.len() as i32) as usize].game;
|
2022-12-02 04:16:53 +11:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-02-16 21:15:38 +11:00
|
|
|
bg.set_visible(false);
|
2022-12-02 04:16:53 +11:00
|
|
|
bg.clear(&mut vram);
|
|
|
|
bg.commit(&mut vram);
|
|
|
|
|
|
|
|
game
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main(mut gba: agb::Gba) -> ! {
|
2023-10-25 07:38:52 +11:00
|
|
|
get_game(&mut gba)(gba)
|
2022-12-02 04:16:53 +11:00
|
|
|
}
|