use fancy way of getting and setting slots

This commit is contained in:
Corwin 2023-04-25 21:07:31 +01:00
parent 929eef1569
commit 409798c3bf
No known key found for this signature in database

View file

@ -63,7 +63,7 @@ fn draw_number(
oam: &mut OamIterator, oam: &mut OamIterator,
direction: DrawDirection, direction: DrawDirection,
sprite_cache: &SpriteCache, sprite_cache: &SpriteCache,
) { ) -> Option<()> {
let mut digits = Vec::new(); let mut digits = Vec::new();
if number == 0 { if number == 0 {
digits.push(0); digits.push(0);
@ -84,12 +84,12 @@ fn draw_number(
let mut obj = ObjectUnmanaged::new(sprite_cache.numbers[digit as usize].clone()); let mut obj = ObjectUnmanaged::new(sprite_cache.numbers[digit as usize].clone());
obj.show().set_position(current_position); obj.show().set_position(current_position);
if let Some(slot) = oam.next() { oam.next()?.set(&obj);
slot.set(&obj);
}
current_position -= (4, 0).into(); current_position -= (4, 0).into();
} }
Some(())
} }
impl SpriteCache { 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() { for saw in self.saws.iter() {
if let Some(slot) = oam.next() { oam.next()?.set(&saw.object);
slot.set(&saw.object);
}
} }
for circle in self.circles.iter() { for circle in self.circles.iter() {
if let Some(slot) = oam.next() { let mut object = ObjectUnmanaged::new(match circle.colour {
let mut object = ObjectUnmanaged::new(match circle.colour { Colour::Red => sprite_cache.red.clone(),
Colour::Red => sprite_cache.red.clone(), Colour::Blue => sprite_cache.blue.clone(),
Colour::Blue => sprite_cache.blue.clone(), });
});
object object
.show() .show()
.set_position(circle.position.floor() - (4, 4).into()); .set_position(circle.position.floor() - (4, 4).into());
slot.set(&object); oam.next()?.set(&object);
}
} }
Some(())
} }
} }