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
}

View file

@ -0,0 +1,9 @@
package graphics
import rl "github.com/gen2brain/raylib-go/raylib"
func LoadTextureFromMemory(fileType string, data []byte) rl.Texture2D {
img := rl.LoadImageFromMemory(fileType, data, int32(len(data)))
defer rl.UnloadImage(img)
return rl.LoadTextureFromImage(img)
}

18
engine/graphics/tile.go Normal file
View file

@ -0,0 +1,18 @@
package graphics
import rl "github.com/gen2brain/raylib-go/raylib"
type Tile struct {
Size byte
X, Y byte
}
// GetTexRect returns the texture rectangle.
func (t Tile) GetTexRect() rl.Rectangle {
return rl.Rectangle{
X: float32(t.X * t.Size),
Y: float32(t.Y * t.Size),
Width: float32(t.Size),
Height: float32(t.Size),
}
}