Documentation ¶
Index ¶
- Constants
- Variables
- func AddScore(p Peer, b Board, v int16) int16
- func ClearScreen(c Color)
- func DrawArc(p Point, d int, start, sweep Angle, s Style)
- func DrawCircle(p Point, d int, s Style)
- func DrawEllipse(p Point, b Size, s Style)
- func DrawImage(i Image, p Point)
- func DrawLine(a, b Point, s LineStyle)
- func DrawPoint(p Point, c Color)
- func DrawRect(p Point, b Size, s Style)
- func DrawRoundedRect(p Point, b, c Size, s Style)
- func DrawSector(p Point, d int, start, sweep Angle, s Style)
- func DrawSubImage(i SubImage, p Point)
- func DrawText(t string, f Font, p Point, c Color)
- func DrawTriangle(a, b, c Point, s Style)
- func DumpFile(path string, raw []byte)
- func GetRandom() uint32
- func GetScore(p Peer, b Board) int16
- func LogDebug(t string)
- func LogError(t string)
- func Quit()
- func RemoveFile(path string)
- func Restart()
- func SaveStash(p Peer, b Stash)
- func SetCanvas(c Canvas)
- func SetColor(c Color, v RGB)
- func SetSeed(seed uint32)
- func UnsetCanvas()
- type Angle
- type Badge
- type Board
- type Buttons
- type Canvas
- type Color
- type DPad
- type File
- type Font
- type Image
- func (i Image) BPP() uint8
- func (i Image) GetColor(p uint8) Color
- func (i Image) Height() int
- func (i Image) Pixels() int
- func (i Image) ReplaceColor(old, new Color)
- func (i Image) SetColor(p uint8, c Color)
- func (i Image) SetTransparency(c Color)
- func (i Image) Size() Size
- func (i Image) Sub(p Point, s Size) SubImage
- func (i Image) Transparency() Color
- func (i Image) Width() int
- type LineStyle
- type Pad
- type Peer
- type Peers
- type Point
- type Progress
- type RGB
- type Size
- type Stash
- type Style
- type SubImage
Constants ¶
const ( // The screen width in pixels. Width = 240 // The screen height in pixels. Height = 160 )
const ( // The lowest possible value for [Pad.X]. PadMinX = -1000 // The lowest possible value for [Pad.Y]. PadMinY = -1000 // The highest possible value for [Pad.X]. PadMaxX = 1000 // The highest possible value for [Pad.Y]. PadMaxY = 1000 )
Variables ¶
var ( // Callback to be called once when the app starts. // // Called after memory is initialized and host functions are registered // but before any other callback. Boot func() // Callback to be called on every update. // // Don't use it to draw on the screen, use [Render] instead. Update func() // Callback to be called before rendering the frame. // // Don't use it to update the state, use [Update] instead. Render func() // Callback to be called before exiting the app. BeforeExit func() // Callback to be called before rendering a horizontal line on the screen. // // Accepts the index of the line about to be rendered // and returns the index of the line for which it should be called next time. // Use it to update color palette to support more than 4 colors per frame. RenderLine func(int) int // Callback to be called when a cheat code is sent from firefly CLI. // // Accepts the command index and value and returns a response to show in CLI. Cheat func(int, int) int )
Functions ¶
func AddScore ¶ added in v0.7.0
Add the given score to the board.
May be negative if you want the lower scores to rank higher. Zero value is not added to the board.
If the Peer is Combined, the score is added for every peer and the returned value is the lowest of their best scores.
func DrawRoundedRect ¶
Draw a rectangle with rounded corners.
func DrawSubImage ¶
Draw a subregion of an image.
Most often used to draw a sprite from a sprite atlas.
func DrawText ¶
Render text using the given font.
Unlike in the other drawing functions, here Point points not to the top-left corner but to the baseline start position.
func SaveStash ¶ added in v0.8.0
Save the given Stash.
When called, the stash for the given peer will be stored in RAM. Calling LoadStash for the same peer will return that stash. On exit, the runtime will persist the stash in FS. Next time the app starts, calling LoadStash will restore the stash saved earlier.
func SetCanvas ¶ added in v0.6.0
func SetCanvas(c Canvas)
Set the target image for all subsequent drawing operations.
func UnsetCanvas ¶ added in v0.6.0
func UnsetCanvas()
Make all subsequent drawing operations target the screen instead of a canvas.
Cancels the effect of SetCanvas.
Types ¶
type Angle ¶
type Angle struct {
// contains filtered or unexported fields
}
An angle between two vectors.
Used by DrawArc and DrawSector. Constructed by [Dagrees] and Radians.
type Buttons ¶
type Buttons struct { // South. The bottom button, like A on the X-Box controller. // // Typically used for confirmation, main action, jump, etc. S bool // East. The right button, like B on the X-Box controller. // // Typically used for cancellation, going to previous screen, etc. E bool // West. The left button, like X on the X-Box controller. // // Typically used for attack. W bool // North. The top button, like Y on the X-Box controller. // // Typically used for a secondary action, like charged attack. N bool // The menu button, almost always handled by the runtime. Menu bool }
State of the buttons.
func ReadButtons ¶
Get the currently pressed buttons.
func (Buttons) AnyPressed ¶ added in v0.8.0
Check if any button is currently pressed.
func (Buttons) JustPressed ¶
Given the old state, get buttons that were not pressed but are pressed now.
func (Buttons) JustReleased ¶
Given the old state, get buttons that were pressed but aren't pressed now.
type Canvas ¶ added in v0.6.0
type Canvas struct {
// contains filtered or unexported fields
}
Canvas is an Image that can be drawn upon.
Constructed by NewCanvas.
type Color ¶
type Color uint8
A pointer to a color in the color palette.
const ( // No color (100% transparency). ColorNone Color = 0 // Black color: #1A1C2C. ColorBlack Color = 1 // Purple color: #5D275D. ColorPurple Color = 2 // Red color: #B13E53. ColorRed Color = 3 // Orange color: #EF7D57. ColorOrange Color = 4 // Yellow color: #FFCD75. ColorYellow Color = 5 // Light green color: #A7F070. ColorLightGreen Color = 6 // Green color: #38B764. ColorGreen Color = 7 // Dark green color: #257179. ColorDarkGreen Color = 8 // Dark blue color: #29366F. ColorDarkBlue Color = 9 // Blue color: #3B5DC9. ColorBlue Color = 10 // Light blue color: #41A6F6. ColorLightBlue Color = 11 // Cyan color: #73EFF7. ColorCyan Color = 12 // White color: #F4F4F4. ColorWhite Color = 13 // Light gray color: #94B0C2. ColorLightGray Color = 14 // Gray color: #566C86. ColorGray Color = 15 // Dark gray color: #333C57. ColorDarkGray Color = 16 )
type DPad ¶
func (DPad) JustPressed ¶
Given the old state, get directions that were not pressed but are pressed now.
func (DPad) JustReleased ¶
Given the old state, get directions that were pressed but aren't pressed now.
type File ¶
type File struct {
Raw []byte
}
A file loaded from the filesystem.
func LoadFile ¶ added in v0.6.0
Read a file.
It will first lookup file in the app's ROM directory and then check the app writable data directory.
If the file does not exist, the Raw value of the returned File will be nil.
The second argument is the buffer in which the file should be loaded. If the buffer is smaller than the file content, it gets cut. If the buffer is nil, a new buffer of sufficient size will be allocated.
type Font ¶
type Font struct {
// contains filtered or unexported fields
}
A loaded font file.
Can be loaded using LoadFile.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
A loaded image file.
Can be loaded using LoadFile.
func (Image) ReplaceColor ¶ added in v0.6.0
Replace the old color with the new value.
func (Image) SetTransparency ¶ added in v0.6.0
Set the color that should represent transparency.
Pass ColorNone to disable transparency.
func (Image) Transparency ¶ added in v0.6.0
The color used for transparency. If no transparency, returns ColorNone.
type Pad ¶
A finger position on the touch pad.
Both X and Y are somewhere the range between -1000 and 1000 (both ends included). The 1000 X is on the right, the 1000 Y is on the top.
func (Pad) Azimuth ¶
The angle of the polar coordinate of the touch point.
type Peer ¶ added in v0.3.0
type Peer uint8
The peer ID.
Can be obtained by getting the list of Peers using GetPeers and then iterating over it.
const Combined Peer = 0xFF
Peer value that can be passed to ReadPad and ReadButtons to get the combined input of all peers.
Useful for single-player games that want in multi-player to handle inputs from all devices as one input.
type Peers ¶ added in v0.3.0
type Peers uint32
The map of peers online.
Can be obtained using GetPeers.
func GetPeers ¶ added in v0.3.0
func GetPeers() Peers
Get the list of peers that are currently online.
Includes the local device.
It can be used to detect if multiplayer is active: if there is more than 1 peer, you're playing with friends.
type Point ¶
A point on the screen.
Typically, the upper-left corner of a bounding box of a shape.
func (Point) ComponentMax ¶
Set both X and Y to their maximum in the two given points.
func (Point) ComponentMin ¶
Set both X and Y to their minimum in the two given points.
type Progress ¶ added in v0.7.0
type Progress struct { // How many points the player already has. Done uint16 // How many points the player needs to earn the badge. Goal uint16 }
func AddProgress ¶ added in v0.7.0
Add the given value to the progress for the badge.
May be negative if you want to decrease the progress. If zero, does not change the progress.
If the Peer is Combined, the progress is added to every peer and the returned value is the lowest progress.
func GetProgress ¶ added in v0.7.0
Get the progress of earning the badge.
type Size ¶
type Size struct { // W is the width of the bounding box. W int // H is the height of the bounding box. H int }
Size of a bounding box for a shape.
The width and height must be positive.
func (Size) ComponentMax ¶
Set both W and H to their maximum in the two given sizes.
func (Size) ComponentMin ¶
Set both W and H to their minimum in the two given sizes.
type Stash ¶ added in v0.8.0
type Stash = []byte
Stash is a serialized binary state of the app that you want to persist between app runs and to be available in multiplayer.
For single-player purposes, you can save data in a regular file using DumpFile. File saved that way can be bigger (and you can create lots of them) but it cannot be accessed in multiplayer.
It's your job to serialize data into a binary stash and later parse it. Stash can be saved using SaveStash and later read using LoadStash.
func LoadStash ¶ added in v0.8.0
Load Stash saved earlier (in this or previous run) by SaveStash.
The buffer should be big enough to fit the stash. If it's not, the stash will be truncated. If there is no stash or it's empty, nil is returned.
If the given buffer is nil, a new buffer will be allocated big enough to fit the biggest allowed stash. At the moment, it is 80 bytes.