mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 16:21:33 +11:00
use palette in no game to save on not useful aseprite file
This commit is contained in:
parent
f95d68187b
commit
d4314213da
BIN
agb/gfx/pastel.png
Normal file
BIN
agb/gfx/pastel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 355 B |
Binary file not shown.
|
@ -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();
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
sprites.push(sprite.to_vram(palettes[palette].clone()));
|
||||
}
|
||||
|
||||
impl Renderable for ObjectUnmanaged {
|
||||
fn render(&self, slots: &mut OamIterator) -> Option<()> {
|
||||
slots.next()?.set(self);
|
||||
Some(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Renderable> Renderable for &[T] {
|
||||
fn render(&self, slots: &mut OamIterator) -> Option<()> {
|
||||
for r in self.iter() {
|
||||
r.render(slots)?;
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue