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-08-30 00:20:41 +10:00
|
|
|
tiled::{InfiniteScrolledMap, RegularBackgroundSize, TileFormat, TileSet},
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
|
|
|
pub enum Game {
|
|
|
|
TheHatChoosesTheWizard,
|
|
|
|
ThePurpleNight,
|
|
|
|
HyperspaceRoll,
|
2023-04-26 05:57:18 +10:00
|
|
|
Amplitude,
|
2022-12-02 04:16:53 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Game {
|
|
|
|
fn launch_game(self, gba: agb::Gba) -> ! {
|
|
|
|
match self {
|
|
|
|
Game::TheHatChoosesTheWizard => the_hat_chooses_the_wizard::main(gba),
|
|
|
|
Game::ThePurpleNight => the_purple_night::main(gba),
|
|
|
|
Game::HyperspaceRoll => hyperspace_roll::main(gba),
|
2023-04-26 05:57:18 +10:00
|
|
|
Game::Amplitude => amplitude::main(gba),
|
2022-12-02 04:16:53 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn from_index(index: i32) -> Game {
|
2023-04-26 10:34:25 +10:00
|
|
|
match index.rem_euclid(4) {
|
2022-12-02 04:16:53 +11:00
|
|
|
0 => Game::TheHatChoosesTheWizard,
|
|
|
|
1 => Game::ThePurpleNight,
|
|
|
|
2 => Game::HyperspaceRoll,
|
2023-04-26 05:57:18 +10:00
|
|
|
3 => Game::Amplitude,
|
2022-12-02 04:16:53 +11:00
|
|
|
_ => unreachable!("game out of index in an unreachable manner"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-19 05:29:45 +10:00
|
|
|
include_background_gfx!(
|
|
|
|
games, "121105",
|
2023-08-29 22:16:57 +10:00
|
|
|
hat => deduplicate "gfx/hat.png",
|
|
|
|
purple => deduplicate "gfx/purple.png",
|
|
|
|
hyperspace => deduplicate "gfx/hyperspace.png",
|
|
|
|
amplitude => 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();
|
|
|
|
|
|
|
|
let hat = TileSet::new(games::hat.tiles, TileFormat::FourBpp);
|
|
|
|
let purple = TileSet::new(games::purple.tiles, TileFormat::FourBpp);
|
|
|
|
let hyperspace = TileSet::new(games::hyperspace.tiles, TileFormat::FourBpp);
|
2023-04-26 05:57:18 +10:00
|
|
|
let amplitude = TileSet::new(games::amplitude.tiles, TileFormat::FourBpp);
|
2022-12-02 04:16:53 +11:00
|
|
|
|
2023-04-26 05:57:18 +10:00
|
|
|
let tiles = [hat, purple, hyperspace, amplitude];
|
2022-12-02 04:16:53 +11:00
|
|
|
|
2023-08-30 00:20:41 +10:00
|
|
|
let tile_settings = &[
|
|
|
|
games::hat.tile_settings,
|
|
|
|
games::purple.tile_settings,
|
|
|
|
games::hyperspace.tile_settings,
|
|
|
|
games::amplitude.tile_settings,
|
2022-12-02 04:16:53 +11:00
|
|
|
];
|
|
|
|
|
|
|
|
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,
|
|
|
|
TileFormat::FourBpp,
|
|
|
|
),
|
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-04-26 05:57:18 +10:00
|
|
|
let game = (pos.x).rem_euclid(tiles.len() as i32 * 30) as usize / 30;
|
2022-12-02 04:16:53 +11:00
|
|
|
let tile_id = (y * 30 + x) as usize;
|
2023-08-30 00:20:41 +10:00
|
|
|
(&tiles[game], tile_settings[game][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);
|
|
|
|
bg.show();
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
position.x +=
|
|
|
|
((Num::new(game_idx * 30 * 8) - position.x) / 8).clamp(-Num::new(8), Num::new(8));
|
|
|
|
|
|
|
|
bg.set_pos(&mut vram, position.floor());
|
|
|
|
|
|
|
|
vblank.wait_for_vblank();
|
|
|
|
bg.commit(&mut vram);
|
|
|
|
input.update();
|
|
|
|
|
|
|
|
if input.is_just_pressed(Button::A) {
|
|
|
|
break Game::from_index(game_idx);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bg.hide();
|
|
|
|
bg.clear(&mut vram);
|
|
|
|
bg.commit(&mut vram);
|
|
|
|
|
|
|
|
game
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main(mut gba: agb::Gba) -> ! {
|
|
|
|
get_game(&mut gba).launch_game(gba)
|
|
|
|
}
|