Run the "start" function on adding objects.

This commit is contained in:
Andrey Parhomenko 2023-02-18 18:57:37 +05:00
parent 02a6cc3e88
commit e03c1479e2
3 changed files with 9 additions and 0 deletions

View file

@ -38,6 +38,8 @@ func NewPlayer() *Player {
}
func (p *Player) Start(e *gx.Engine) {
c := e.Camera()
c.Object.T.RA = gx.V(360, -120)
}
func (p *Player) Update(e *gx.Engine) error {
@ -84,12 +86,14 @@ func (p *Player) Update(e *gx.Engine) error {
} else {
c.Object.T.RA.X += gx.Pi * p.MoveSpeed * dt
}
log.Println(c.Object.T.RA.X)
case ebiten.KeyX :
if e.KeyIsPressed(ebiten.KeyShift) {
c.Object.T.RA.Y -= gx.Pi * p.MoveSpeed * dt
} else {
c.Object.T.RA.Y += gx.Pi * p.MoveSpeed * dt
}
log.Println(c.Object.T.RA.Y)
}}
return nil

View file

@ -66,6 +66,7 @@ func (e *Engine) Add(l Layer, b any) {
beh, ok := b.(Behaver)
if ok {
e.AddBehaver(beh)
beh.Start(e)
}
drw, ok := b.(Drawer)

View file

@ -18,6 +18,10 @@ type Transform struct {
R Float
}
func V(x, y Float) Vector {
return Vector{x, y}
}
func T() Transform {
ret := Transform{}
return ret