1
0
Fork 0

Initial commit

This commit is contained in:
Henrik Hautakoski 2025-09-14 08:38:30 +02:00
commit 0245a5cb43
22 changed files with 610 additions and 0 deletions

View file

@ -0,0 +1,41 @@
package font
import (
"tetris/engine/graphics"
)
// TileFont represents a tile-based font where each character maps
// to a tile location (X, Y) in a tileset or texture atlas.
//
// The character-to-tile mapping is defined in the Charmap.
// If CaseInsensitive is true, uppercase characters ('A''Z')
// are automatically converted to lowercase before lookup.
type TileFont struct {
Charmap map[rune]byte
// CaseInsensitive forces all characters to lowercase before lookup.
CaseInsensitive bool
}
// GetTile returns the Tile corresponding to the given character.
//
// If CaseInsensitive is enabled, uppercase ASCII characters are converted
// to lowercase before lookup. If the character is not found in the Charmap,
// GetTile returns nil.
//
// The resulting Tile assumes a fixed tile size of 8x8 pixels
func (f TileFont) GetTile(char rune) *graphics.Tile {
// convert to lowercase
if f.CaseInsensitive && char >= 'A' && char <= 'Z' {
char = char + 0x20
}
if offset, found := f.Charmap[char]; found {
return &graphics.Tile{
Size: 8,
X: offset & 0xF,
Y: offset >> 4,
}
}
return nil
}