added touch
This commit is contained in:
parent
858552f55f
commit
fea5e09f82
@ -50,13 +50,13 @@ impl Machine {
|
||||
/// Lógica do frame (demo hardcoded por enquanto).
|
||||
pub fn tick(&mut self) {
|
||||
// Limpa a tela com Preto
|
||||
self.gfx.clear(Color::BLACK);
|
||||
self.gfx.clear(Color::GRAY);
|
||||
|
||||
// SETUP BANCO 0 (Tiles 8x8)
|
||||
if self.gfx.banks[0].is_none() {
|
||||
let mut bank = crate::model::TileBank::new(crate::model::TileSize::Size8, 128, 128);
|
||||
// Define Cor na Paleta 0, Índice 1 = VERDE
|
||||
bank.palettes[0][1] = Color::GREEN.raw();
|
||||
bank.palettes[0][1] = Color::GREEN;
|
||||
|
||||
let tile_size = 8;
|
||||
let start_x = 8; // Tile ID 1
|
||||
@ -73,7 +73,7 @@ impl Machine {
|
||||
if self.gfx.banks[1].is_none() {
|
||||
let mut bank = crate::model::TileBank::new(crate::model::TileSize::Size16, 128, 128);
|
||||
// Define Cor na Paleta 0, Índice 1 = VERMELHO
|
||||
bank.palettes[0][1] = Color::RED.raw();
|
||||
bank.palettes[0][1] = Color::RED;
|
||||
|
||||
let tile_size = 16;
|
||||
let start_x = 16; // Tile ID 1
|
||||
@ -90,9 +90,13 @@ impl Machine {
|
||||
if self.gfx.banks[2].is_none() {
|
||||
let mut bank = crate::model::TileBank::new(crate::model::TileSize::Size16, 128, 128);
|
||||
// Define Cor na Paleta 0, Índice 1 = INDIGO (Roxo)
|
||||
bank.palettes[0][1] = Color::rgb(0x4B, 0x00, 0x82).raw();
|
||||
bank.palettes[0][1] = Color::INDIGO;
|
||||
// Define Cor na Paleta 1, Índice 1 = AMARELO (para Palette Swap)
|
||||
bank.palettes[1][1] = Color::YELLOW.raw();
|
||||
bank.palettes[1][1] = Color::YELLOW;
|
||||
// Define Cor na Paleta 1, Índice 1 = AMARELO (para Palette Swap)
|
||||
bank.palettes[2][1] = Color::RED;
|
||||
// Define Cor na Paleta 1, Índice 1 = AMARELO (para Palette Swap)
|
||||
bank.palettes[3][1] = Color::GREEN;
|
||||
|
||||
let tile_size = 16;
|
||||
let start_x = 16;
|
||||
@ -136,19 +140,10 @@ impl Machine {
|
||||
s.flip_y = i % 3 == 0;
|
||||
}
|
||||
|
||||
// Post-FX Fade Pulsante
|
||||
let pulse = (self.frame_index / 4) % 64;
|
||||
let level = if pulse > 31 { 63 - pulse } else { pulse };
|
||||
self.gfx.scene_fade_level = level as u8;
|
||||
self.gfx.scene_fade_color = Color::BLACK;
|
||||
self.gfx.hud_fade_level = 31;
|
||||
|
||||
|
||||
|
||||
// --- INTERATIVIDADE COM TOUCH ---
|
||||
let cursor = &mut self.gfx.sprites[511];
|
||||
cursor.active = true;
|
||||
cursor.bank_id = 0; // Banco Verde
|
||||
cursor.bank_id = 2; // Banco Verde
|
||||
cursor.tile.id = 1;
|
||||
cursor.priority = 4;
|
||||
|
||||
@ -156,15 +151,22 @@ impl Machine {
|
||||
if self.touch.f.down {
|
||||
cursor.x = self.touch.x - 4; // Centraliza tile 8x8
|
||||
cursor.y = self.touch.y - 4;
|
||||
cursor.tile.palette_id = 0; // Verde
|
||||
cursor.tile.palette_id = 2; // RED
|
||||
} else {
|
||||
cursor.tile.palette_id = 1; // Vermelho (se configurado)
|
||||
cursor.tile.palette_id = 3; // GREEN
|
||||
}
|
||||
|
||||
// Teste de Pressed: se clicou JUSTO AGORA, reseta o frame_index
|
||||
if self.touch.f.pressed {
|
||||
self.frame_index = 0;
|
||||
}
|
||||
// // Teste de Pressed: se clicou JUSTO AGORA, reseta o frame_index
|
||||
// if self.touch.f.pressed {
|
||||
// self.frame_index = 0;
|
||||
// }
|
||||
|
||||
// // Post-FX Fade Pulsante
|
||||
// let pulse = (self.frame_index / 4) % 64;
|
||||
// let level = if pulse > 31 { 63 - pulse } else { pulse };
|
||||
// self.gfx.scene_fade_level = level as u8;
|
||||
// self.gfx.scene_fade_color = Color::BLACK;
|
||||
// self.gfx.hud_fade_level = 31;
|
||||
}
|
||||
|
||||
/// Final do frame: troca buffers.
|
||||
|
||||
@ -10,6 +10,7 @@ pub struct Color(pub u16);
|
||||
|
||||
impl Color {
|
||||
pub const INDIGO: Self = Self::rgb(32, 32, 64);
|
||||
pub const GRAY: Self = Self::rgb(64, 64, 64);
|
||||
pub const BLACK: Self = Self::rgb(0, 0, 0); // 0x0000
|
||||
pub const WHITE: Self = Self::rgb(255, 255, 255); // 0xFFFF
|
||||
pub const RED: Self = Self::rgb(255, 0, 0); // 0xF800
|
||||
|
||||
@ -16,7 +16,7 @@ pub struct TileBank {
|
||||
/// Agora guardamos índices de 0 a 15 (4 bits por pixel simulados em 8 bits)
|
||||
pub pixel_indices: Vec<u8>,
|
||||
/// 256 paletas, cada uma com 16 cores (RGB565 como u16)
|
||||
pub palettes: [[u16; 16]; 256],
|
||||
pub palettes: [[Color; 16]; 256],
|
||||
}
|
||||
|
||||
impl TileBank {
|
||||
@ -26,7 +26,7 @@ impl TileBank {
|
||||
width,
|
||||
height,
|
||||
pixel_indices: vec![0; width * height], // Índice 0 = Transparente
|
||||
palettes: [[0; 16]; 256],
|
||||
palettes: [[Color::BLACK; 16]; 256],
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +56,6 @@ impl TileBank {
|
||||
return Color::COLOR_KEY;
|
||||
}
|
||||
|
||||
let raw_color = self.palettes[palette_id as usize][pixel_index as usize];
|
||||
Color::from_raw(raw_color)
|
||||
self.palettes[palette_id as usize][pixel_index as usize]
|
||||
}
|
||||
}
|
||||
@ -344,32 +344,28 @@ impl Gfx {
|
||||
// 2. Tile Layers (4 Game Layers)
|
||||
for layer in &self.layers {
|
||||
// Tamanho da struct + os dados do mapa (Vec<Tile>)
|
||||
total += std::mem::size_of::<ScrollableTileLayer>();
|
||||
total += layer.map.tiles.len() * std::mem::size_of::<crate::model::Tile>();
|
||||
total += size_of::<ScrollableTileLayer>();
|
||||
total += layer.map.tiles.len() * size_of::<crate::model::Tile>();
|
||||
}
|
||||
|
||||
// 3. HUD Layer
|
||||
total += std::mem::size_of::<HudTileLayer>();
|
||||
total += self.hud.map.tiles.len() * std::mem::size_of::<crate::model::Tile>();
|
||||
total += size_of::<HudTileLayer>();
|
||||
total += self.hud.map.tiles.len() * size_of::<crate::model::Tile>();
|
||||
|
||||
// 4. Tile Banks (Assets e Paletas)
|
||||
for bank_opt in &self.banks {
|
||||
if let Some(bank) = bank_opt {
|
||||
total += std::mem::size_of::<TileBank>();
|
||||
|
||||
// Buffer de Índices (pixel_indices: Vec<u8>)
|
||||
// Cada pixel ocupa exatamente 1 byte.
|
||||
total += size_of::<TileBank>();
|
||||
total += bank.pixel_indices.len();
|
||||
|
||||
// Tabela de Paletas (palettes: [[u16; 16]; 256])
|
||||
// 256 paletas * 16 cores * 2 bytes cada.
|
||||
total += 256 * 16 * 2;
|
||||
// Tabela de Paletas: 256 paletas * 16 cores * tamanho da struct Color
|
||||
total += 256 * 16 * size_of::<Color>();
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Sprites (OAM)
|
||||
// Array fixo de 512 Sprites.
|
||||
total += self.sprites.len() * std::mem::size_of::<crate::model::Sprite>();
|
||||
total += self.sprites.len() * size_of::<Sprite>();
|
||||
|
||||
total
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user