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) { 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 { func (p *Player) Update(e *gx.Engine) error {
@ -84,12 +86,14 @@ func (p *Player) Update(e *gx.Engine) error {
} else { } else {
c.Object.T.RA.X += gx.Pi * p.MoveSpeed * dt c.Object.T.RA.X += gx.Pi * p.MoveSpeed * dt
} }
log.Println(c.Object.T.RA.X)
case ebiten.KeyX : case ebiten.KeyX :
if e.KeyIsPressed(ebiten.KeyShift) { if e.KeyIsPressed(ebiten.KeyShift) {
c.Object.T.RA.Y -= gx.Pi * p.MoveSpeed * dt c.Object.T.RA.Y -= gx.Pi * p.MoveSpeed * dt
} else { } else {
c.Object.T.RA.Y += gx.Pi * p.MoveSpeed * dt c.Object.T.RA.Y += gx.Pi * p.MoveSpeed * dt
} }
log.Println(c.Object.T.RA.Y)
}} }}
return nil return nil

View file

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

View file

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