graphics

package
v0.0.0-...-1e47bcc Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

useful for when you're not blind

Index

Constants

View Source
const ChunkSize int64 = 16

chunk size (they're square)

View Source
const MaxLayer int64 = 48

how up can you go

View Source
const MinLayer int64 = -16

how down can you go

View Source
const TotalLayers int64 = 64

mate

Variables

View Source
var TileNames map[TileId]string = map[TileId]string{
	TileAir:      "stellarthing:Air",
	TileBobGuy:   "stellarthing:BobGuy",
	TileMarsRock: "stellarthing:MarsRock",
	TileBlueGuy:  "stellarthing:BlueGuy",
	TileGreenGuy: "stellarthing:GreenGuy",
	TileLife:     "stellarthing:Life",
}

printable tile IDs so i don't have to memorize 2370611866

View Source
var Tiles map[TileId]map[VariationId]*TileData = map[TileId]map[VariationId]*TileData{
	TileAir: {
		0: &TileData{
			Texture: "assets/air.png",
			Tint:    core.ColorWhite,
		},
	},
	TileBobGuy: {
		0: &TileData{
			Texture: "assets/bob_guy.png",
			Tint:    core.ColorWhite,
		},
	},
	TileMarsRock: {
		0: &TileData{
			Texture: "assets/mars_rock.png",
			Tint:    core.ColorWhite,
		},
	},
	TileBlueGuy: {
		0: &TileData{
			Texture: "assets/blue_guy.png",
			Tint:    core.ColorWhite,
		},
	},
	TileGreenGuy: {
		0: &TileData{
			Texture: "assets/green_guy.png",
			Tint:    core.ColorWhite,
		},
	},
	TileLife: {
		0: &TileData{
			Texture: "assets/life.png",
			Tint:    core.ColorWhite,
		},
	},
}

tile data from IDs and variations

Functions

func Clear

func Clear(color core.Color)

clears the screen

func DrawTexture

func DrawTexture(texture Texture, pos core.Vec2, angle float64, color core.Color)

draws a texture. if you want a comically large parameter list use DrawTextureExt instead

func DrawTextureExt

func DrawTextureExt(texture Texture, srcPos core.Vec2, srcSize core.Vec2, dstPos core.Vec2,
	dstSize core.Vec2, origin core.Vec2, angle float64, tint core.Color)

this is utter insanity. srcPos and srcSize are used for cropping the image, dstPos and dstSize are the actual position and size, origin is a multiplier so (0, 0) is the top left, (0.5, 0.5) is the center, and (1, 1) is the bottom right. everything else is self-explanatory

func EndDrawing

func EndDrawing()

as the name implies, it ends drawing

func Free

func Free()

mate

func FreeAllTextures

func FreeAllTextures()

func GenerateChunk

func GenerateChunk(randgen *rand.Rand, chunkPos core.Vec3i) (map[core.Vec3i]*Tile, map[core.Vec3i]*Tile)

first result is ground tiles, 2nd is object tiles (cities use those)

func Init

func Init()

called when the window is created

Types

type Texture

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

texture :)

func LoadTexture

func LoadTexture(path string) Texture

supported formats are PNG, BMP, TGA, JPG, GIF, QOI, PSD, DDS, HDR, KTX, ASTC, PKM, and PVR

func (Texture) Free

func (t Texture) Free()

frees the texture and removes it from the cache. if you want to reload the texture, use this

func (Texture) Size

func (t Texture) Size() core.Vec2i

returns the size of the texture in pixels

type Tile

type Tile struct {
	TileId    TileId
	EntityRef entities.EntityRef
	Variation VariationId
}

optimized tile. for actual data use TileData

func (*Tile) GetData

func (t *Tile) GetData() *TileData

as the name implies, it gets the data

func (*Tile) String

func (t *Tile) String() string

type TileData

type TileData struct {
	// path for the string, loaded by the renderer then put in the Texture cache
	Texture string
	// used for moving entities
	Position core.Vec3
	// man
	UsingCustomPos bool
	// lol
	Tint core.Color
}

it's tile data

type TileId

type TileId uint32

yeah

const TileAir TileId = 0
const TileBlueGuy TileId = 3620194283
const TileBobGuy TileId = 370779849
const TileGreenGuy TileId = 1097781405
const TileLife TileId = 4262882056
const TileMarsRock TileId = 2370611866

type TileWorld

type TileWorld struct {
	Seed int64

	// set with SetCameraPosition :)
	CameraPosition core.Vec3
	// mate
	CameraOffset core.Vec2
	// the top left corner
	StartPos core.Vec2i
	// the bottom right corner
	EndPos            core.Vec2i
	LoadedGroundTiles map[core.Vec3i]*Tile
	LoadedObjectTiles map[core.Vec3i]*Tile
	LoadedChunks      []core.Vec3i
	// this sucks
	TheyMightBeMoving []*Tile
	// contains filtered or unexported fields
}

world of tiles :D

var CurrentWorld *TileWorld

current world.

func NewTileWorld

func NewTileWorld(startPos core.Vec2i, endPos core.Vec2i, seed int64) *TileWorld

makes a new world. the startPos is the top left corner and the endPos is the bottom right corner.

func (*TileWorld) Draw

func (t *TileWorld) Draw()

it draws the world. no shit.

func (*TileWorld) GetTile

func (t *TileWorld) GetTile(pos core.Vec3i, ground bool) *Tile

as the name implies, it gets a tile

func (*TileWorld) NewTile

func (t *TileWorld) NewTile(pos core.Vec3i, ground bool, tileId TileId, entity entities.EntityRef,
	variation VariationId) *Tile

as the name implies, it makes a new tile. if the variation doesn't exist, it's gonna copy the default variation too

func (*TileWorld) ScreenToTile

func (t *TileWorld) ScreenToTile(pos core.Vec2, textureSize core.Vec2i) core.Vec3i

gets a tile position from screen positions

func (*TileWorld) SetCameraPosition

func (t *TileWorld) SetCameraPosition(pos core.Vec3)

sets the camera position and loads chunks

func (*TileWorld) TileToScreen

func (t *TileWorld) TileToScreen(pos core.Vec3i, textureSize core.Vec2i) core.Vec2

gets a screen position from tile positions

type VariationId

type VariationId uint32

tiles can have variations. the default variation is always 0

Jump to

Keyboard shortcuts

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