golf

package
v0.0.0-...-a3854e7 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ScreenHeight = 192
	ScreenWidth  = 192
)

Engine Screen Width and Height

View Source
const (
	Col0 = Col(0b10000000)
	Col1 = Col(0b10000001)
	Col2 = Col(0b10000010)
	Col3 = Col(0b10000011)
	Col4 = Col(0b10000100)
	Col5 = Col(0b10000101)
	Col6 = Col(0b10000110)
	Col7 = Col(0b10000111)
)

These are the pallet and color constants

View Source
const (
	Pal0  = Pal(0b00000000)
	Pal1  = Pal(0b00000001)
	Pal2  = Pal(0b00000010)
	Pal3  = Pal(0b00000011)
	Pal4  = Pal(0b00000100)
	Pal5  = Pal(0b00000101)
	Pal6  = Pal(0b00000110)
	Pal7  = Pal(0b00000111)
	Pal8  = Pal(0b00001000)
	Pal9  = Pal(0b00001001)
	Pal10 = Pal(0b00001010)
	Pal11 = Pal(0b00001011)
	Pal12 = Pal(0b00001100)
	Pal13 = Pal(0b00001101)
	Pal14 = Pal(0b00001110)
	Pal15 = Pal(0b00001111)
)

The list of all pallets

View Source
const (
	Backspace    = Key(8)
	Tab          = Key(9)
	Enter        = Key(13)
	Shift        = Key(16)
	Ctrl         = Key(17)
	Alt          = Key(18)
	Break        = Key(19)
	CapsLock     = Key(20)
	Esc          = Key(27)
	Space        = Key(32)
	PageUp       = Key(33)
	PageDown     = Key(34)
	End          = Key(35)
	Home         = Key(36)
	LeftArrow    = Key(37)
	UpArrow      = Key(38)
	RightArrow   = Key(39)
	DownArrow    = Key(40)
	Insert       = Key(45)
	Delete       = Key(46)
	ZeroKey      = Key(48)
	OneKey       = Key(49)
	TwoKey       = Key(50)
	ThreeKey     = Key(51)
	FourKey      = Key(52)
	FiveKey      = Key(53)
	SixKey       = Key(54)
	SevenKey     = Key(55)
	EightKey     = Key(56)
	NineKey      = Key(57)
	AKey         = Key(65)
	BKey         = Key(66)
	CKey         = Key(67)
	DKey         = Key(68)
	EKey         = Key(69)
	FKey         = Key(70)
	GKey         = Key(71)
	HKey         = Key(72)
	IKey         = Key(73)
	JKey         = Key(74)
	KKey         = Key(75)
	LKey         = Key(76)
	MKey         = Key(77)
	NKey         = Key(78)
	OKey         = Key(79)
	PKey         = Key(80)
	QKey         = Key(81)
	RKey         = Key(82)
	SKey         = Key(83)
	TKey         = Key(84)
	UKey         = Key(85)
	VKey         = Key(86)
	WKey         = Key(87)
	XKey         = Key(88)
	YKey         = Key(89)
	ZKey         = Key(90)
	LeftWinKey   = Key(91)
	RightWinKey  = Key(92)
	Select       = Key(93)
	NumPad0      = Key(96)
	NumPad1      = Key(97)
	NumPad2      = Key(98)
	NumPad3      = Key(99)
	NumPad4      = Key(100)
	NumPad5      = Key(101)
	NumPad6      = Key(102)
	NumPad7      = Key(103)
	NumPad8      = Key(104)
	NumPad9      = Key(105)
	NumPadMul    = Key(106)
	NumPadPlus   = Key(107)
	NumPadMinus  = Key(109)
	NumPadDot    = Key(110)
	NumPadDiv    = Key(111)
	F1           = Key(112)
	F2           = Key(113)
	F3           = Key(114)
	F4           = Key(115)
	F5           = Key(116)
	F6           = Key(117)
	F7           = Key(118)
	F8           = Key(119)
	F9           = Key(120)
	F10          = Key(121)
	F11          = Key(122)
	F12          = Key(123)
	NumLock      = Key(144)
	ScrollLock   = Key(145)
	SemiColon    = Key(186)
	Equals       = Key(187)
	Comma        = Key(188)
	Minus        = Key(189)
	Period       = Key(190)
	FSlash       = Key(191)
	Tilda        = Key(192)
	OpenBracket  = Key(219)
	BSlash       = Key(220)
	CloseBracket = Key(221)
	Quotes       = Key(222)
)

Golf Key Codes, Mirrors JS key code values

View Source
const (
	LeftClick   = MouseBtn(0)
	MiddleClick = MouseBtn(1)
	RightClick  = MouseBtn(2)
)

MouseKey codes

Variables

This section is empty.

Functions

This section is empty.

Types

type Col

type Col byte

Col is a screen color

type Engine

type Engine struct {
	RAM *[0xFFFF]byte

	Draw   func()
	Update func()
	// contains filtered or unexported fields
}

Engine is the golf engine

func NewEngine

func NewEngine(update func(), draw func()) *Engine

NewEngine creates a new golf engine

func (*Engine) Btn

func (e *Engine) Btn(key Key) bool

Btn returns true if the given key was pressed

func (*Engine) Btnp

func (e *Engine) Btnp(key Key) bool

Btnp returns true if the given key was pressed this frame

func (*Engine) Btnr

func (e *Engine) Btnr(key Key) bool

Btnr returns true if the given key was released this frame

func (*Engine) Camera

func (e *Engine) Camera(x, y int)

Camera moves the camera which modifies all draw functions

func (*Engine) Circ

func (e *Engine) Circ(xc, yc, r float64, col Col, fixed ...bool)

Circ draws a circle using Bresenham's algorithm

func (*Engine) CircFill

func (e *Engine) CircFill(xc, yc, r float64, col Col, fixed ...bool)

CircFill draws a filled circle using Bresenham's algorithm

func (*Engine) Clip

func (e *Engine) Clip(x, y, w, h int)

Clip clips all functions that draw to the screen

func (*Engine) Cls

func (e *Engine) Cls(col Col)

Cls fills the screen with col and resets TextL and TextR

func (*Engine) Dget

func (e *Engine) Dget(name string) ([]byte, bool)

Dget retrives the named data from the browser

func (*Engine) DrawMouse

func (e *Engine) DrawMouse(style int)

DrawMouse sets the draw style 0 = none 1 = mouse 2 = hand 3 = cross

func (*Engine) Dset

func (e *Engine) Dset(name string, data []byte) error

Dset saves the data to the broser with the given name

func (*Engine) Fget

func (e *Engine) Fget(n, f int) bool

Fget gets the fth flag on the nth sprite

func (*Engine) FgetByte

func (e *Engine) FgetByte(n int) byte

FgetByte gets the byte flag on the nth sprite

func (*Engine) Frames

func (e *Engine) Frames() int

Frames is the number of frames since the engine was started

func (*Engine) Fset

func (e *Engine) Fset(n, f int, s bool)

Fset sets the fth flag on the nth sprite to s

func (*Engine) FsetByte

func (e *Engine) FsetByte(n int, b byte)

FsetByte sets the byte flag on the nth sprite

func (*Engine) Line

func (e *Engine) Line(x1, y1, x2, y2 float64, col Col, fixed ...bool)

Line draws a colored line

func (*Engine) LoadFlags

func (e *Engine) LoadFlags(flags [0x200]byte)

LoadFlags load the sprite flags into memory

func (*Engine) LoadMap

func (e *Engine) LoadMap(mapData [0x4800]byte)

LoadMap loads the sprite sheet into memory

func (*Engine) LoadSprs

func (e *Engine) LoadSprs(sheet [0x3000]byte)

LoadSprs loads the sprite sheet into memory

func (*Engine) Map

func (e *Engine) Map(mx, my, mw, mh int, dx, dy float64, opts ...SOp)

Map draws the map on the screen starting from tile mx, my with a size of mw and mh. The map is draw at screen coordinate dx, dy

func (*Engine) Mbtn

func (e *Engine) Mbtn(key MouseBtn) bool

Mbtn returns true is the mouse key is being pressed

func (*Engine) Mbtnp

func (e *Engine) Mbtnp(key MouseBtn) bool

Mbtnp returns true if the mouse key was pressed this frame

func (*Engine) Mbtnr

func (e *Engine) Mbtnr(key MouseBtn) bool

Mbtnr returns true if the mouse key was released this frame

func (*Engine) Mget

func (e *Engine) Mget(x, y int) int

Mget gets the tile at the x, y coordinate on the map

func (*Engine) Mouse

func (e *Engine) Mouse() (int, int)

Mouse returns the X, Y coords of the mouse

func (*Engine) Mset

func (e *Engine) Mset(x, y, t int)

Mset sets the tile at the x, y coordinate on the map

func (*Engine) PalA

func (e *Engine) PalA(pallet Pal)

PalA sets pallet A

func (*Engine) PalB

func (e *Engine) PalB(pallet Pal)

PalB sets pallet B

func (*Engine) PalGet

func (e *Engine) PalGet() (Pal, Pal)

PalGet gets the currently set pallets

func (*Engine) Pget

func (e *Engine) Pget(x, y float64) Col

Pget gets the color of a pixel on the screen

func (*Engine) Pset

func (e *Engine) Pset(x, y float64, col Col)

Pset sets a pixel on the screen

func (*Engine) RClip

func (e *Engine) RClip()

RClip resets the screen cliping

func (*Engine) Rect

func (e *Engine) Rect(x, y, w, h float64, col Col, fixed ...bool)

Rect draws a rectangle border on the screen

func (*Engine) RectFill

func (e *Engine) RectFill(x, y, w, h float64, col Col, fixed ...bool)

RectFill draws a filled rectangle one the screen

func (*Engine) Run

func (e *Engine) Run()

Run starts the game engine running

func (*Engine) SSpr

func (e *Engine) SSpr(sx, sy, sw, sh int, dx, dy float64, opts ...SOp)

SSpr draw a rect from the sprite sheet to the screen sx, sy, sw, and sh define the rect on the sprite sheet dx, dy is the location to draw on the screen

func (*Engine) Spr

func (e *Engine) Spr(n int, x, y float64, opts ...SOp)

Spr draws 8x8 sprite n from the sprite sheet to the screen at x, y.

func (*Engine) Text

func (e *Engine) Text(x, y float64, text string, opts ...TOp)

Text prints text at the x, y coords on the screen

func (*Engine) TextL

func (e *Engine) TextL(text string, opts ...TOp)

TextL prints text at the top left of the screen the cursor moves to a new line each time TextL is called

func (*Engine) TextR

func (e *Engine) TextR(text string, opts ...TOp)

TextR prints text at the top right of the screen the cursor moves to a new line each time TextR is called

type Key

type Key int

Key is a Golf Key

type MouseBtn

type MouseBtn int

MouseBtn is a mouse key

type Pal

type Pal byte

Pal is a screen pallet

type SOp

type SOp struct {
	FH, FV bool
	TCol   Col
	PFrom  []Col
	PTo    []Col
	W, H   int
	SW, SH float64
	Fixed  bool
}

SOp additional options for drawing sprites

type TOp

type TOp struct {
	Col    Col
	Fixed  bool
	SW, SH float64
}

TOp additional options for drawing text

Jump to

Keyboard shortcuts

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