use palette in no game to save on not useful aseprite file

This commit is contained in:
Corwin 2023-05-06 22:45:26 +01:00
parent f95d68187b
commit d4314213da
No known key found for this signature in database
3 changed files with 35 additions and 30 deletions

BIN
agb/gfx/pastel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

View file

@ -1,19 +1,18 @@
//! The no game screen is what is displayed if there isn't a game made yet.
use agb_fixnum::{num, Num, Vector2D};
use alloc::vec;
use alloc::vec::Vec;
use alloc::{boxed::Box, vec};
use crate::display::object::{DynamicSprite, PaletteVram, Size, SpriteVram};
use crate::display::palette16::Palette16;
use crate::{
display::{
object::{OamIterator, ObjectUnmanaged, Sprite},
HEIGHT, WIDTH,
},
include_aseprite,
display::{object::ObjectUnmanaged, HEIGHT, WIDTH},
include_palette,
interrupt::VBlank,
};
const SQUARES: &[Sprite] = include_aseprite!("gfx/square.aseprite").sprites();
const PALETTE: &[u16] = &include_palette!("gfx/pastel.png");
fn letters() -> Vec<Vec<Vector2D<Num<i32, 8>>>> {
vec![
@ -111,34 +110,44 @@ fn letters() -> Vec<Vec<Vector2D<Num<i32, 8>>>> {
]
}
trait Renderable {
fn render(&self, slots: &mut OamIterator) -> Option<()>;
}
fn generate_sprites() -> Box<[SpriteVram]> {
let mut sprites = Vec::new();
impl Renderable for ObjectUnmanaged {
fn render(&self, slots: &mut OamIterator) -> Option<()> {
slots.next()?.set(self);
Some(())
// generate palettes
let palettes: Vec<PaletteVram> = PALETTE
.chunks(15)
.map(|x| {
core::iter::once(0)
.chain(x.iter().copied())
.chain(core::iter::repeat(0))
.take(16)
.collect::<Vec<_>>()
})
.map(|palette| {
let palette = Palette16::new(palette.try_into().unwrap());
PaletteVram::new(&palette).unwrap()
})
.collect();
// generate sprites
let mut sprite = DynamicSprite::new(Size::S8x8);
for (palette, colour) in (0..PALETTE.len()).map(|x| (x / 15, x % 15)) {
for y in 0..8 {
for x in 0..8 {
sprite.set_pixel(x, y, colour + 1);
}
}
impl<T: Renderable> Renderable for &[T] {
fn render(&self, slots: &mut OamIterator) -> Option<()> {
for r in self.iter() {
r.render(slots)?;
}
sprites.push(sprite.to_vram(palettes[palette].clone()));
}
Some(())
}
sprites.into_boxed_slice()
}
pub fn no_game(mut gba: crate::Gba) -> ! {
let (mut oam, mut loader) = gba.display.object.get_unmanaged();
let squares: Vec<_> = SQUARES
.iter()
.map(|sprite| loader.get_vram_sprite(sprite))
.collect();
let squares = generate_sprites();
let mut letter_positons = Vec::new();
@ -179,10 +188,6 @@ pub fn no_game(mut gba: crate::Gba) -> ! {
let mut time: Num<i32, 8> = num!(0.);
let time_delta: Num<i32, 8> = num!(0.025);
// let (_background, mut vram) = gba.display.video.tiled0();
// vram.set_background_palettes(&[Palette16::new([u16::MAX; 16])]);
let vblank = VBlank::get();
loop {