110 lines
2.2 KiB
Rust
110 lines
2.2 KiB
Rust
use crate::model::tile_bank::TileSize;
|
|
use crate::model::Tile;
|
|
use crate::model::TileSize::Size8;
|
|
|
|
pub struct TileMap {
|
|
pub width: usize,
|
|
pub height: usize,
|
|
pub tiles: Vec<Tile>,
|
|
}
|
|
|
|
impl TileMap {
|
|
fn create(width: usize, height: usize) -> Self {
|
|
Self {
|
|
width,
|
|
height,
|
|
tiles: vec![Tile::default(); width * height],
|
|
}
|
|
}
|
|
|
|
pub fn set_tile(&mut self, x: usize, y: usize, tile: Tile) {
|
|
if x < self.width && y < self.height {
|
|
self.tiles[y * self.width + x] = tile;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
pub struct TileLayer {
|
|
pub bank_id: u8,
|
|
pub tile_size: TileSize,
|
|
pub map: TileMap,
|
|
}
|
|
|
|
impl TileLayer {
|
|
fn create(width: usize, height: usize, tile_size: TileSize) -> Self {
|
|
Self {
|
|
bank_id: 0,
|
|
tile_size,
|
|
map: TileMap::create(width, height),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::ops::Deref for TileLayer {
|
|
type Target = TileMap;
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.map
|
|
}
|
|
}
|
|
|
|
impl std::ops::DerefMut for TileLayer {
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
&mut self.map
|
|
}
|
|
}
|
|
|
|
pub struct ScrollableTileLayer {
|
|
pub layer: TileLayer,
|
|
pub scroll_x: i32,
|
|
pub scroll_y: i32,
|
|
}
|
|
|
|
impl ScrollableTileLayer {
|
|
pub fn new(width: usize, height: usize, tile_size: TileSize) -> Self {
|
|
Self {
|
|
layer: TileLayer::create(width, height, tile_size),
|
|
scroll_x: 0,
|
|
scroll_y: 0,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::ops::Deref for ScrollableTileLayer {
|
|
type Target = TileLayer;
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.layer
|
|
}
|
|
}
|
|
|
|
impl std::ops::DerefMut for ScrollableTileLayer {
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
&mut self.layer
|
|
}
|
|
}
|
|
|
|
pub struct HudTileLayer {
|
|
pub layer: TileLayer,
|
|
}
|
|
|
|
impl HudTileLayer {
|
|
pub fn new(width: usize, height: usize) -> Self {
|
|
Self {
|
|
layer: TileLayer::create(width, height, Size8),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::ops::Deref for HudTileLayer {
|
|
type Target = TileLayer;
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.layer
|
|
}
|
|
}
|
|
|
|
impl std::ops::DerefMut for HudTileLayer {
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
&mut self.layer
|
|
}
|
|
}
|