mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 17:41:33 +11:00
Fix the games
This commit is contained in:
parent
92066f7adb
commit
b90a5829b8
|
@ -90,7 +90,7 @@ pub struct PlayerDice {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Agb<'a> {
|
struct Agb<'a> {
|
||||||
obj: ObjectController,
|
obj: ObjectController<'a>,
|
||||||
vblank: VBlank,
|
vblank: VBlank,
|
||||||
star_background: StarBackground<'a>,
|
star_background: StarBackground<'a>,
|
||||||
vram: VRamManager,
|
vram: VRamManager,
|
||||||
|
@ -101,7 +101,7 @@ pub fn main(mut gba: agb::Gba) -> ! {
|
||||||
save::init_save(&mut gba).expect("Could not initialize save game");
|
save::init_save(&mut gba).expect("Could not initialize save game");
|
||||||
|
|
||||||
if save::load_high_score() > 1000 {
|
if save::load_high_score() > 1000 {
|
||||||
save::save_high_score(&mut gba, 0).expect("Could not reset high score");
|
save::save_high_score(&mut gba.save, 0).expect("Could not reset high score");
|
||||||
}
|
}
|
||||||
|
|
||||||
let gfx = gba.display.object.get();
|
let gfx = gba.display.object.get();
|
||||||
|
@ -208,7 +208,7 @@ pub fn main(mut gba: agb::Gba) -> ! {
|
||||||
agb.obj.commit();
|
agb.obj.commit();
|
||||||
agb.sfx.customise();
|
agb.sfx.customise();
|
||||||
if save::load_high_score() < current_level {
|
if save::load_high_score() < current_level {
|
||||||
save::save_high_score(&mut gba, current_level)
|
save::save_high_score(&mut gba.save, current_level)
|
||||||
.expect("Could not save high score");
|
.expect("Could not save high score");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use agb::save::Error;
|
use agb::save::{Error, SaveManager};
|
||||||
use agb::sync::Static;
|
use agb::sync::Static;
|
||||||
use agb::Gba;
|
use agb::Gba;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ pub fn init_save(gba: &mut Gba) -> Result<(), Error> {
|
||||||
if buffer[0] != 0 {
|
if buffer[0] != 0 {
|
||||||
access.prepare_write(0..1)?.write(0, &[0])?;
|
access.prepare_write(0..1)?.write(0, &[0])?;
|
||||||
core::mem::drop(access);
|
core::mem::drop(access);
|
||||||
save_high_score(gba, 0)?;
|
save_high_score(&mut gba.save, 0)?;
|
||||||
} else {
|
} else {
|
||||||
let mut buffer = [0; 4];
|
let mut buffer = [0; 4];
|
||||||
access.read(1, &mut buffer)?;
|
access.read(1, &mut buffer)?;
|
||||||
|
@ -35,9 +35,8 @@ pub fn load_high_score() -> u32 {
|
||||||
HIGH_SCORE.read()
|
HIGH_SCORE.read()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_high_score(gba: &mut Gba, score: u32) -> Result<(), Error> {
|
pub fn save_high_score(save: &mut SaveManager, score: u32) -> Result<(), Error> {
|
||||||
gba.save
|
save.access()?
|
||||||
.access()?
|
|
||||||
.prepare_write(1..5)?
|
.prepare_write(1..5)?
|
||||||
.write(1, &score.to_le_bytes())?;
|
.write(1, &score.to_le_bytes())?;
|
||||||
HIGH_SCORE.write(score);
|
HIGH_SCORE.write(score);
|
||||||
|
|
|
@ -45,14 +45,14 @@ enum BattleOrMenu {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Sfx<'a> {
|
pub struct Sfx<'a> {
|
||||||
mixer: &'a mut Mixer,
|
mixer: &'a mut Mixer<'a>,
|
||||||
state: BattleOrMenu,
|
state: BattleOrMenu,
|
||||||
|
|
||||||
current_bgm: ChannelId,
|
current_bgm: ChannelId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Sfx<'a> {
|
impl<'a> Sfx<'a> {
|
||||||
pub fn new(mixer: &'a mut Mixer) -> Self {
|
pub fn new(mixer: &'a mut Mixer<'a>) -> Self {
|
||||||
let mut title_music = SoundChannel::new_high_priority(TITLE_BGM);
|
let mut title_music = SoundChannel::new_high_priority(TITLE_BGM);
|
||||||
title_music.should_loop();
|
title_music.should_loop();
|
||||||
let title_channel = mixer.play_sound(title_music).unwrap();
|
let title_channel = mixer.play_sound(title_music).unwrap();
|
||||||
|
|
|
@ -20,6 +20,7 @@ use agb::{
|
||||||
sound::mixer::Frequency,
|
sound::mixer::Frequency,
|
||||||
};
|
};
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
|
use sfx::SfxPlayer;
|
||||||
|
|
||||||
mod enemies;
|
mod enemies;
|
||||||
mod level_display;
|
mod level_display;
|
||||||
|
@ -693,7 +694,7 @@ impl<'a, 'b> PlayingLevel<'a, 'b> {
|
||||||
|
|
||||||
fn update_frame(
|
fn update_frame(
|
||||||
&mut self,
|
&mut self,
|
||||||
sfx_player: &mut sfx::SfxPlayer,
|
sfx_player: &mut SfxPlayer,
|
||||||
vram: &mut VRamManager,
|
vram: &mut VRamManager,
|
||||||
controller: &'a ObjectController,
|
controller: &'a ObjectController,
|
||||||
) -> UpdateState {
|
) -> UpdateState {
|
||||||
|
@ -798,13 +799,17 @@ pub fn main(mut agb: agb::Gba) -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut mixer = agb.mixer.mixer(Frequency::Hz10512);
|
||||||
|
|
||||||
|
mixer.enable();
|
||||||
|
let mut sfx = sfx::SfxPlayer::new(&mut mixer);
|
||||||
|
|
||||||
world_display.commit(&mut vram);
|
world_display.commit(&mut vram);
|
||||||
world_display.show();
|
world_display.show();
|
||||||
|
|
||||||
splash_screen::show_splash_screen(
|
splash_screen::show_splash_screen(
|
||||||
splash_screen::SplashScreen::Start,
|
splash_screen::SplashScreen::Start,
|
||||||
None,
|
&mut sfx,
|
||||||
None,
|
|
||||||
&mut splash_screen,
|
&mut splash_screen,
|
||||||
&mut vram,
|
&mut vram,
|
||||||
);
|
);
|
||||||
|
@ -816,10 +821,6 @@ pub fn main(mut agb: agb::Gba) -> ! {
|
||||||
vram.set_background_palettes(tile_sheet::PALETTES);
|
vram.set_background_palettes(tile_sheet::PALETTES);
|
||||||
|
|
||||||
let object = agb.display.object.get();
|
let object = agb.display.object.get();
|
||||||
let mut mixer = agb.mixer.mixer(Frequency::Hz10512);
|
|
||||||
|
|
||||||
mixer.enable();
|
|
||||||
let mut music_box = sfx::MusicBox::new();
|
|
||||||
|
|
||||||
let vblank = agb::interrupt::VBlank::get();
|
let vblank = agb::interrupt::VBlank::get();
|
||||||
let mut current_level = 0;
|
let mut current_level = 0;
|
||||||
|
@ -829,8 +830,7 @@ pub fn main(mut agb: agb::Gba) -> ! {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
music_box.before_frame(&mut mixer);
|
sfx.frame();
|
||||||
mixer.frame();
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
|
|
||||||
level_display::write_level(
|
level_display::write_level(
|
||||||
|
@ -844,8 +844,7 @@ pub fn main(mut agb: agb::Gba) -> ! {
|
||||||
world_display.commit(&mut vram);
|
world_display.commit(&mut vram);
|
||||||
world_display.show();
|
world_display.show();
|
||||||
|
|
||||||
music_box.before_frame(&mut mixer);
|
sfx.frame();
|
||||||
mixer.frame();
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
|
|
||||||
let map_current_level = current_level;
|
let map_current_level = current_level;
|
||||||
|
@ -889,20 +888,17 @@ pub fn main(mut agb: agb::Gba) -> ! {
|
||||||
);
|
);
|
||||||
|
|
||||||
while level.background.init_background(&mut vram) != PartialUpdateStatus::Done {
|
while level.background.init_background(&mut vram) != PartialUpdateStatus::Done {
|
||||||
music_box.before_frame(&mut mixer);
|
sfx.frame();
|
||||||
mixer.frame();
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
}
|
}
|
||||||
|
|
||||||
while level.background.init_foreground(&mut vram) != PartialUpdateStatus::Done {
|
while level.background.init_foreground(&mut vram) != PartialUpdateStatus::Done {
|
||||||
music_box.before_frame(&mut mixer);
|
sfx.frame();
|
||||||
mixer.frame();
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
}
|
}
|
||||||
|
|
||||||
for _ in 0..20 {
|
for _ in 0..20 {
|
||||||
music_box.before_frame(&mut mixer);
|
sfx.frame();
|
||||||
mixer.frame();
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,17 +909,12 @@ pub fn main(mut agb: agb::Gba) -> ! {
|
||||||
world_display.hide();
|
world_display.hide();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match level.update_frame(
|
match level.update_frame(&mut sfx, &mut vram, &object) {
|
||||||
&mut sfx::SfxPlayer::new(&mut mixer, &music_box),
|
|
||||||
&mut vram,
|
|
||||||
&object,
|
|
||||||
) {
|
|
||||||
UpdateState::Normal => {}
|
UpdateState::Normal => {}
|
||||||
UpdateState::Dead => {
|
UpdateState::Dead => {
|
||||||
level.dead_start();
|
level.dead_start();
|
||||||
while level.dead_update(&object) {
|
while level.dead_update(&object) {
|
||||||
music_box.before_frame(&mut mixer);
|
sfx.frame();
|
||||||
mixer.frame();
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
object.commit();
|
object.commit();
|
||||||
}
|
}
|
||||||
|
@ -935,8 +926,7 @@ pub fn main(mut agb: agb::Gba) -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
music_box.before_frame(&mut mixer);
|
sfx.frame();
|
||||||
mixer.frame();
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
object.commit();
|
object.commit();
|
||||||
}
|
}
|
||||||
|
@ -949,8 +939,7 @@ pub fn main(mut agb: agb::Gba) -> ! {
|
||||||
|
|
||||||
splash_screen::show_splash_screen(
|
splash_screen::show_splash_screen(
|
||||||
splash_screen::SplashScreen::End,
|
splash_screen::SplashScreen::End,
|
||||||
Some(&mut mixer),
|
&mut sfx,
|
||||||
Some(&mut music_box),
|
|
||||||
&mut splash_screen,
|
&mut splash_screen,
|
||||||
&mut vram,
|
&mut vram,
|
||||||
);
|
);
|
||||||
|
|
|
@ -37,40 +37,14 @@ mod effects {
|
||||||
pub const SNAIL_DEATH: &[u8] = agb::include_wav!("sfx/snail-death.wav");
|
pub const SNAIL_DEATH: &[u8] = agb::include_wav!("sfx/snail-death.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MusicBox {
|
|
||||||
frame: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MusicBox {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
MusicBox { frame: 0 }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn before_frame(&mut self, mixer: &mut Mixer) {
|
|
||||||
if self.frame == 0 {
|
|
||||||
// play the introduction
|
|
||||||
mixer.play_sound(SoundChannel::new_high_priority(music_data::INTRO_MUSIC));
|
|
||||||
} else if self.frame == music_data::TRIGGER_MUSIC_POINT
|
|
||||||
|| (self.frame - music_data::TRIGGER_MUSIC_POINT) % music_data::LOOP_MUSIC == 0
|
|
||||||
{
|
|
||||||
mixer.play_sound(SoundChannel::new_high_priority(music_data::LOOP));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.frame += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SfxPlayer<'a> {
|
pub struct SfxPlayer<'a> {
|
||||||
mixer: &'a mut Mixer,
|
mixer: &'a mut Mixer<'a>,
|
||||||
frame: i32,
|
frame: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SfxPlayer<'a> {
|
impl<'a> SfxPlayer<'a> {
|
||||||
pub fn new(mixer: &'a mut Mixer, music_box: &MusicBox) -> Self {
|
pub fn new(mixer: &'a mut Mixer<'a>) -> Self {
|
||||||
SfxPlayer {
|
SfxPlayer { mixer, frame: 0 }
|
||||||
mixer,
|
|
||||||
frame: music_box.frame,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn catch(&mut self) {
|
pub fn catch(&mut self) {
|
||||||
|
@ -120,7 +94,24 @@ impl<'a> SfxPlayer<'a> {
|
||||||
|
|
||||||
fn play_random(&mut self, effect: &[&'static [u8]]) {
|
fn play_random(&mut self, effect: &[&'static [u8]]) {
|
||||||
self.mixer.play_sound(SoundChannel::new(
|
self.mixer.play_sound(SoundChannel::new(
|
||||||
effect[(self.frame as usize) % effect.len()],
|
effect[agb::rng::gen() as usize % effect.len()],
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn frame(&mut self) {
|
||||||
|
if self.frame == 0 {
|
||||||
|
// play the introduction
|
||||||
|
self.mixer
|
||||||
|
.play_sound(SoundChannel::new_high_priority(music_data::INTRO_MUSIC));
|
||||||
|
} else if self.frame == music_data::TRIGGER_MUSIC_POINT
|
||||||
|
|| (self.frame - music_data::TRIGGER_MUSIC_POINT) % music_data::LOOP_MUSIC == 0
|
||||||
|
{
|
||||||
|
self.mixer
|
||||||
|
.play_sound(SoundChannel::new_high_priority(music_data::LOOP));
|
||||||
|
}
|
||||||
|
|
||||||
|
self.frame += 1;
|
||||||
|
|
||||||
|
self.mixer.frame();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
use super::sfx::MusicBox;
|
use super::sfx::SfxPlayer;
|
||||||
use agb::{
|
use agb::display::tiled::{RegularMap, TileFormat, TileSet, TileSetting, TiledMap, VRamManager};
|
||||||
display::tiled::{RegularMap, TileFormat, TileSet, TileSetting, TiledMap, VRamManager},
|
|
||||||
sound::mixer::Mixer,
|
|
||||||
};
|
|
||||||
|
|
||||||
agb::include_gfx!("gfx/splash_screens.toml");
|
agb::include_gfx!("gfx/splash_screens.toml");
|
||||||
|
|
||||||
|
@ -13,8 +10,7 @@ pub enum SplashScreen {
|
||||||
|
|
||||||
pub fn show_splash_screen(
|
pub fn show_splash_screen(
|
||||||
which: SplashScreen,
|
which: SplashScreen,
|
||||||
mut mixer: Option<&mut Mixer>,
|
sfx: &mut SfxPlayer,
|
||||||
mut music_box: Option<&mut MusicBox>,
|
|
||||||
map: &mut RegularMap,
|
map: &mut RegularMap,
|
||||||
vram: &mut VRamManager,
|
vram: &mut VRamManager,
|
||||||
) {
|
) {
|
||||||
|
@ -32,13 +28,7 @@ pub fn show_splash_screen(
|
||||||
|
|
||||||
let mut input = agb::input::ButtonController::new();
|
let mut input = agb::input::ButtonController::new();
|
||||||
|
|
||||||
if let Some(ref mut mixer) = mixer {
|
sfx.frame();
|
||||||
if let Some(ref mut music_box) = music_box {
|
|
||||||
music_box.before_frame(mixer);
|
|
||||||
}
|
|
||||||
mixer.frame();
|
|
||||||
}
|
|
||||||
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
|
|
||||||
for y in 0..20u16 {
|
for y in 0..20u16 {
|
||||||
|
@ -51,13 +41,7 @@ pub fn show_splash_screen(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref mut mixer) = mixer {
|
sfx.frame();
|
||||||
if let Some(ref mut music_box) = music_box {
|
|
||||||
music_box.before_frame(mixer);
|
|
||||||
}
|
|
||||||
mixer.frame();
|
|
||||||
}
|
|
||||||
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,12 +59,8 @@ pub fn show_splash_screen(
|
||||||
) {
|
) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if let Some(mixer) = &mut mixer {
|
|
||||||
if let Some(music_box) = &mut music_box {
|
sfx.frame();
|
||||||
music_box.before_frame(mixer);
|
|
||||||
}
|
|
||||||
mixer.frame();
|
|
||||||
}
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -533,7 +533,7 @@ struct Player<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Player<'a> {
|
impl<'a> Player<'a> {
|
||||||
fn new(object_controller: &'a ObjectController) -> Player {
|
fn new(object_controller: &'a ObjectController<'a>) -> Player {
|
||||||
let mut entity = Entity::new(
|
let mut entity = Entity::new(
|
||||||
object_controller,
|
object_controller,
|
||||||
Rect::new((0_u16, 0_u16).into(), (4_u16, 12_u16).into()),
|
Rect::new((0_u16, 0_u16).into(), (4_u16, 12_u16).into()),
|
||||||
|
|
|
@ -27,11 +27,11 @@ const BLUE_SPIRIT: &[u8] = agb::include_wav!("sfx/03 - Blue Spirit (Main Loop).w
|
||||||
|
|
||||||
pub struct Sfx<'a> {
|
pub struct Sfx<'a> {
|
||||||
bgm: Option<ChannelId>,
|
bgm: Option<ChannelId>,
|
||||||
mixer: &'a mut Mixer,
|
mixer: &'a mut Mixer<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Sfx<'a> {
|
impl<'a> Sfx<'a> {
|
||||||
pub fn new(mixer: &'a mut Mixer) -> Self {
|
pub fn new(mixer: &'a mut Mixer<'a>) -> Self {
|
||||||
Self { mixer, bgm: None }
|
Self { mixer, bgm: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue