cr1ckt

package
v0.0.0-...-499239b Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JumpPressNone int = iota
	JumpPressLeft
	JumpPressRight
	JumpPressCancel
)

JumpPress are the different jump states for controls

View Source
const LayerAuto int = 1

LayerAuto is the layer to check for auto-tile collisions

View Source
const LayerEntities int = 0

LayerEntities is the layer to use for entity positions

View Source
const LayerTile int = 2

LayerTile is the layer to check for tile collisions

Variables

View Source
var BlacknessFactor int = 10

BlacknessFactor sets after how many jumps the amount of blackness that's added per jump should be doubled

View Source
var DebugMode bool = false

DebugMode sets whether to display additional debugging info on the screen during playing the game or not

View Source
var MaxPrime int = 5

MaxPrime is the maximum jump level (after division) you can prime the cricket to jump for, it avoids you jumping off the screen

View Source
var MinPrime int = 1

MinPrime is the minimum jump level (after division) you can prime the cricket to jump for, it ensures you jump somewhat even just for a short tap

View Source
var TileSquishy = []int{
	9, 41, 73,
	13, 45, 77,
	15, 47, 79,
	19, 20,
}

TileSquishy is a list of tiles you should move on top of when you them

View Source
var TilesImpassible = []int{
	0, 1, 32, 64, 65,
	17, 21, 81, 85,
	128,
	194, 256, 260, 322,
}

TilesImpassible is a list of tiles you can't pass through while jumping

View Source
var TilesWater = []int{18, 19, 20, 82, 83, 84, 114, 145, 156, 146}

TilesWater is a list of tiles that should behave like water

View Source
var VelocityDenominator int = 10

VelocityDenominator is by how much to divide the time the jump was primed to get the jump velocity

View Source
var VelocityXMultiplier int = 2

VelocityXMultiplier is by how much to multiply the Y velocity to get the velocity for the X axis, it's usually bigger

Functions

func ApplyConfigs

func ApplyConfigs()

ApplyConfigs overrides default values with a config file if available

func Collides

func Collides(g *Game) *ldtkgo.Tile

Collides checks whether the Cricket is colliding with a tile

func Impassible

func Impassible(tile *ldtkgo.Tile) bool

Impassible checks whether a tile is impassible (true) or passible (false)

func LoadImage

func LoadImage(name string) *ebiten.Image

LoadImage loads an ebiten.Image given the name of a file in the embedded fs

func NewGame

func NewGame(game *Game)

NewGame populates a default game object with game data

func OverlapsTiles

func OverlapsTiles(ts []*ldtkgo.Tile, hitbox image.Rectangle, gridSize int) *ldtkgo.Tile

OverlapsTiles checks for collisions on a given layer This inner function is a workaround because we need to loop through both Tiles and AutoTiles in exactly the same way

func Squishy

func Squishy(tile *ldtkgo.Tile) bool

Squishy checks whether a tile is squishy (true) or hard (false)

Types

type Blackness

type Blackness map[image.Point]bool

Blackness is a map to store where black squares should appear on the camera

func (Blackness) Has

func (b Blackness) Has(v image.Point) bool

Has is a convenience function to check if a point on the camera is already black, it can be used in-line because it only returns one value

type Cricket

type Cricket struct {
	*Object

	Position      image.Point
	Velocity      image.Point
	Jumping       bool
	PrimeDuration int
	Direction     int
	Frame         int
	Width         int
	State         CricketState
	// contains filtered or unexported fields
}

Cricket is a small, jumping insect, the main character of the game

func NewCricket

func NewCricket(cricketPos []int) *Cricket

NewCricket returns a new Cricket object at the given position

func (*Cricket) Hitbox

func (c *Cricket) Hitbox() image.Rectangle

Hitbox returns a correctly positioned rectangular hitbox for collision detection with the Cricket

type CricketState

type CricketState int

CricketState are the different animation states a Cricket can be in

const (
	// Idle is the animation state when the Cricket is not moving
	Idle CricketState = iota
	// Jumping is the animation state on the way up
	Jumping
	// Landing is the animation state on the way down
	Landing
)

type EmbedLoader

type EmbedLoader struct {
	BasePath string
}

EmbedLoader is a TilesetLoader for the embedded FS

func (*EmbedLoader) LoadTileset

func (l *EmbedLoader) LoadTileset(tileSetPath string) *ebiten.Image

LoadTileset loads an LDtk tileset image from the embedded FS

type Game

type Game struct {
	Width        int
	Height       int
	Cricket      *Cricket
	Wait         int
	WaitTime     int
	TileRenderer *TileRenderer
	LDTKProject  *ldtkgo.Project
	Level        int
	Loading      bool
	// contains filtered or unexported fields
}

Game represents the main game state

func (*Game) Draw

func (g *Game) Draw(screen *ebiten.Image)

Draw handles rendering the sprites

func (*Game) EntityByIdentifier

func (g *Game) EntityByIdentifier(identifier string) *ldtkgo.Entity

EntityByIdentifier is a convenience function for the same thing in ldtkgo but defaulting to checking the Entities layer of the current level

func (*Game) Layout

func (g *Game) Layout(outsideWidth int, outsideHeight int) (screenWidth int, screenHeight int)

Layout is hardcoded for now, may be made dynamic in future

func (*Game) Reset

func (g *Game) Reset(level int)

Reset resets the game level and cricket states to defaults for a provided game level

func (*Game) Update

func (g *Game) Update() error

Update calculates game logic

type Object

type Object struct {
	Image  *ebiten.Image
	Op     *ebiten.DrawImageOptions
	Center image.Point
}

An Object is something that can be seen and positioned in the game

func NewObjectFromImage

func NewObjectFromImage(img *ebiten.Image) *Object

NewObjectFromImage makes a new game Object with fields calculated from an already loaded image

type RenderedLayer

type RenderedLayer struct {
	Image *ebiten.Image // The image that was rendered out
	Layer *ldtkgo.Layer // The layer used to render the image
}

RenderedLayer represents an LDtk.Layer that was rendered out to an *ebiten.Image.

type TileRenderer

type TileRenderer struct {
	Tilesets       map[string]*ebiten.Image
	CurrentTileset string
	RenderedLayers []*RenderedLayer
	Loader         TilesetLoader // Loader for the renderer; defaults to a DiskLoader instance, though this can be switched out with something else as necessary.
}

TileRenderer is a struct that renders LDtk levels to *ebiten.Images.

func NewTileRenderer

func NewTileRenderer(loader TilesetLoader) *TileRenderer

NewTileRenderer creates a new Renderer instance. TilesetLoader should be an instance of a struct designed to return *ebiten.Images for each Tileset requested (by path relative to the LDtk project file).

func (*TileRenderer) Clear

func (er *TileRenderer) Clear()

Clear clears the renderer's Result.

func (*TileRenderer) Render

func (er *TileRenderer) Render(level *ldtkgo.Level)

Render clears, and then renders out each visible Layer in an ldtgo.Level instance.

type TilesetLoader

type TilesetLoader interface {
	LoadTileset(string) *ebiten.Image
}

TilesetLoader represents an interface that can be implemented to load a tileset from string, returning an *ebiten.Image.

type WinScreen

type WinScreen int

WinScreen is the screen that's displayed when you win the game

func (WinScreen) Draw

func (w WinScreen) Draw(g *Game, screen *ebiten.Image)

Draw draws the win screen to a provided image

Jump to

Keyboard shortcuts

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