28 lines
529 B
Go
28 lines
529 B
Go
//go:build example
|
|
// +build example
|
|
|
|
package component
|
|
|
|
import (
|
|
"code.rocketnine.space/tslocum/gohan"
|
|
"code.rocketnine.space/tslocum/gohan/examples/twinstick/world"
|
|
)
|
|
|
|
type PositionComponent struct {
|
|
X, Y float64
|
|
}
|
|
|
|
var PositionComponentID = world.World.NewComponentID()
|
|
|
|
func (p *PositionComponent) ComponentID() gohan.ComponentID {
|
|
return PositionComponentID
|
|
}
|
|
|
|
func Position(ctx *gohan.Context) *PositionComponent {
|
|
c, ok := ctx.Component(PositionComponentID).(*PositionComponent)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return c
|
|
}
|