ichigo/engine/interface.go

52 lines
1.5 KiB
Go
Raw Normal View History

2021-08-05 12:26:41 +10:00
package engine
2021-08-05 12:33:23 +10:00
import (
"image"
"github.com/hajimehoshi/ebiten/v2"
)
// Collider components have tangible form.
type Collider interface {
CollidesWith(image.Rectangle) bool
}
2021-08-05 12:26:41 +10:00
// Drawer components can draw themselves. Draw is called often.
2021-08-05 12:40:32 +10:00
// Each component is responsible for calling Draw on its child components
// (so that hiding the parent can hide the children, etc).
2021-08-05 12:26:41 +10:00
type Drawer interface {
2021-08-12 14:06:01 +10:00
Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions)
2021-08-05 12:26:41 +10:00
}
// Identifier components have a sense of self. This makes it easier for
// components to find and interact with one another.
type Identifier interface {
Ident() string
}
// Prepper components can be prepared. It is called after the component
// database has been populated but before the game is run. The component can
// store the reference to game, if needed, and also query the component database.
type Prepper interface {
Prepare(game *Game)
}
// Scanner components can be scanned. It is called when the game tree is walked
// (such as when the game component database is constructed).
// Scan should return a slice containing all immediate subcomponents.
type Scanner interface {
Scan() []interface{}
}
// Updater components can update themselves. Update is called repeatedly.
2021-08-05 12:40:32 +10:00
// Each component is responsible for calling Update on its child components
// (so that disabling the parent prevents updates to the children, etc).
2021-08-05 12:26:41 +10:00
type Updater interface {
Update() error
}
// ZPositioner is used to reorder layers.
type ZPositioner interface {
Z() float64
}