added changelog, changed tilemap to background, working on template gfx.gif

This commit is contained in:
dani 2023-07-25 04:36:02 +00:00
parent 8372690bc0
commit 3c447c764f
5 changed files with 25 additions and 6 deletions

6
CHANGLOG.md Normal file
View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
Background, Gsa, Rgb, BACKGROUND_MAX_SIZE, HALF_TILE_SIZE, MAX_BACKGROUNDS, SCREEN_HEIGHT, Background, Gsa, Rgb, BACKGROUND_MAX_SIZE, EMPTY_TILE, HALF_TILE_SIZE, MAX_BACKGROUNDS,
SCREEN_WIDTH, TILESET_SIZE, TILE_SIZE, SCREEN_HEIGHT, SCREEN_WIDTH, TILESET_SIZE, TILE_SIZE, TRANSPARENT,
}; };
use glam::IVec2; use glam::IVec2;
use softbuffer::Buffer; 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 y in (starty - pos.y)..(endy - pos.y) {
for x in (startx - pos.x)..(endx - pos.x) { for x in (startx - pos.x)..(endx - pos.x) {
let p = tileset[(x as usize + tx) + (y as usize + ty) * (TILESET_SIZE * TILE_SIZE)]; 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) target[(x as usize + pos.x as usize)
+ (y as usize + pos.y as usize) * SCREEN_WIDTH] = p; + (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 x in startx..endx {
for y in starty..endy { for y in starty..endy {
let tile = map.tiles[x as usize][y as usize]; let tile = map.tiles[x as usize][y as usize];
if tile > 0 { if tile > EMPTY_TILE {
draw_tile( draw_tile(
target, target,
IVec2 { IVec2 {

View File

@ -8,6 +8,7 @@
//! - Colors: 256 (indexed out of a possible 24-bit) //! - Colors: 256 (indexed out of a possible 24-bit)
//! - Tilesize: 16x16 (or 8x8 for half-tiles) //! - Tilesize: 16x16 (or 8x8 for half-tiles)
//! - Tileset: 65536 tiles, indexed via 0xYYXX //! - 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) //! - Sprites: 256 of size 16x16 (pondering allowing larger sprites)
//! - Backgrounds: 4 of size 1024x1024, scrollable //! - 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] /// X and y dimensions of maps in [Gsa::bgs]
pub const BACKGROUND_MAX_SIZE: usize = 1024; 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 /// Width and height (in tiles) of tileset
pub const TILESET_SIZE: usize = 0x100; pub const TILESET_SIZE: usize = 0x100;
/// Width and height of a tile /// Width and height of a tile
pub const TILE_SIZE: usize = 16; 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 /// Width and height of a tile in half-tile mode
pub const HALF_TILE_SIZE: usize = 8; pub const HALF_TILE_SIZE: usize = 8;

View File

@ -1,7 +1,7 @@
use crate::buttons::{button_from_gilrs, button_from_scancode}; use crate::buttons::{button_from_gilrs, button_from_scancode};
use crate::gsa_render_to_screen::{render_to_screen, render_to_window}; use crate::gsa_render_to_screen::{render_to_screen, render_to_window};
use crate::tileset::load_tileset; 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 gilrs::EventType;
use glam::IVec2; use glam::IVec2;
use std::cmp::min; use std::cmp::min;
@ -41,7 +41,7 @@ pub fn run<TGame: 'static>(
sprites: [Sprite::default(); MAX_SPRITES], sprites: [Sprite::default(); MAX_SPRITES],
bgs: Default::default(), bgs: Default::default(),
palette, palette,
font: 0x1010, font: FONT_BOLD,
pressed: 0, pressed: 0,
released: 0, released: 0,
down: 0, down: 0,