use crate::{BACKGROUND_MAX_SIZE, EMPTY_TILE}; use glam::IVec2; /// Tilemap which will be rendered on screen pub struct Background { /// Tiles in idx, accessible via \[x\]\[y\], x and y 0..[BACKGROUND_MAX_SIZE] pub tiles: Vec>, /// Camera scroll (negative draw offset) for rendering pub scroll: IVec2, /// Size (used for rendering) pub size: IVec2, /// Are tiles indices half-tile indices? pub half_tile: bool, /// Is this background being displayed? pub active: bool, } impl Default for Background { fn default() -> Self { let row = vec![0u16; BACKGROUND_MAX_SIZE]; let tiles = vec![row; BACKGROUND_MAX_SIZE]; Self { tiles, scroll: IVec2::ZERO, half_tile: false, active: true, size: IVec2 { x: 19, y: 11 }, } } } impl Background { /// Clears all tiles of given bg pub fn clear(&mut self) { self.fill(EMPTY_TILE); } /// Sets all tiles to val pub fn fill(&mut self, val: u16) { for x in 0..BACKGROUND_MAX_SIZE { for y in 0..BACKGROUND_MAX_SIZE { self.tiles[x][y] = val; } } } }