added size to backgrounds

This commit is contained in:
dani 2023-08-06 16:50:36 +00:00
parent eebeb478d2
commit 42f8174a51
2 changed files with 11 additions and 4 deletions

View File

@ -7,6 +7,8 @@ pub struct Background {
pub tiles: Vec<Vec<u16>>, pub tiles: Vec<Vec<u16>>,
/// Camera scroll (negative draw offset) for rendering /// Camera scroll (negative draw offset) for rendering
pub scroll: IVec2, pub scroll: IVec2,
/// Size (used for rendering)
pub size: IVec2,
/// Are tiles indices half-tile indices? /// Are tiles indices half-tile indices?
pub half_tile: bool, pub half_tile: bool,
/// Is this background being displayed? /// Is this background being displayed?
@ -22,6 +24,7 @@ impl Default for Background {
scroll: IVec2::ZERO, scroll: IVec2::ZERO,
half_tile: false, half_tile: false,
active: true, active: true,
size: IVec2 { x: 19, y: 11 },
} }
} }
} }

View File

@ -41,10 +41,14 @@ fn render_map(target: &mut [u8], map: &Background, tileset: &[u8], screen_size:
} as i32; } as i32;
let mut startx = map.scroll.x / tilesize; let mut startx = map.scroll.x / tilesize;
let mut starty = map.scroll.y / tilesize; let mut starty = map.scroll.y / tilesize;
let endx = let endx = map
(BACKGROUND_MAX_SIZE as i32).min(startx + (screen_size.x / TILE_SIZE as i32 + 1) * tcmult); .size
let endy = .x
(BACKGROUND_MAX_SIZE as i32).min(starty + (screen_size.y / TILE_SIZE as i32 + 1) * tcmult); .min(startx + (screen_size.x / TILE_SIZE as i32 + 1) * tcmult);
let endy = map
.size
.y
.min(starty + (screen_size.y / TILE_SIZE as i32 + 1) * tcmult);
startx = 0.max(startx); startx = 0.max(startx);
starty = 0.max(starty); starty = 0.max(starty);
for x in startx..endx { for x in startx..endx {