From e3e84b4f2336e3b2f515a39db6f3885b877108b1 Mon Sep 17 00:00:00 2001 From: surdeus Date: Sat, 18 Feb 2023 15:26:54 +0500 Subject: [PATCH] Added more hotkeys for testing in the example. --- src/cmd/test/main.go | 18 ++++++++++++++++-- src/gx/keys.go | 10 ++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/cmd/test/main.go b/src/cmd/test/main.go index 5716ff4..b318d4f 100644 --- a/src/cmd/test/main.go +++ b/src/cmd/test/main.go @@ -12,6 +12,7 @@ import ( type Player struct { *gx.Sprite MoveSpeed gx.Float + ScaleSpeed gx.Float } type Debug struct{} @@ -33,6 +34,7 @@ func NewPlayer() *Player { Image: playerImg, }, MoveSpeed: 90., + ScaleSpeed: .2, } } @@ -59,9 +61,21 @@ func (p *Player) Update(e *gx.Engine) error { case ebiten.KeyD : p.Object.T.P.X += p.MoveSpeed * dt case ebiten.KeyR : - c.Object.T.R += gx.Pi * .3 * dt + c.Object.T.R += gx.Pi * p.ScaleSpeed * dt case ebiten.KeyT : - c.Object.T.R -= gx.Pi * .3 * dt + c.Object.T.R -= gx.Pi * p.ScaleSpeed * dt + case ebiten.KeyF : + if e.KeyIsPressed(ebiten.KeyShift) { + c.Object.T.S.X -= gx.Pi * p.ScaleSpeed * dt + } else { + c.Object.T.S.X += gx.Pi * p.ScaleSpeed * dt + } + case ebiten.KeyG : + if e.KeyIsPressed(ebiten.KeyShift) { + c.Object.T.S.Y -= gx.Pi * p.ScaleSpeed * dt + } else { + c.Object.T.S.Y += gx.Pi * p.ScaleSpeed * dt + } }} return nil diff --git a/src/gx/keys.go b/src/gx/keys.go index bcfce50..3694b50 100644 --- a/src/gx/keys.go +++ b/src/gx/keys.go @@ -6,3 +6,13 @@ import ( type Key = ebiten.Key +func (e *Engine) KeyIsPressed(k Key) bool { + keys := e.Keys() + for _, v := range keys { + if v == k { + return true + } + } + + return false +}