Documentation ¶
Overview ¶
Package matrigo provides an abstraction layer over go-sdl2.
It works for tile-based words, like famous games Sokoban, Minesweeper and Tetris.
The client sends a configuration object during the initialization and this package exposes few methods to draw tiles and manage input from the user.
For usage examples see the Readme file in the package repository: https://github.com/tommyblue/matrigo
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Draw ¶
func Draw(matrix *Matrix)
Draw what needs to be drawn down. It draws the background image and color, all the images and then syncs the frame rate to the value in the fpsTarget variable
func Init ¶
Init the package. The client must call this function with a valid configuration at the beginning of the ui setup
func ManageInput ¶
func ManageInput(inputInterface Input)
ManageInput listens for events from the user and calls the callbacks provided by the Input interface
Types ¶
type Conf ¶
type Conf struct { TileSize int32 // Size of the side of the tiles (tiles are squared) Title string // Title of the window Fonts map[string]FontConfig // Fonts to use Debug bool // Enable or disable debugging Window *Window // Window to draw BackgroundColor *[4]uint8 // Background color of the window BackgroundImage string // Background image. Must be of the same size of the Window (optional) ImagesToCache *map[string]string // All the images to add to the cache, as key => abs path of the image SyncFPS bool // Sync the frame rate to 60fps }
Conf is the global configuration of the library
type FontConfig ¶
type FontConfig struct { Path string // Absolute path to a ttf font file Size int // Font size in points }
FontConfig is used to configure the fonts to use. Each struct must contain the absolute path to a ttf font file and its size (in points)
type Input ¶
type Input interface { // x and y passed to the mouse click functions are the position, in pixels, based on the Window // where (0, 0) is the top-left (NW) corner. The receiver should then convert the position to // the clicked tile MouseLeftClickDown(x, y int32) MouseRightClickDown(x, y int32) // TODO: keyboard event Quit() }
Input is the interface that must be implemented by clients to receive input callbacks. The implementation must then be passed to ManageInput that will call the callbacks when the corresponding event will happen
type Matrix ¶
type Matrix struct {
Tiles []*Tile // Array of tiles
}
Matrix represents the whole tiles (i.e. images) to draw in the window
type Tile ¶
type Tile struct { ImageID string // Absolute path to the image file PosX int32 // X position (column) of the tile in the matrix PosY int32 // Y position (row) of the tile in the matrix OffsetX int32 // Offset in the X direction in pixels OffsetY int32 // Offset in the Y direction in pixels }
Tile is an image to be drawn down. Each Tile has an absolute path to the image file and its position (x and y) in the matrix