firefly

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The screen width in pixels.
	Width = 240

	// The screen height in pixels.
	Height = 160
)
View Source
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

View Source
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 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 ClearScreen

func ClearScreen(c Color)

Fill the whole frame with the given color.

func DrawArc

func DrawArc(p Point, d int, start, sweep Angle, s Style)

Draw an arc.

func DrawCircle

func DrawCircle(p Point, d int, s Style)

Draw a circle with the given diameter.

func DrawEllipse

func DrawEllipse(p Point, b Size, s Style)

Draw an ellipse (oval).

func DrawImage

func DrawImage(i Image, p Point)

Render an image using the given colors.

func DrawLine

func DrawLine(a, b Point, s LineStyle)

Draw a straight line from point a to point b.

func DrawPoint

func DrawPoint(p Point, c Color)

Set a single point (1 pixel is scaling is 1) on the frame.

func DrawRect

func DrawRect(p Point, b Size, s Style)

Draw a rectangle filling the given bounding box.

func DrawRoundedRect

func DrawRoundedRect(p Point, b, c Size, s Style)

Draw a rectangle with rounded corners.

func DrawSector

func DrawSector(p Point, d int, start, sweep Angle, s Style)

Draw a sector.

func DrawSubImage

func DrawSubImage(i SubImage, p Point)

Draw a subregion of an image.

Most often used to draw a sprite from a sprite atlas.

func DrawText

func DrawText(t string, f Font, p Point, c Color)

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 DrawTriangle

func DrawTriangle(a, b, c Point, s Style)

Draw a triangle.

The order of points doesn't matter.

func DumpDataFile

func DumpDataFile(path string, raw []byte)

Write a file into the app data dir.

func GetRandom

func GetRandom() uint32

Get a random value.

func LogDebug

func LogDebug(t string)

Log a debug message.

func LogError

func LogError(t string)

Log an error message.

func Quit

func Quit()

Exit the app after the current update is finished.

func RemoveDataFile

func RemoveDataFile(path string)

Remove a file from the app data dir.

func Restart added in v0.3.0

func Restart()

Restart the app.

func SetColor

func SetColor(c Color, v RGB)

Set a color value in the palette.

func SetSeed

func SetSeed(seed uint32)

Set the seed used to generate random values.

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.

func Degrees

func Degrees(a float32) Angle

Define an angle in radians where 360.0 is the full circle.

func Radians

func Radians(a float32) Angle

Define an angle in radians where Tau (doubled Pi) is the full circle.

func (Angle) Degrees

func (a Angle) Degrees() float32

Get the angle value in degrees.

func (Angle) Radians

func (a Angle) Radians() float32

Get the angle value in radians.

type Buttons

type Buttons struct {
	// If "a" button is pressed.
	A bool

	// If "b" button is pressed.
	B bool

	// If "x" button is pressed.
	X bool

	// If "y" button is pressed.
	Y bool

	// If "menu" button is pressed.
	//
	// For singleplayer games, the button press is always intercepted by the runtime.
	Menu bool
}

State of the buttons.

func ReadButtons

func ReadButtons(p Peer) Buttons

Get the currently pressed buttons.

The peer can be Combined or one of the GetPeers.

func (Buttons) Held

func (p Buttons) Held(old Buttons) Buttons

Given the old state, get buttons that were pressed and are still pressed now.

func (Buttons) JustPressed

func (p Buttons) JustPressed(old Buttons) Buttons

Given the old state, get buttons that were not pressed but are pressed now.

func (Buttons) JustReleased

func (p Buttons) JustReleased(old Buttons) Buttons

Given the old state, get buttons that were pressed but aren't pressed now.

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

type DPad struct {
	Left  bool
	Right bool
	Up    bool
	Down  bool
}

func (DPad) Held

func (p DPad) Held(old DPad) DPad

Given the old state, get directions that were pressed and are still pressed now.

func (DPad) JustPressed

func (p DPad) JustPressed(old DPad) DPad

Given the old state, get directions that were not pressed but are pressed now.

func (DPad) JustReleased

func (p DPad) JustReleased(old DPad) DPad

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 LoadDataFile

func LoadDataFile(path string) File

Read a file from the app data dir.

func LoadROMFile

func LoadROMFile(path string) File

Read a file from the app ROM.

func (File) Font

func (f File) Font() Font

Convert the File to a Font.

func (File) Image

func (f File) Image() Image

Convert the File to an Image.

type Font

type Font struct {
	// contains filtered or unexported fields
}

A loaded font file.

Can be loaded using LoadROMFile.

type Image

type Image struct {
	// contains filtered or unexported fields
}

A loaded image file.

Can be loaded using LoadROMFile.

func (Image) Sub

func (i Image) Sub(p Point, s Size) SubImage

Get a rectangle subregion of the image.

type LineStyle

type LineStyle struct {
	Color Color
	Width int
}

The same as Style but without a fill color (only stroke color and width).

type Pad

type Pad struct {
	X int
	Y int
}

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 ReadPad

func ReadPad(p Peer) (Pad, bool)

Get the current touch pad state.

The peer can be Combined or one of the GetPeers.

func (Pad) Azimuth

func (p Pad) Azimuth() Angle

The angle of the polar coordinate of the touch point.

func (Pad) DPad

func (p Pad) DPad() DPad

Convert the Pad into DPad.

func (Pad) Point

func (p Pad) Point() Point

Convert the Pad into a Point.

func (Pad) Radius

func (p Pad) Radius() float32

The distance from the pad center to the touch point.

func (Pad) Size

func (p Pad) Size() Size

Convert the Pad into a Size.

type Peer added in v0.3.0

type Peer uint8

The peer ID.

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.

func GetMe added in v0.3.0

func GetMe() Peer

Get the peer ID representing the local device.

type Peers added in v0.3.0

type Peers uint32

The map of peers online.

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.

func (Peers) IsOnline added in v0.3.0

func (peers Peers) IsOnline(peer Peer) bool

Check if the given peer is online.

func (Peers) Len added in v0.3.0

func (peers Peers) Len() int

Get how many peers are online.

func (Peers) Slice added in v0.3.0

func (peers Peers) Slice() []Peer

Get the slice of all peers that are online.

type Point

type Point struct {
	X int
	Y int
}

A point on the screen.

Typically, the upper-left corner of a bounding box of a shape.

func (Point) Abs

func (p Point) Abs() Point

Set X and Y to their absolute (non-negative) value.

func (Point) Add

func (p Point) Add(r Point) Point

Add together two points.

func (Point) ComponentMax

func (p Point) ComponentMax(r Point) Point

Set both X and Y to their maximum in the two given points.

func (Point) ComponentMin

func (p Point) ComponentMin(r Point) Point

Set both X and Y to their minimum in the two given points.

func (Point) Pad

func (p Point) Pad() Pad

Convert the Point to a Pad.

func (Point) Size

func (p Point) Size() Size

Convert the Point to a Size.

func (Point) Sub

func (p Point) Sub(r Point) Point

Subtract the given point from the current one.

type RGB

type RGB struct {
	// Red component
	R uint8
	// Green component
	G uint8
	// Blue component
	B uint8
}

The RGB value of a color in the palette.

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) Abs

func (s Size) Abs() Size

Set W and H to their absolute (non-negative) value.

func (Size) Add

func (s Size) Add(r Size) Size

Add two sizes.

func (Size) ComponentMax

func (s Size) ComponentMax(r Size) Size

Set both W and H to their maximum in the two given sizes.

func (Size) ComponentMin

func (s Size) ComponentMin(r Size) Size

Set both W and H to their minimum in the two given sizes.

func (Size) Pad

func (s Size) Pad() Pad

Convert the Size to a Pad.

func (Size) Point

func (s Size) Point() Point

Convert the Size to a Point.

func (Size) Sub

func (s Size) Sub(r Size) Size

Subtract the given size from the current one.

type Style

type Style struct {
	// The color to use to fill the shape.
	FillColor Color

	// The color to use for the shape stroke.
	StrokeColor Color

	// The width of the shape stroke.
	//
	// If zero, a solid shape without a stroke will be drawn.
	StrokeWidth int
}

Style of a shape.

func (Style) LineStyle

func (s Style) LineStyle() LineStyle

Convert the Style to a LineStyle.

LineStyle is the same as Style except it doesn't have a fill color.

type SubImage

type SubImage struct {
	// contains filtered or unexported fields
}

A subregion of an image. Constructed using Image.Sub.

Directories

Path Synopsis
Structs for working with shapes as values.
Structs for working with shapes as values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL