vm

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package vm is low-level package for directly accessing virtual machine data, such as screen pixels, sprite-sheet, fonts or buttons state. This data can be manipulated by backend, console, utility functions, or a game itself. It is very useful for writing custom tools, new backends or even entire new API to be used by games. Code using vm package directly could be very fast, because it can use low-level Go functions such as copy.

Please note though, that with great power comes great responsibility. You can easily shoot yourself in the foot if you are not careful enough how you change the data. For example, increasing the SpriteSheetWidth without adjusting the SpriteSheetData will likely result in a panic during sprite-drawing operations.

Index

Constants

View Source
const (
	ControllerLeft  = 0
	ControllerRight = 1
	ControllerUp    = 2
	ControllerDown  = 3
	ControllerO     = 4 // O is a first fire button
	ControllerX     = 5 // X is a second fire button
)
View Source
const (
	KeyShift        = 1
	KeyCtrl         = 3
	KeyAlt          = 5 // Please note that on some keyboard layouts on Windows the right alt is a combination of Ctrl+Alt
	KeyCap          = 7
	KeyBack         = '\b' // 8
	KeyTab          = '\t' // 9
	KeyEnter        = '\n' // 10
	KeyF1           = 11
	KeyF2           = 12
	KeyF3           = 13
	KeyF4           = 14
	KeyF5           = 15
	KeyF6           = 16
	KeyF7           = 17
	KeyF8           = 18
	KeyF9           = 19
	KeyF10          = 20
	KeyF11          = 21
	KeyF12          = 22
	KeyLeft         = 23
	KeyRight        = 24
	KeyUp           = 25
	KeyDown         = 26
	KeyEsc          = 27
	KeySpace        = ' '  // 32
	KeyApostrophe   = '\'' // 39
	KeyComma        = ','  // 44
	KeyMinus        = '-'  // 45
	KeyPeriod       = '.'  // 46
	KeySlash        = '/'  // 47
	KeyDigit0       = '0'  // 48
	KeyDigit1       = '1'  // 49
	KeyDigit2       = '2'  // 50
	KeyDigit3       = '3'  // 51
	KeyDigit4       = '4'  // 52
	KeyDigit5       = '5'  // 53
	KeyDigit6       = '6'  // 54
	KeyDigit7       = '7'  // 55
	KeyDigit8       = '8'  // 56
	KeyDigit9       = '9'  // 57
	KeySemicolon    = ';'  // 59
	KeyEqual        = '='  // 61
	KeyA            = 'A'  // 65
	KeyB            = 'B'  // 66
	KeyC            = 'C'  // 67
	KeyD            = 'D'  // 68
	KeyE            = 'E'  // 69
	KeyF            = 'F'  // 70
	KeyG            = 'G'  // 71
	KeyH            = 'H'  // 72
	KeyI            = 'I'  // 73
	KeyJ            = 'J'  // 74
	KeyK            = 'K'  // 75
	KeyL            = 'L'  // 76
	KeyM            = 'M'  // 77
	KeyN            = 'N'  // 78
	KeyO            = 'O'  // 79
	KeyP            = 'P'  // 80
	KeyQ            = 'Q'  // 81
	KeyR            = 'R'  // 82
	KeyS            = 'S'  // 83
	KeyT            = 'T'  // 84
	KeyU            = 'U'  // 85
	KeyV            = 'V'  // 86
	KeyW            = 'W'  // 87
	KeyX            = 'X'  // 88
	KeyY            = 'Y'  // 89
	KeyZ            = 'Z'  // 90
	KeyBracketLeft  = '['  // 91
	KeyBackslash    = '\\' // 92
	KeyBracketRight = ']'  // 93
	KeyBackquote    = '`'  // 96
)
View Source
const (
	MouseLeft   = 0
	MouseMiddle = 1
	MouseRight  = 2
)

Variables

View Source
var (
	SystemFont = Font{
		Width:        4,
		WidthSpecial: 8,
		Height:       6,
	}

	CustomFont = Font{
		Width:        4,
		WidthSpecial: 8,
		Height:       6,
	}
)
View Source
var (
	// Update is a user provided function executed each frame (30 times per second).
	//
	// The purpose of this function is to handle user input, perform calculations, update
	// game state etc. Typically, this function does not draw on screen.
	Update func()

	// Draw is a user provided function executed at most each frame (up to 30 times per second).
	// π may skip calling this function if previous frame took too long.
	//
	// The purpose of this function is to draw on screen.
	Draw func()
)
View Source
var (
	// Palette has all colors available in the game. Up to 256.
	// Palette is taken from loaded sprite sheet (which must be
	// a PNG file with indexed color mode). If sprite-sheet.png was not
	// found, then default 16 color palette is used.
	//
	// Can be freely read and updated. Changes will be visible immediately.
	Palette [256]RGB

	DrawPalette    [256]byte
	DisplayPalette [256]byte

	ColorTransparency [256]bool
)
View Source
var (
	// ScreenData contains pixel colors for the screen visible by the player.
	// Each pixel is one byte. It is initialized during pi.Boot.
	//
	// Pixels on the screen are organized from left to right,
	// top to bottom. Slice element number 0 has pixel located
	// in the top-left corner. Slice element number 1 has pixel color
	// on the right and so on.
	//
	// Can be freely read and updated. Useful when you want to use your own
	// functions for pixel manipulation.
	// Pi will panic if you try to change the length of the slice.
	ScreenData []byte

	// ScreenWidth is the width of the screen (in pixels).
	ScreenWidth int

	// ScreenHeight is the height of the screen (in pixels).
	ScreenHeight int
)
View Source
var (
	// SpriteSheetWidth is a sprite-sheet width in pixels
	SpriteSheetWidth int
	// SpriteSheetHeight is a sprite-sheet height in pixels
	SpriteSheetHeight int

	// SpriteSheetData contains pixel colors for the entire sprite sheet.
	// Each pixel is one byte. It is initialized during pi.Boot.
	//
	// Pixels in the sprite-sheet are organized from left to right,
	// top to bottom. Slice element number 0 has pixel located
	// in the top-left corner. Slice element number 1 has a pixel color
	// on the right and so on.
	//
	// Can be freely read and updated.
	// Useful when you want to use your own functions for pixel manipulation.
	// Pi will panic if you try to change the length of the slice.
	SpriteSheetData []byte
)
View Source
var (
	// TimeSeconds is the number of seconds since game was started
	TimeSeconds float64

	GameLoopStopped bool
)
View Source
var Controllers [8]Controller // 0th element is for Player 0, 1st for Player 1 etc.
View Source
var KeyDuration [97]uint

KeyDuration has info how many frames in a row a keyboard button was pressed: Index of array is equal to key button constant, for example KeyDuration[1] has button duration for Shift key.

View Source
var MouseBtnDuration [3]uint

MouseBtnDuration has how many frames in a row a mouse button was pressed: Index of array is equal to mouse button constant.

Functions

This section is empty.

Types

type Controller

type Controller struct {
	// BtnDuration is how many frames button was pressed:
	// Index of array is equal to controller button constant.
	BtnDuration [6]uint
}

type Font

type Font struct {
	// Data contains all 256 characters sorted by their ascii-like number.
	// Each character is 8 subsequent bytes, starting from the top.
	// Left-most pixel in a line is bit 0. Right-most pixel in a line is bit 7.
	Data [8 * 256]byte
	// Width in pixels for all characters below 128
	Width int
	// WidthSpecial is a with of all special characters (code>=128)
	WidthSpecial int
	// Height of line
	Height int
}

Font contains all information about loaded font.

type Pos

type Pos struct {
	X, Y int
}
var Camera Pos
var MousePos Pos

MousePos is the position of mouse in screen coordinates.

type RGB

type RGB struct{ R, G, B byte }

RGB represents color

func (RGB) String

func (r RGB) String() string

type Region

type Region struct {
	X, Y, W, H int
}
var ClippingRegion Region

Jump to

Keyboard shortcuts

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