mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-09 08:31:33 +11:00
use fancy way of getting and setting slots
This commit is contained in:
parent
929eef1569
commit
409798c3bf
|
@ -63,7 +63,7 @@ fn draw_number(
|
|||
oam: &mut OamIterator,
|
||||
direction: DrawDirection,
|
||||
sprite_cache: &SpriteCache,
|
||||
) {
|
||||
) -> Option<()> {
|
||||
let mut digits = Vec::new();
|
||||
if number == 0 {
|
||||
digits.push(0);
|
||||
|
@ -84,12 +84,12 @@ fn draw_number(
|
|||
let mut obj = ObjectUnmanaged::new(sprite_cache.numbers[digit as usize].clone());
|
||||
obj.show().set_position(current_position);
|
||||
|
||||
if let Some(slot) = oam.next() {
|
||||
slot.set(&obj);
|
||||
}
|
||||
oam.next()?.set(&obj);
|
||||
|
||||
current_position -= (4, 0).into();
|
||||
}
|
||||
|
||||
Some(())
|
||||
}
|
||||
|
||||
impl SpriteCache {
|
||||
|
@ -259,27 +259,25 @@ impl Game {
|
|||
}
|
||||
}
|
||||
|
||||
fn render(&self, oam: &mut OamIterator, sprite_cache: &SpriteCache) {
|
||||
fn render(&self, oam: &mut OamIterator, sprite_cache: &SpriteCache) -> Option<()> {
|
||||
for saw in self.saws.iter() {
|
||||
if let Some(slot) = oam.next() {
|
||||
slot.set(&saw.object);
|
||||
}
|
||||
oam.next()?.set(&saw.object);
|
||||
}
|
||||
|
||||
for circle in self.circles.iter() {
|
||||
if let Some(slot) = oam.next() {
|
||||
let mut object = ObjectUnmanaged::new(match circle.colour {
|
||||
Colour::Red => sprite_cache.red.clone(),
|
||||
Colour::Blue => sprite_cache.blue.clone(),
|
||||
});
|
||||
let mut object = ObjectUnmanaged::new(match circle.colour {
|
||||
Colour::Red => sprite_cache.red.clone(),
|
||||
Colour::Blue => sprite_cache.blue.clone(),
|
||||
});
|
||||
|
||||
object
|
||||
.show()
|
||||
.set_position(circle.position.floor() - (4, 4).into());
|
||||
object
|
||||
.show()
|
||||
.set_position(circle.position.floor() - (4, 4).into());
|
||||
|
||||
slot.set(&object);
|
||||
}
|
||||
oam.next()?.set(&object);
|
||||
}
|
||||
|
||||
Some(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue