diff --git a/CHANGLOG.md b/CHANGLOG.md new file mode 100644 index 0000000..1ad587c --- /dev/null +++ b/CHANGLOG.md @@ -0,0 +1,6 @@ +# 0.2.0 - +- added README.md +- renamed tilemaps to backgrounds to make space for... tilemaps + +# 0.1.0 - 2023-07-21 +initial release \ No newline at end of file diff --git a/examples/gfx.gif b/examples/gfx.gif index b4b5f42..6c29528 100644 Binary files a/examples/gfx.gif and b/examples/gfx.gif differ diff --git a/src/gsa_render_to_screen.rs b/src/gsa_render_to_screen.rs index e0b0154..1509cf3 100644 --- a/src/gsa_render_to_screen.rs +++ b/src/gsa_render_to_screen.rs @@ -1,6 +1,6 @@ use crate::{ - Background, Gsa, Rgb, BACKGROUND_MAX_SIZE, HALF_TILE_SIZE, MAX_BACKGROUNDS, SCREEN_HEIGHT, - SCREEN_WIDTH, TILESET_SIZE, TILE_SIZE, + Background, Gsa, Rgb, BACKGROUND_MAX_SIZE, EMPTY_TILE, HALF_TILE_SIZE, MAX_BACKGROUNDS, + SCREEN_HEIGHT, SCREEN_WIDTH, TILESET_SIZE, TILE_SIZE, TRANSPARENT, }; use glam::IVec2; use softbuffer::Buffer; @@ -16,7 +16,7 @@ fn draw_tile(target: &mut [u8], pos: IVec2, tile: u16, tileset: &[u8], half: boo for y in (starty - pos.y)..(endy - pos.y) { for x in (startx - pos.x)..(endx - pos.x) { let p = tileset[(x as usize + tx) + (y as usize + ty) * (TILESET_SIZE * TILE_SIZE)]; - if p > 0 { + if p != TRANSPARENT { target[(x as usize + pos.x as usize) + (y as usize + pos.y as usize) * SCREEN_WIDTH] = p; } @@ -40,7 +40,7 @@ fn render_map(target: &mut [u8], map: &Background, tileset: &[u8]) { for x in startx..endx { for y in starty..endy { let tile = map.tiles[x as usize][y as usize]; - if tile > 0 { + if tile > EMPTY_TILE { draw_tile( target, IVec2 { diff --git a/src/lib.rs b/src/lib.rs index a11d689..340d8fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ //! - Colors: 256 (indexed out of a possible 24-bit) //! - Tilesize: 16x16 (or 8x8 for half-tiles) //! - Tileset: 65536 tiles, indexed via 0xYYXX +//! - rectangle(not id range) of 0x7000 to 0x7F7F semi-reserved //! - Sprites: 256 of size 16x16 (pondering allowing larger sprites) //! - Backgrounds: 4 of size 1024x1024, scrollable //! @@ -55,12 +56,24 @@ pub const SCREEN_HEIGHT: usize = 176; /// X and y dimensions of maps in [Gsa::bgs] pub const BACKGROUND_MAX_SIZE: usize = 1024; +/// Tile considered empty (never drawn even if has contents) +pub const EMPTY_TILE: u16 = 0xffff + +/// Tile id of bold default font +pub const FONT_BOLD: u16 = 0xf000; + +/// Tile id of thin default font +pub const FONT_THIN: u16 = 0xe000; + /// Width and height (in tiles) of tileset pub const TILESET_SIZE: usize = 0x100; /// Width and height of a tile pub const TILE_SIZE: usize = 16; +/// Palette index which is treated as transparent +pub const TRANSPARENT: u8 = 0xff; + /// Width and height of a tile in half-tile mode pub const HALF_TILE_SIZE: usize = 8; diff --git a/src/run.rs b/src/run.rs index 67156c5..0defd77 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,7 +1,7 @@ use crate::buttons::{button_from_gilrs, button_from_scancode}; use crate::gsa_render_to_screen::{render_to_screen, render_to_window}; use crate::tileset::load_tileset; -use crate::{Buttons, Gsa, Sprite, MAX_SPRITES, SCREEN_HEIGHT, SCREEN_WIDTH}; +use crate::{Buttons, Gsa, Sprite, FONT_BOLD, MAX_SPRITES, SCREEN_HEIGHT, SCREEN_WIDTH}; use gilrs::EventType; use glam::IVec2; use std::cmp::min; @@ -41,7 +41,7 @@ pub fn run( sprites: [Sprite::default(); MAX_SPRITES], bgs: Default::default(), palette, - font: 0x1010, + font: FONT_BOLD, pressed: 0, released: 0, down: 0,