Documentation ¶
Index ¶
- Constants
- Variables
- func AddCollideable(c Collideable)
- func CollisionBBox(pos1, size1, pos2, size2 pixel.Vec) bool
- func DrawHLine(img *image.RGBA, x1, y, x2 int)
- func DrawSetColor(color pixel.RGBA)
- func DrawVLine(img *image.RGBA, x, y1, y2 int)
- func GetCollisionDirection(c1, c2 Collideable) byte
- func GetInventoryItemDrawPosition(win *opengl.Window, x, y int) pixel.Vec
- func MakeDebugRect(win *opengl.Window, w, h int) *pixel.Sprite
- func MakeRect(w, h int, c color.Color) (*image.RGBA, *pixel.Sprite)
- type Block
- type Camera
- type Chunk
- type Collideable
- type Floater
- func (f *Floater) Collide(c Collideable)
- func (f *Floater) Draw(win *opengl.Window)
- func (f *Floater) DrawDebug(win *opengl.Window)
- func (f *Floater) GetOldPosition() pixel.Vec
- func (f *Floater) GetPosition() pixel.Vec
- func (f *Floater) GetSize() pixel.Vec
- func (f *Floater) GetType() byte
- func (f *Floater) IsSolid() bool
- func (f *Floater) Update(dt float64)
- type GUI
- func (g *GUI) ButtonCallback(btn pixel.Button, action pixel.Action)
- func (g *GUI) ClearCraftingItems()
- func (g *GUI) Draw(cam *Camera)
- func (g *GUI) DrawHotbar()
- func (g *GUI) DrawInventory()
- func (g *GUI) HandleCraftingSlotLeftClick(x, y int)
- func (g *GUI) HandleCraftingSlotRightClick(x, y int)
- func (g *GUI) HandleDeleteItemLeftClick(x, y int)
- func (g *GUI) HandleInventoryLeftClick(x, y int)
- func (g *GUI) HandleInventoryRightClick(x, y int)
- func (g *GUI) RedrawBars()
- func (g *GUI) SetHotbarItems(items []*InventoryItem, hotbarX int)
- func (g *GUI) SetInventoryItems(items [][]*InventoryItem)
- func (g *GUI) Update(dt float64)
- func (g *GUI) UpdateHealth(v float64)
- func (g *GUI) UpdateHunger(v float64)
- func (g *GUI) UpdateThirst(v float64)
- type Game
- func (g *Game) ButtonCallback(btn pixel.Button, action pixel.Action)
- func (g *Game) CharCallback(r rune)
- func (g *Game) CheckCollisions()
- func (g *Game) Draw()
- func (g *Game) Init(win *opengl.Window)
- func (g *Game) Scroll(win *opengl.Window, scroll pixel.Vec)
- func (g *Game) Update(win *opengl.Window, dt float64)
- type IntVec
- type InventoryItem
- type Map
- type Player
- func (p *Player) AddInventoryItem(i *InventoryItem)
- func (p *Player) AddItemToInventory(underType, itemType, frame byte)
- func (p *Player) AddMovementDirection(d byte)
- func (p *Player) ButtonCallback(game *Game, btn pixel.Button, action pixel.Action)
- func (p *Player) CharCallback(game *Game, r rune)
- func (p *Player) ClearInventory()
- func (p *Player) Collide(c Collideable)
- func (p *Player) Draw(game *Game)
- func (p *Player) DrawDebug(win *opengl.Window)
- func (p *Player) GetBlockPosition() IntVec
- func (p *Player) GetChunkPosition() pixel.Vec
- func (p *Player) GetHeldItem() *InventoryItem
- func (p *Player) GetMouseMapBlockCoords(game *Game) pixel.Vec
- func (p *Player) GetMouseMapBlockPosition(game *Game) pixel.Vec
- func (p *Player) GetMouseMapCoords(game *Game) (IntVec, IntVec)
- func (p *Player) GetMouseMapPosition(game *Game) pixel.Vec
- func (p *Player) GetOldPosition() pixel.Vec
- func (p *Player) GetPosition() pixel.Vec
- func (p *Player) GetSize() pixel.Vec
- func (p *Player) GetType() byte
- func (p *Player) HandleRightClick(game *Game)
- func (p *Player) IsMovingInDirection(d byte) bool
- func (p *Player) IsSolid() bool
- func (p *Player) PlaceBlock(game *Game, item *InventoryItem)
- func (p *Player) RemoveInventoryItem(i *InventoryItem)
- func (p *Player) RemoveMovementDirection(d byte)
- func (p *Player) ThrowInventoryItem(game *Game)
- func (p *Player) Update(win *opengl.Window, dt float64)
- type Spritesheet
Constants ¶
View Source
const ( BlockTypeDirt byte = 0 BlockTypeGrass byte = 1 BlockTypeTree byte = 2 BlockTypeStone byte = 3 BlockTypeCopper byte = 4 BlockTypeDirtFrameDirt byte = 0 BlockTypeGrassFrame1 byte = 0 BlockTypeGrassFrame2 byte = 1 BlockTypeGrassFrame3 byte = 2 BlockTypeGrassFrame4 byte = 3 BlockTypeTreeFrameSapling byte = 0 BlockTypeTreeFrameGrownTop byte = 1 BlockTypeTreeFrameGrownBottom byte = 2 BlockTypeStoneFrame1 byte = 0 BlockTypeCopperFrame1 byte = 0 )
View Source
const ( CollideableTypeBlock byte = 0 CollideableTypePlayer byte = 1 CollideableTypeFloater byte = 2 )
View Source
const ( CollisionDirectionUp byte = 1 CollisionDirectionDown byte = 2 CollisionDirectionLeft byte = 3 CollisionDirectionRight byte = 4 )
View Source
const ( PlayerDirectionUp byte = 0 PlayerDirectionDown byte = 1 PlayerDirectionLeft byte = 2 PlayerDirectionRight byte = 3 PlayerWalking byte = 0 PlayerRunning byte = 1 )
View Source
const (
FloaterTypeDirt byte = 0
)
View Source
const (
UnderlyingTypePlaceableBlock byte = 0
)
Variables ¶
View Source
var ( DrawColor = pixel.RGBA{R: 1, G: 1, B: 1} RectangleSprites = map[int]map[int]*pixel.Sprite{} )
Functions ¶
func AddCollideable ¶
func AddCollideable(c Collideable)
func CollisionBBox ¶
func CollisionBBox(pos1, size1, pos2, size2 pixel.Vec) bool
func DrawSetColor ¶
func DrawSetColor(color pixel.RGBA)
func GetCollisionDirection ¶
func GetCollisionDirection(c1, c2 Collideable) byte
func MakeDebugRect ¶
Rect draws a rectangle utilizing HLine() and VLine()
Types ¶
type Block ¶
func (*Block) Collide ¶
func (b *Block) Collide(c Collideable)
func (*Block) GetOldPosition ¶
func (b *Block) GetOldPosition() pixel.Vec
func (*Block) GetPosition ¶
func (b *Block) GetPosition() pixel.Vec
type Camera ¶
type Camera struct { Matrix pixel.Matrix Position pixel.Vec Speed float64 Zoom float64 ZoomSpeed float64 }
func (*Camera) StartCamera ¶
type Collideable ¶
type Collideable interface { GetPosition() pixel.Vec GetSize() pixel.Vec Collide(Collideable) IsSolid() bool GetType() byte DrawDebug(*opengl.Window) GetOldPosition() pixel.Vec }
type Floater ¶
type Floater struct { Position pixel.Vec Velocity pixel.Vec OldPosition pixel.Vec UnderlyingType byte ItemType byte Frame byte Size pixel.Vec Scale float64 Solid bool Sprite *pixel.Sprite RotationSpeed float64 Rotation float64 ScaleSpeed float64 ScaleMax float64 ScaleMin float64 ScaleDir float64 DebugRect *pixel.Sprite Deleted bool }
When an item is dropped, it "floats" and rotates around on the ground until someone picks it up
func NewFloater ¶
func (*Floater) Collide ¶
func (f *Floater) Collide(c Collideable)
func (*Floater) GetOldPosition ¶
func (f *Floater) GetOldPosition() pixel.Vec
func (*Floater) GetPosition ¶
func (f *Floater) GetPosition() pixel.Vec
type GUI ¶
type GUI struct { Window *opengl.Window Camera *Camera Spritesheet *Spritesheet BarSprite *pixel.Sprite OffsetX float64 OffsetY float64 Scale float64 Health float64 HealthBarPosition pixel.Vec HealthBarImage *image.RGBA HealthBarSprite *pixel.Sprite Hunger float64 HungerBarPosition pixel.Vec HungerBarImage *image.RGBA HungerBarSprite *pixel.Sprite Thirst float64 ThirstBarPosition pixel.Vec ThirstBarImage *image.RGBA ThirstBarSprite *pixel.Sprite BigSprite *pixel.Sprite BigOffset pixel.Vec ItemSprite *pixel.Sprite NeedsRedraw bool HotbarItems []*InventoryItem HotbarX int HotbarSelectionSprite *pixel.Sprite Inventory [][]*InventoryItem ShouldDrawInventory bool Tiles map[byte]map[byte]*pixel.Sprite HoldingInvItem *InventoryItem CraftingSlots [][]*InventoryItem }
func (*GUI) ButtonCallback ¶
func (g *GUI) ButtonCallback(btn pixel.Button, action pixel.Action)
func (*GUI) ClearCraftingItems ¶
func (g *GUI) ClearCraftingItems()
func (*GUI) DrawHotbar ¶
func (g *GUI) DrawHotbar()
func (*GUI) DrawInventory ¶
func (g *GUI) DrawInventory()
func (*GUI) HandleCraftingSlotLeftClick ¶
func (*GUI) HandleCraftingSlotRightClick ¶
func (*GUI) HandleDeleteItemLeftClick ¶
func (*GUI) HandleInventoryLeftClick ¶
func (*GUI) HandleInventoryRightClick ¶
func (*GUI) RedrawBars ¶
func (g *GUI) RedrawBars()
func (*GUI) SetHotbarItems ¶
func (g *GUI) SetHotbarItems(items []*InventoryItem, hotbarX int)
func (*GUI) SetInventoryItems ¶
func (g *GUI) SetInventoryItems(items [][]*InventoryItem)
func (*GUI) UpdateHealth ¶
func (*GUI) UpdateHunger ¶
func (*GUI) UpdateThirst ¶
type Game ¶
type Game struct { Map *Map Player *Player CollideablesDrawDebug bool GUI *GUI Window *opengl.Window Camera *Camera }
func (*Game) ButtonCallback ¶
func (g *Game) ButtonCallback(btn pixel.Button, action pixel.Action)
func (*Game) CharCallback ¶
func (*Game) CheckCollisions ¶
func (g *Game) CheckCollisions()
type InventoryItem ¶
type InventoryItem struct { UnderlyingType byte ItemType byte Frame byte Amount int InventoryPosition pixel.Vec DrawPosition pixel.Vec ShouldUseDrawPosition bool Count *text.Text Font font.Face Atlas *text.Atlas }
func NewInventoryItem ¶
func NewInventoryItem(underType, itemType, frame byte, amt int, inventoryPos pixel.Vec) *InventoryItem
func (*InventoryItem) Draw ¶
func (i *InventoryItem) Draw(win *opengl.Window)
func (*InventoryItem) DrawCraftingItem ¶
func (i *InventoryItem) DrawCraftingItem(win *opengl.Window, scale float64)
func (*InventoryItem) GetCraftingPosition ¶
func (i *InventoryItem) GetCraftingPosition(win *opengl.Window, scale float64) pixel.Vec
func (*InventoryItem) GetDrawPosition ¶
func (i *InventoryItem) GetDrawPosition(win *opengl.Window) pixel.Vec
type Map ¶
type Map struct { Name string Chunks map[int]map[int]*Chunk Spritesheets map[string]*Spritesheet FloorBatch *pixel.Batch // the holder for batch drawing TreeBatchBottom *pixel.Batch TreeBatchTop *pixel.Batch DrawRadius float64 // how many chunks around the current center chunk should be drawn ChunkPosition pixel.Vec // the current center chunk }
func (*Map) BlockExists ¶
func (*Map) GenerateAllDirtChunk ¶
func (*Map) GenerateChunksAroundPlayer ¶
func (*Map) RefreshDrawBatch ¶
func (m *Map) RefreshDrawBatch()
RefreshDrawBatch loads the chunks around the maps center chunk using
type Player ¶
type Player struct { Position pixel.Vec OldPosition pixel.Vec Speed map[byte]float64 // pixels per second WalkingOrRunning byte Spritesheet *Spritesheet Frames map[byte][]*pixel.Sprite SwingFrames map[byte][]*pixel.Sprite FrameSpeed map[byte]float64 Inventory [][]*InventoryItem InventoryW int InventoryH int HotbarX int ShouldDrawInventory bool CurrentFrame float64 MaxMovementFrame float64 MovementDirection byte MovementDirections []byte Solid bool DebugRect *pixel.Sprite IsSwinging bool SwingFrameSpeed float64 InInventory bool MouseX int // block position from bottom left MouseY int // block position from bottom left MouseRectImage *image.RGBA MouseRectSprite *pixel.Sprite MaxPlaceDistance float64 }
func (*Player) AddInventoryItem ¶
func (p *Player) AddInventoryItem(i *InventoryItem)
func (*Player) AddItemToInventory ¶
func (*Player) AddMovementDirection ¶
func (*Player) ButtonCallback ¶
func (*Player) CharCallback ¶
func (*Player) ClearInventory ¶
func (p *Player) ClearInventory()
func (*Player) Collide ¶
func (p *Player) Collide(c Collideable)
func (*Player) GetBlockPosition ¶
func (*Player) GetChunkPosition ¶
func (p *Player) GetChunkPosition() pixel.Vec
func (*Player) GetHeldItem ¶
func (p *Player) GetHeldItem() *InventoryItem
func (*Player) GetMouseMapBlockCoords ¶
func (*Player) GetMouseMapBlockPosition ¶
Returns the X and Y coordinates for the block the mouse is over on the map
func (*Player) GetMouseMapPosition ¶
func (*Player) GetOldPosition ¶
func (p *Player) GetOldPosition() pixel.Vec
func (*Player) GetPosition ¶
func (p *Player) GetPosition() pixel.Vec
func (*Player) HandleRightClick ¶
func (*Player) IsMovingInDirection ¶
func (*Player) PlaceBlock ¶
func (p *Player) PlaceBlock(game *Game, item *InventoryItem)
func (*Player) RemoveInventoryItem ¶
func (p *Player) RemoveInventoryItem(i *InventoryItem)
func (*Player) RemoveMovementDirection ¶
func (*Player) ThrowInventoryItem ¶
type Spritesheet ¶
type Spritesheet struct { Path string Picture pixel.Picture }
func NewSpritesheet ¶
func NewSpritesheet(path string) (*Spritesheet, error)
Click to show internal directories.
Click to hide internal directories.