Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a library to handle tiled graphics #325

Open
euhmeuh opened this issue Sep 20, 2019 · 5 comments
Open

Provide a library to handle tiled graphics #325

euhmeuh opened this issue Sep 20, 2019 · 5 comments

Comments

@euhmeuh
Copy link

euhmeuh commented Sep 20, 2019

I'm trying to make a top down strategy game using gbForth, and wonder how to easily render tiled maps on the screen.

For now, I'm using the term.fs library, but it feels clunky and unpractical to consider graphics as text lines. The machine tends to become slow as I try to render more lines of tiles to the screen (I currently prepare the map in RAM before sending it to type, which explains the performance loss).

I'm considering writing a library, something like tilemap.fs, to ease the creation and rendering of tilemaps.

I'm opening this issue here to gather thoughts and directions on how to do that.

Plans

  1. Define the 32x32 map using a word like map::
map: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
map: 0 3 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
map: 3 2 3 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
map: 0 3 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
map: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
map: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 0 0 0 0 0 0 0 0 0 0 0
map: 0 0 0 0 0 0 0 0 4 0 4 0 4 0 0 0 0 0 0 6 6 0 0 0 0 0 0 0 0 0 0 0
map: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
\ ... 32 times
  1. Define masks of a specific tile:
( this would render a map using tiles 4 and 5 )
mask: 4 %00000000 %00001110 %00000000 %00000001
mask: 5 %01100000 %00111110 %00000000 %00000001
mask: 5 %01100000 %00011000 %00000000 %00000011
mask: 4 %00000000 %00000000 %00001111 %00000111
\ ... 32 times
  1. Copy/extract a map to VRAM using map!video or mask!video.
@tkers
Copy link
Member

tkers commented Sep 22, 2019

Interesting :) just to understand a bit better what you’re looking for: Are you talking about a static (background) tilemap? Also, what would mask: do in your example (if map: is already used to define the map)?

@euhmeuh
Copy link
Author

euhmeuh commented Sep 23, 2019

Yes, I'm talking about background maps. The gameboy has a 32x32 tilemap that you can scroll (using rSCX and rSCY).

map: would create map data using the official 1-byte-per-tile format of the machine, while mask: would be used has a way to compress that data on the ROM in case you only need one type of tile, by using 1-bit-per-tile (thus allowing to save 8 times more maps in the same space).

A concrete example would be:

I have 2 different types of tiles: Grass and Water
I want to generate a random map using layers of those two tiles.
I'll create a first mask with patches of grass:

create GRASS-LAYER
mask: GRASS %00011000 %00000001 %10000000 %00000000
mask: GRASS %00111100 %00001111 %11100000 %00000000
mask: GRASS %00011100 %00000111 %11000001 %11000000
mask: GRASS %00000000 %00000000 %00000111 %10000000

Then I'll create some water streams:

create WATER-LAYER
mask: WATER %00000000 %00000000 %00000000 %00000000
mask: WATER %00000111 %11100000 %00000011 %11110000
mask: WATER %11111000 %00011000 %00111100 %00001000
mask: WATER %00000000 %00000111 %11000000 %00000111

Then I can load both of them on the real map using mask!video:

GRASS-LAYER mask!video 
WATER-LAYER mask!video

I would get a final result looking like this:

...ww..........ww...............
..www~~~~~~.wwwwwww...~~~~~~....
~~~~~w.....~~wwwww~~~~.www..~...
.............~~~~~...wwww....~~~

@euhmeuh
Copy link
Author

euhmeuh commented Sep 23, 2019

Maybe we could also leave the tile identity to runtime:

create MASK01
mask: %00000000 %00000000 %00000000 %00000000
mask: %00000111 %11100000 %00000011 %11110000
mask: %11111000 %00011000 %00111100 %00001000
mask: %00000000 %00000111 %11000000 %00000111

: load-map
  MASK00 GRASS mask!video
  MASK01 WATER mask!video
;

So that you can create a lot of masks and reuse them with different tiles.

@euhmeuh
Copy link
Author

euhmeuh commented Oct 8, 2019

But maybe I'll leave the mask thing out, and just provide a way to load maps.
It seems the mask system is too tied to my game logic.

I'll put up a pull request soon.

@tkers
Copy link
Member

tkers commented Oct 8, 2019

I’d probably agree on that. While I understand the use case for it in your situation, it doesn’t seem to be a very general need.

That being said, looking forward to your contribution (and game!) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants