preparing for 0.2.0 release

This commit is contained in:
dani 2023-07-27 05:13:11 +00:00
parent 9b1dd5e085
commit 4d1ab31451
7 changed files with 57 additions and 28 deletions

View File

@ -1,6 +1,7 @@
# 0.2.0 - # 0.2.0 -
- added README.md - added README.md
- renamed tilemaps to backgrounds to make space for... tilemaps - renamed tilemaps to backgrounds to make space for... tilemaps
- tile idx 0xffff and palette idx 0xff are now transparent rather than 0x0000
# 0.1.0 - 2023-07-21 # 0.1.0 - 2023-07-21
initial release initial release

View File

@ -1,7 +1,7 @@
[package] [package]
name = "gsa" name = "gsa"
version = "0.1.0" version = "0.2.0"
edition = "2021" edition = "2021"
description = "Game development library modelled after an imaginary console" description = "Game development library modelled after an imaginary console"
license = "0BSD" license = "0BSD"

View File

@ -2,8 +2,8 @@ use crate::background::Background;
use crate::rgb::Rgb; use crate::rgb::Rgb;
use crate::sprite::Sprite; use crate::sprite::Sprite;
use crate::{ use crate::{
Buttons, BACKGROUND_MAX_SIZE, DPAD_DOWN, DPAD_LEFT, DPAD_RIGHT, DPAD_UP, MAX_BACKGROUNDS, Buttons, BACKGROUND_MAX_SIZE, DPAD_DOWN, DPAD_LEFT, DPAD_RIGHT, DPAD_UP, EMPTY_TILE,
MAX_SPRITES, MAX_BACKGROUNDS, MAX_SPRITES,
}; };
use ascii::{AsciiChar, AsciiStr}; use ascii::{AsciiChar, AsciiStr};
use glam::IVec2; use glam::IVec2;
@ -16,7 +16,7 @@ pub struct Gsa {
/// Palette used to draw graphics, initially loaded from gfx.gif /// Palette used to draw graphics, initially loaded from gfx.gif
pub palette: [Rgb; 256], pub palette: [Rgb; 256],
/// Tilemap layers available /// Tilemap layers available, layer 0 in the back, layer 3 in front; layer 3 defaults to half-tile mode
pub bgs: [Background; MAX_BACKGROUNDS], pub bgs: [Background; MAX_BACKGROUNDS],
/// Currently selected font /// Currently selected font
@ -30,16 +30,36 @@ pub struct Gsa {
} }
impl Gsa { impl Gsa {
/// Clears all tiles of given map to 0 /// Clears all tiles of given bg
pub fn clear_map(&mut self, map: usize) { pub fn clear_bg(&mut self, bg: usize) {
self.fill_map(map, 0); self.fill_bg(bg, EMPTY_TILE);
} }
/// Sets all tiles of map to val /// Resets all bg
pub fn fill_map(&mut self, map: usize, val: u16) { pub fn reset_bgs(&mut self) {
for bg in 0..MAX_BACKGROUNDS {
self.clear_bg(bg);
self.bgs[bg].scroll = IVec2::ZERO;
self.bgs[bg].half_tile = false;
}
//todo: document ui layer defaulting to half tile
self.bgs[3].half_tile = true;
}
/// Clears all sprites
pub fn reset_sprites(&mut self) {
for sprite in 0..MAX_SPRITES {
self.sprites[sprite].pos = IVec2::ZERO;
self.sprites[sprite].tile = EMPTY_TILE;
self.sprites[sprite].priority = 0;
}
}
/// Sets all tiles of bg to val
pub fn fill_bg(&mut self, bg: usize, val: u16) {
for x in 0..BACKGROUND_MAX_SIZE { for x in 0..BACKGROUND_MAX_SIZE {
for y in 0..BACKGROUND_MAX_SIZE { for y in 0..BACKGROUND_MAX_SIZE {
self.bgs[map].tiles[x][y] = val; self.bgs[bg].tiles[x][y] = val;
} }
} }
} }

View File

@ -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 > EMPTY_TILE { if tile != EMPTY_TILE {
draw_tile( draw_tile(
target, target,
IVec2 { IVec2 {
@ -60,7 +60,7 @@ pub(crate) fn render_to_screen(target: &mut [u8], gsa: &Gsa, tileset: &[u8]) {
for i in 0..MAX_BACKGROUNDS { for i in 0..MAX_BACKGROUNDS {
render_map(target, &gsa.bgs[i], tileset); render_map(target, &gsa.bgs[i], tileset);
for sprite in &gsa.sprites { for sprite in &gsa.sprites {
if sprite.tile > 0 && sprite.priority == i as u8 { if sprite.tile != EMPTY_TILE && sprite.priority == i as u8 {
draw_tile(target, sprite.pos, sprite.tile, tileset, false); draw_tile(target, sprite.pos, sprite.tile, tileset, false);
} }
} }

View File

@ -14,6 +14,15 @@
//! - 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
//! //!
//! ## Getting started
//! `cargo install gsa`
//!
//! `gsa new my_project`
//!
//! `cd my_project`
//!
//! `cargo run`
//!
//! ## Features not yet implemented //! ## Features not yet implemented
//! - Background effects //! - Background effects
//! - Rotation? Scaling? //! - Rotation? Scaling?

View File

@ -77,11 +77,12 @@ fn main() {
Some(local) => { Some(local) => {
writeln!( writeln!(
cargo, cargo,
"{} = {{path = \"{}\"}}", "{} = {{path = \"{}\"}}\nglam = \"0.24.0\"\n\n[profile.dev.package.{}]\nopt-level = 3",
crate_name!(), crate_name!(),
canonicalize(local) canonicalize(local)
.expect("couldn't find path") .expect("couldn't find path")
.to_slash_lossy() .to_slash_lossy(),
crate_name!()
) )
.unwrap(); .unwrap();
} }

View File

@ -1,7 +1,11 @@
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, FONT_BOLD, MAX_SPRITES, SCREEN_HEIGHT, SCREEN_WIDTH}; use crate::{
Buttons, Gsa, Sprite, FONT_BOLD, MAX_BACKGROUNDS, MAX_SPRITES, SCREEN_HEIGHT, SCREEN_WIDTH,
TRANSPARENT,
};
use clap::crate_version;
use gilrs::EventType; use gilrs::EventType;
use glam::IVec2; use glam::IVec2;
use std::cmp::min; use std::cmp::min;
@ -46,22 +50,17 @@ pub fn run<TGame: 'static>(
released: 0, released: 0,
down: 0, down: 0,
}; };
let mut game = init_fn(&mut gsa);
/*let state = State::<TGame> {
gsa,
game,
tileset,
update_fn,
first: true,
gilrs: Gilrs::new().unwrap(),
};
*/ gsa.reset_bgs();
gsa.reset_sprites();
let mut game = init_fn(&mut gsa);
let event_loop = EventLoop::new(); let event_loop = EventLoop::new();
let size = LogicalSize::new(SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32); let size = LogicalSize::new(SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32);
//todo: custom title
let window = WindowBuilder::new() let window = WindowBuilder::new()
.with_title("Game Skunk Advance v0.1") .with_title(format!("Game Skunk Advance v{}", crate_version!()))
.with_inner_size(size) .with_inner_size(size)
.with_min_inner_size(size) .with_min_inner_size(size)
.build(&event_loop) .build(&event_loop)
@ -119,8 +118,6 @@ pub fn run<TGame: 'static>(
last_second += Duration::from_secs(1); last_second += Duration::from_secs(1);
} }
let mut screen_buffer = [0u8; SCREEN_WIDTH * SCREEN_HEIGHT];
match event { match event {
Event::WindowEvent { Event::WindowEvent {
event: event:
@ -197,6 +194,7 @@ pub fn run<TGame: 'static>(
*off_x = (size.width as usize - SCREEN_WIDTH * *scale) / 2; *off_x = (size.width as usize - SCREEN_WIDTH * *scale) / 2;
*off_y = (size.height as usize - SCREEN_HEIGHT * *scale) / 2; *off_y = (size.height as usize - SCREEN_HEIGHT * *scale) / 2;
let mut screen_buffer = [TRANSPARENT; SCREEN_WIDTH * SCREEN_HEIGHT];
let mut window_buffer = surface.buffer_mut().unwrap(); let mut window_buffer = surface.buffer_mut().unwrap();
render_to_screen(&mut screen_buffer, &gsa, &tileset); render_to_screen(&mut screen_buffer, &gsa, &tileset);
render_to_window( render_to_window(