mechanics

package
v0.0.0-...-cbcac17 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CollisionTypeTraversable = iota - 1
	CollisionTypeWin
	CollisionTypeSolid
	CollisionTypeSolidHalfTop
	CollisionTypeSolidHalfBottom
	CollisionTypeRampUp
	CollisionTypeRampDown
	CollisionTypeDie
	CollisionTypeDieHalfTop
	CollisionTypeDieHalfBottom
	CollisionTypeStop

	ObjectTypeEnemy       = "enemy"
	ObjectTypeCollectable = "collectable"

	CollisionGroupTraversable = "traversable"
	CollisionGroupSolid       = "solid"
	CollisionGroupRamp        = "ramp"
	CollisionGroupDie         = "die"
	CollisionGroupStopper     = "stopper"
	CollisionGroupWin         = "win"
)
View Source
const (
	MoverDirectionRight = iota
	MoverDirectionLeft
)

Variables

View Source
var (
	ErrDestroy = errors.New("object is destroyed")
)

Functions

func PositionInTiles

func PositionInTiles(x, y int, tileSize, width, height float64) (int32, int32)

Types

type CharState

type CharState uint8
const (
	CharStateStand CharState = iota
	CharStateWalk
	CharStateJump
	CharStateAir
	CharStateFall
	CharStateRun
	CharStateCollide
	CharStateDead
)

type Character

type Character struct {
	*Mover

	Scale float64

	Image        *ebiten.Image
	SpriteWidth  int
	SpriteHeight int

	JumpPlayer *audio.Player
	HurtPlayer *audio.Player

	State CharState

	IsDead bool
	// contains filtered or unexported fields
}

func NewCharacter

func NewCharacter(image *ebiten.Image, jumpPlayer, hurtPlayer *audio.Player, spriteWidth, spriteHeight int, scale float64, animations map[CharState][]int) *Character

func (*Character) Die

func (c *Character) Die()

func (*Character) Draw

func (c *Character) Draw(screen *ebiten.Image)

func (*Character) Jump

func (c *Character) Jump()

func (*Character) Update

func (c *Character) Update(collisions *resolv.Space) (int32, int32)

type Chest

type Chest struct {
	resolv.Shape
	// contains filtered or unexported fields
}

func NewChest

func NewChest(sprite *ebiten.Image, scale float64, spriteWidth, spriteHeight int, animations [3][]int) *Chest

func (*Chest) Draw

func (c *Chest) Draw(screen *ebiten.Image)

func (*Chest) Height

func (c *Chest) Height() float64

func (*Chest) Update

func (c *Chest) Update(char *Character, collisions *resolv.Space) error

func (*Chest) Width

func (c *Chest) Width() float64

type Collectable

type Collectable struct {
	resolv.Shape
	// contains filtered or unexported fields
}

func NewCollectable

func NewCollectable(typ int, sprite *ebiten.Image, scale float64, spriteWidth, spriteHeight int, animation []int) *Collectable

func (*Collectable) Draw

func (c *Collectable) Draw(screen *ebiten.Image)

func (*Collectable) Height

func (c *Collectable) Height() float64

func (*Collectable) Type

func (c *Collectable) Type() int

func (*Collectable) Update

func (c *Collectable) Update(char *Character, _ *resolv.Space) error

func (*Collectable) Width

func (c *Collectable) Width() float64

type CollisionMap

type CollisionMap struct {
	Map IntMap
}

type Enemy

type Enemy struct {
	*Mover
	// contains filtered or unexported fields
}

func NewEnemy

func NewEnemy(typ int, sprite *ebiten.Image, scale float64, spriteWidth, spriteHeight int, animation []int) *Enemy

func (*Enemy) Draw

func (e *Enemy) Draw(screen *ebiten.Image)

func (*Enemy) Height

func (e *Enemy) Height() float64

func (*Enemy) Type

func (e *Enemy) Type() int

func (*Enemy) Update

func (e *Enemy) Update(char *Character, collisions *resolv.Space) error

func (*Enemy) Width

func (e *Enemy) Width() float64

type Game

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

func NewGame

func NewGame(title, level, gameover, credits, quit Scene) *Game

func (*Game) Draw

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

func (*Game) Layout

func (m *Game) Layout(outsideWidth int, outsideHeight int) (int, int)

func (*Game) Update

func (m *Game) Update() error

type IntMap

type IntMap [][]int

type Layer

type Layer struct {
	Map         IntMap
	TilesSprite *ebiten.Image
	TilesPerRow int
}

func (*Layer) Draw

func (l *Layer) Draw(screen *ebiten.Image, tileSize int, offsetX, offsetY float64)

type Level

type Level struct {
	TileSize     int
	Back         []*Layer
	Front        []*Layer
	CollisionMap *CollisionMap
	EnemiesMap   IntMap
	ObjectsMap   IntMap
	// contains filtered or unexported fields
}

func (*Level) CollisionSpace

func (l *Level) CollisionSpace() resolv.Space

func (*Level) Draw

func (l *Level) Draw(screen *ebiten.Image, drawChar func(*ebiten.Image), objects resolv.Space)

func (*Level) Objects

func (l *Level) Objects() resolv.Space

func (*Level) SetCamera

func (l *Level) SetCamera(x, y int32)

func (*Level) SetObjectProvider

func (l *Level) SetObjectProvider(provider ObjectProvider)

type Mover

type Mover struct {
	resolv.Shape
	Vx        float64
	Vy        float64
	Gravity   float64
	Direction MoverDirection
	// contains filtered or unexported fields
}

func (*Mover) CollideMove

func (m *Mover) CollideMove(collisions *resolv.Space) (int32, int32)

type MoverDirection

type MoverDirection int

type Object

type Object interface {
	resolv.Shape
	Draw(screen *ebiten.Image)
	Update(char *Character, collisions *resolv.Space) error
	Width() float64
	Height() float64
}

type ObjectProvider

type ObjectProvider interface {
	CreateEnemy(typ int) *Enemy
	CreateObject(typ int) Object
}

type Scene

type Scene interface {
	Update() (SceneType, error)
	Draw(screen *ebiten.Image)
	Layout(outsideWidth int, outsideHeight int) (int, int)
	Init()
}

type SceneType

type SceneType int
const (
	SceneTypeTitle SceneType = iota
	SceneTypeLevel
	SceneTypeGameOver
	SceneTypeCredits
	SceneTypeQuit
)

Jump to

Keyboard shortcuts

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