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 VelocityComponent struct {
|
|
X, Y float64
|
|
}
|
|
|
|
var VelocityComponentID = world.World.NewComponentID()
|
|
|
|
func (c *VelocityComponent) ComponentID() gohan.ComponentID {
|
|
return VelocityComponentID
|
|
}
|
|
|
|
func Velocity(ctx *gohan.Context) *VelocityComponent {
|
|
c, ok := ctx.Component(VelocityComponentID).(*VelocityComponent)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return c
|
|
}
|