Proper support for Tiled-based tiling

Before, all tiles were 'a'; now, the right
character gets selected for each!
This commit is contained in:
Jaidyn Ann 2023-06-01 00:07:28 -05:00
parent 7de2dbe941
commit 9661bfefe0
9 changed files with 69 additions and 41 deletions

View File

@ -21,9 +21,10 @@
(ql:quickload :cl-tiled) (ql:quickload :cl-tiled)
(defun main () (defun main ()
(clear-screen) (clear-screen)
(draw-map "/home/jaidyn/.local/src/games/flower/res/mom.tmx")) (draw-map "/home/jaidyn/.local/src/games/flower/res/map.tmx"))
(defun move-cursor (row column &key (stream *standard-output*)) (defun move-cursor (row column &key (stream *standard-output*))
@ -40,19 +41,33 @@ Borrowed from https://github.com/gorozhin/chlorophyll/
(defun draw-map (map-path) (defun draw-map (map-path)
"Draw a Tiled-format tilemap to the screen."
(mapcar #'draw-tile-layer (mapcar #'draw-tile-layer
(cl-tiled:map-layers (cl-tiled:load-map map-path)))) (cl-tiled:map-layers (cl-tiled:load-map map-path))))
(defun draw-tile-layer (tile-layer) (defun draw-tile-layer (tile-layer)
"Draw a Tiled tile-layer to the screen."
(mapcar #'draw-cell (mapcar #'draw-cell
(cl-tiled:layer-cells tile-layer))) (cl-tiled:layer-cells tile-layer)))
(defun draw-cell (cell) (defun draw-cell (cell)
(move-cursor (cl-tiled:cell-row cell) "Draw a specific cell of a tile-layer to the screen."
(cl-tiled:cell-column cell)) (move-cursor (+ (cl-tiled:cell-row cell) 1)
(write-char #\A)) (+ (cl-tiled:cell-column cell) 1))
(write-char (tile-character
(cl-tiled:cell-tile cell))))
(defun tile-character (tile)
"Given a tileset's tile, return it's corresponding text character,
assuming that the tileset is a bitmap font starting with char-code 32
with 15 characters-per-line."
(code-char
(+ (* (cl-tiled:tile-row tile) 15)
(cl-tiled:tile-column tile)
32)))
(main) (main)

BIN
res/font.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

4
res/font.tsx Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.10.1" name="font" tilewidth="17" tileheight="17" tilecount="105" columns="15">
<image source="font.png" width="256" height="128"/>
</tileset>

18
res/font.txt Normal file
View File

@ -0,0 +1,18 @@
A Tiled tileset generated from Fira Code Regular⁽¹⁾ printable ASCII characters.
This is (ofc) not used in the game, but is very handy for visualizing the map in Tiled!
Generated thanks to the beautiful program ttf2png⁽²⁾, like so:
$ ttf2png -r 32,126 -s 15 -l 15 -e -t -o font.png FiraCode-Regular.ttf
Note `-l 15`, which sets the row-length to 15. This is very important!
Flora's engine parses the tiles' character values by calculating the tile's
[15(row - 1) + column].
Could we avoid this, and automatically figure out the row-length? Yeaaa.
Could I be bothered? Nooo.
[1] https://github.com/tonsky/FiraCode
Fira Code © 2014 Fira Coda Authors, SIL OFL 1.1
[2] https://www.tdb.fi/ttf2png.shtml
TTF2PNG © 2021 tdb, GNU GPLv1

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.10.1" name="map font" tilewidth="7" tileheight="9" tilecount="126" columns="18">
<image source="map font.png" trans="000000" width="128" height="64"/>
</tileset>

View File

@ -1,5 +0,0 @@
License: CC0
Author: domsson
URL: https://opengameart.org/content/ascii-bitmap-font-oldschool
Used as a tilemap in Tiled — just to help visualize the maps!

28
res/map.tmx Normal file
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.1" orientation="orthogonal" renderorder="left-down" width="72" height="20" tilewidth="17" tileheight="17" infinite="0" nextlayerid="2" nextobjectid="1">
<tileset firstgid="1" source="font.tsx"/>
<layer id="1" name="Tile Layer 1" width="72" height="20">
<data encoding="csv">
2,0,18,18,18,19,20,21,22,23,24,0,0,0,48,48,33,33,33,33,33,18,19,20,21,22,23,24,0,18,33,33,48,63,63,63,64,65,66,67,63,18,19,20,21,22,23,24,0,0,0,0,0,0,0,0,33,48,63,64,65,66,67,68,69,0,0,0,0,0,0,0,
0,0,33,33,18,19,20,21,22,23,24,0,0,18,63,63,48,48,48,48,48,18,19,20,21,22,23,24,18,33,48,48,63,64,65,66,67,68,69,0,0,18,19,20,21,22,23,24,0,0,0,0,0,0,0,18,48,63,64,65,66,67,68,69,0,0,0,0,0,0,0,0,
0,0,48,48,18,19,20,21,22,23,24,0,0,33,63,64,63,63,63,63,63,18,19,20,21,22,23,18,33,48,63,63,64,65,66,67,68,69,0,0,0,18,19,20,21,22,23,24,0,0,0,0,0,0,18,33,63,64,65,66,67,68,69,0,0,0,0,0,0,0,0,0,
0,18,63,63,33,18,19,20,21,22,23,24,0,48,63,64,65,66,67,68,69,18,19,20,21,22,23,33,48,63,64,65,66,67,68,69,0,0,0,0,0,18,19,20,21,22,23,24,0,0,0,0,0,0,33,48,63,64,65,66,67,68,69,0,0,0,0,0,0,0,0,0,
0,33,63,64,48,18,19,20,21,22,23,24,0,63,63,64,65,66,67,68,69,18,19,20,21,22,18,48,63,64,65,66,67,68,69,0,0,0,0,0,0,18,19,20,21,22,23,24,0,0,0,0,0,18,48,63,64,65,66,67,68,69,0,0,0,0,0,0,0,0,0,0,
0,48,63,64,63,18,19,20,21,22,23,24,0,63,64,65,66,67,68,69,0,18,18,18,18,18,33,63,64,65,66,67,68,69,18,19,20,21,22,23,18,19,20,21,22,23,24,39,0,0,0,0,0,33,63,64,65,66,67,68,69,0,0,0,0,0,0,0,0,0,0,0,
0,63,64,65,66,18,19,20,21,22,23,24,0,63,64,65,66,67,68,69,18,18,33,33,33,33,48,63,64,65,66,67,68,69,33,18,18,18,19,20,18,19,20,21,22,23,24,54,0,0,0,0,18,48,63,64,65,66,67,68,69,0,0,0,0,0,0,0,0,0,0,0,
0,63,64,65,66,33,18,19,20,21,22,23,24,63,64,65,66,18,18,18,33,33,48,48,48,48,63,64,65,66,67,68,69,48,48,33,33,18,18,18,19,20,21,22,23,24,39,69,0,0,0,0,33,63,64,65,66,67,68,69,18,19,20,21,22,23,24,24,24,24,24,0,
18,63,64,65,66,48,33,18,19,20,21,22,23,63,64,65,66,33,33,33,48,48,63,63,63,63,64,65,66,67,68,69,63,63,63,48,48,33,18,18,19,20,21,22,23,24,54,0,0,0,0,18,48,63,64,65,66,67,68,69,19,20,21,22,23,24,39,39,39,39,39,24,
33,63,64,65,66,63,48,18,19,20,21,22,23,63,64,65,66,48,48,48,63,63,64,65,66,63,64,65,66,67,68,69,0,0,0,63,63,48,18,18,19,20,21,22,23,24,69,0,0,0,0,33,63,64,65,66,67,68,69,19,20,21,22,23,24,39,54,54,54,54,54,39,
48,63,64,65,66,67,63,33,18,19,20,21,22,63,64,65,66,63,63,63,64,65,66,67,68,63,64,65,66,67,68,69,0,0,0,0,0,63,18,19,20,21,22,23,24,39,0,0,0,0,18,48,63,64,65,66,67,68,69,20,21,22,23,24,39,54,69,69,69,69,69,54,
63,63,64,65,66,67,68,48,33,18,19,20,21,63,64,65,66,63,64,65,66,67,68,69,69,63,64,65,66,67,68,69,24,0,0,0,0,18,19,20,21,22,23,24,39,54,0,0,0,0,33,63,64,65,66,67,68,69,20,21,22,23,24,24,54,69,65,66,67,68,69,69,
63,64,65,66,67,68,69,63,48,18,19,20,21,63,64,65,66,67,68,69,39,0,0,0,0,63,64,65,66,67,68,69,39,24,19,20,21,18,19,20,21,22,23,24,54,69,0,0,0,0,48,63,64,65,66,67,68,69,20,21,22,23,24,39,69,0,0,63,64,65,66,67,
63,64,65,66,67,68,69,0,63,33,18,19,20,63,64,65,66,67,68,69,54,0,0,0,0,63,64,65,66,67,68,69,54,39,24,24,18,19,20,21,22,23,24,39,69,0,0,0,0,0,63,64,65,66,67,68,69,20,21,22,23,24,39,54,0,0,0,0,0,63,64,65,
63,64,65,66,67,68,69,0,0,48,33,18,19,20,63,64,65,66,67,68,69,24,0,0,0,0,63,64,65,66,67,68,69,54,39,18,19,20,21,22,23,24,24,54,69,0,0,0,0,0,63,64,65,66,67,68,69,21,22,23,24,39,54,69,0,0,0,0,0,0,0,18,
63,64,65,66,67,68,69,0,0,63,48,33,18,19,63,64,65,66,67,68,69,39,0,0,0,0,63,64,65,66,67,68,69,69,54,18,19,20,21,22,23,24,39,69,0,0,0,0,0,18,63,64,65,66,67,68,69,22,23,24,24,54,69,0,0,0,0,18,18,18,18,33,
63,64,65,66,67,68,69,0,0,0,63,48,33,18,63,64,65,66,67,68,69,54,24,0,0,0,0,0,63,64,65,66,67,68,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,33,63,64,65,66,67,68,69,22,23,24,39,69,18,18,18,18,18,33,33,33,33,48,
63,64,65,66,67,68,69,0,0,0,0,63,48,33,18,63,64,65,66,67,68,69,39,0,0,0,0,0,0,0,0,0,0,0,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,48,63,64,65,66,67,68,69,23,24,39,54,33,33,33,33,33,33,48,48,48,48,63,
0,0,0,0,0,0,0,0,0,0,0,0,63,48,33,63,64,65,66,67,68,69,54,24,0,0,0,0,0,0,0,0,0,0,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,63,64,65,66,67,68,69,22,23,24,54,69,48,48,48,48,48,48,63,63,63,63,64,
0,0,0,0,0,0,0,0,0,0,0,0,0,63,48,33,63,64,65,66,67,68,69,39,0,0,0,0,0,0,0,0,0,0,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,64,65,66,67,68,69,22,23,24,69,63,63,63,63,63,63,63,64,65,66,67,68
</data>
</layer>
</map>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.1" orientation="orthogonal" renderorder="left-down" width="72" height="20" tilewidth="9" tileheight="9" infinite="0" nextlayerid="5" nextobjectid="4">
<tileset firstgid="1" source="map font.tsx"/>
<layer id="4" name="Foreground" width="72" height="20">
<data encoding="csv">
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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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