update games

This commit is contained in:
Corwin 2022-04-03 21:20:20 +01:00
parent 2ef1dd0bf2
commit 3e3039a7f6
4 changed files with 26 additions and 34 deletions

View file

@ -88,7 +88,8 @@ fn main(mut gba: agb::Gba) -> ! {
.object .object
.set_y((chicken.position.y >> 8).try_into().unwrap()); .set_y((chicken.position.y >> 8).try_into().unwrap());
chicken.object.show(); chicken.object.show();
chicken.object.commit();
object.commit();
let acceleration = 1 << 4; let acceleration = 1 << 4;
let gravity = 1 << 4; let gravity = 1 << 4;
@ -133,8 +134,7 @@ fn main(mut gba: agb::Gba) -> ! {
restrict_to_screen(&mut chicken); restrict_to_screen(&mut chicken);
update_chicken_object(&mut chicken, &object, state, frame_count); update_chicken_object(&mut chicken, &object, state, frame_count);
// Commit the chicken to vram object.commit();
chicken.object.commit();
} }
} }

View file

@ -6,7 +6,6 @@ extern crate alloc;
use agb::display::object::{Graphics, ObjectController, Sprite, TagMap}; use agb::display::object::{Graphics, ObjectController, Sprite, TagMap};
use alloc::vec::Vec; use alloc::vec::Vec;
const GRAPHICS: &Graphics = agb::include_aseprite!( const GRAPHICS: &Graphics = agb::include_aseprite!(
"../examples/the-purple-night/gfx/objects.aseprite", "../examples/the-purple-night/gfx/objects.aseprite",
"../examples/the-purple-night/gfx/boss.aseprite" "../examples/the-purple-night/gfx/boss.aseprite"
@ -49,7 +48,7 @@ fn all_sprites(gfx: &ObjectController) {
for (i, obj) in objs.iter_mut().enumerate() { for (i, obj) in objs.iter_mut().enumerate() {
let this_image = (image + i * SPRITES.len() / objs_len) % SPRITES.len(); let this_image = (image + i * SPRITES.len() / objs_len) % SPRITES.len();
obj.set_sprite(gfx.sprite(&SPRITES[this_image])); obj.set_sprite(gfx.sprite(&SPRITES[this_image]));
obj.commit(); gfx.commit();
} }
} }
} }
@ -91,8 +90,8 @@ fn all_tags(gfx: &ObjectController) {
image += 1; image += 1;
for (obj, tag) in objs.iter_mut() { for (obj, tag) in objs.iter_mut() {
obj.set_sprite(gfx.sprite(tag.animation_sprite(image))); obj.set_sprite(gfx.sprite(tag.animation_sprite(image)));
obj.commit();
} }
gfx.commit();
} }
} }
} }
@ -101,10 +100,6 @@ fn all_tags(gfx: &ObjectController) {
fn main(mut gba: agb::Gba) -> ! { fn main(mut gba: agb::Gba) -> ! {
let gfx = gba.display.object.get(); let gfx = gba.display.object.get();
let mut timers = gba.timers.timers();
let _a = agb::interrupt::profiler(&mut timers.timer0, 5000);
loop { loop {
all_tags(&gfx); all_tags(&gfx);
all_sprites(&gfx); all_sprites(&gfx);

View file

@ -258,7 +258,6 @@ impl<'a> Entity<'a> {
} else { } else {
self.sprite.show(); self.sprite.show();
} }
self.sprite.commit();
} }
} }
@ -356,8 +355,7 @@ impl<'a> Player<'a> {
wizard.sprite.show(); wizard.sprite.show();
hat.sprite.show(); hat.sprite.show();
wizard.sprite.commit(); hat.sprite.set_z(-1);
hat.sprite.commit();
wizard.position = start_position; wizard.position = start_position;
hat.position = start_position - (0, 10).into(); hat.position = start_position - (0, 10).into();
@ -498,22 +496,6 @@ impl<'a> Player<'a> {
_ => HAT_SPIN_3, _ => HAT_SPIN_3,
}; };
match self.facing {
agb::input::Tri::Negative => {
self.wizard.sprite.set_hflip(true);
self.hat
.sprite
.set_sprite(controller.sprite(hat_base_tile.sprite(5)));
}
agb::input::Tri::Positive => {
self.wizard.sprite.set_hflip(false);
self.hat
.sprite
.set_sprite(controller.sprite(hat_base_tile.sprite(0)));
}
_ => {}
}
let hat_resting_position = match self.wizard_frame { let hat_resting_position = match self.wizard_frame {
1 | 2 => (0, 9).into(), 1 | 2 => (0, 9).into(),
5 => (0, 10).into(), 5 => (0, 10).into(),
@ -571,6 +553,21 @@ impl<'a> Player<'a> {
self.hat_slow_counter = 0; self.hat_slow_counter = 0;
self.hat_left_range = false; self.hat_left_range = false;
self.hat.position = self.wizard.position - hat_resting_position; self.hat.position = self.wizard.position - hat_resting_position;
match self.facing {
agb::input::Tri::Negative => {
self.wizard.sprite.set_hflip(true);
self.hat
.sprite
.set_sprite(controller.sprite(hat_base_tile.sprite(5)));
}
agb::input::Tri::Positive => {
self.wizard.sprite.set_hflip(false);
self.hat
.sprite
.set_sprite(controller.sprite(hat_base_tile.sprite(0)));
}
_ => {}
}
} }
HatState::WizardTowards => { HatState::WizardTowards => {
self.hat.sprite.set_sprite( self.hat.sprite.set_sprite(
@ -907,6 +904,8 @@ fn main(mut agb: agb::Gba) -> ! {
mixer.after_vblank(); mixer.after_vblank();
} }
object.commit();
level.show_backgrounds(); level.show_backgrounds();
world_display.hide(); world_display.hide();
@ -925,6 +924,7 @@ fn main(mut agb: agb::Gba) -> ! {
mixer.frame(); mixer.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
mixer.after_vblank(); mixer.after_vblank();
object.commit();
} }
break; break;
} }
@ -938,6 +938,7 @@ fn main(mut agb: agb::Gba) -> ! {
mixer.frame(); mixer.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
mixer.after_vblank(); mixer.after_vblank();
object.commit();
} }
level.hide_backgrounds(); level.hide_backgrounds();

View file

@ -285,7 +285,6 @@ impl<'a> Entity<'a> {
self.sprite.show(); self.sprite.show();
} }
} }
self.sprite.commit();
} }
fn commit_with_size(&mut self, offset: Vector2D<Number>, size: Vector2D<i32>) { fn commit_with_size(&mut self, offset: Vector2D<Number>, size: Vector2D<i32>) {
@ -304,7 +303,6 @@ impl<'a> Entity<'a> {
self.sprite.show(); self.sprite.show();
} }
} }
self.sprite.commit();
} }
} }
@ -540,7 +538,6 @@ impl<'a> Player<'a> {
entity.sprite.set_sprite(s); entity.sprite.set_sprite(s);
entity.sprite.show(); entity.sprite.show();
entity.position = (144, 0).into(); entity.position = (144, 0).into();
entity.sprite.commit();
Player { Player {
entity, entity,
@ -1405,8 +1402,6 @@ impl<'a> Enemy<'a> {
entity.sprite.set_sprite(sprite); entity.sprite.set_sprite(sprite);
entity.sprite.show(); entity.sprite.show();
entity.sprite.commit();
Self { entity, enemy_data } Self { entity, enemy_data }
} }
@ -2285,6 +2280,7 @@ fn game_with_level(gba: &mut agb::Gba) {
sfx.frame(); sfx.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
sfx.after_vblank(); sfx.after_vblank();
object.commit();
match game.advance_frame(&object, &mut vram, &mut sfx) { match game.advance_frame(&object, &mut vram, &mut sfx) {
GameStatus::Continue => {} GameStatus::Continue => {}
GameStatus::Lost => { GameStatus::Lost => {