From 8b076efcc4e08613e69f4bbfb469912a0c089d6a Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Tue, 10 Aug 2021 15:23:13 +1000 Subject: [PATCH] rotato --- engine/camera.go | 14 +++++++++----- game/aw.go | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/engine/camera.go b/engine/camera.go index 6ca75b6..459cb31 100644 --- a/engine/camera.go +++ b/engine/camera.go @@ -11,18 +11,22 @@ type Camera struct { Scene *Scene // camera controls - Zoom float64 - Centre image.Point + Centre image.Point + Rotation float64 + Zoom float64 game *Game // TODO: camera constraints } func (c *Camera) Draw(screen *ebiten.Image, geom ebiten.GeoM) { - //geom.Concat(*c.Transform.GeoM()) - scx, scy := float64(c.game.ScreenWidth/2), float64(c.game.ScreenHeight/2) - geom.Translate((scx/c.Zoom - float64(c.Centre.X)), (scy/c.Zoom - float64(c.Centre.Y))) + // move the c.Centre to the origin + geom.Translate(-float64(c.Centre.X), -float64(c.Centre.Y)) + // zoom and rotate geom.Scale(c.Zoom, c.Zoom) + geom.Rotate(c.Rotation) + // move the origin to the centre of screen space + geom.Translate(float64(c.game.ScreenWidth/2), float64(c.game.ScreenHeight/2)) c.Scene.Draw(screen, geom) } diff --git a/game/aw.go b/game/aw.go index 7a4b0b6..072860d 100644 --- a/game/aw.go +++ b/game/aw.go @@ -3,6 +3,7 @@ package game import ( "encoding/gob" "image" + "math" "drjosh.dev/gurgle/engine" "github.com/hajimehoshi/ebiten/v2" @@ -71,8 +72,12 @@ func (aw *Awakeman) Update() error { if ebiten.IsKeyPressed(ebiten.KeyShift) { aw.camera.Zoom = 2 } + if inpututil.IsKeyJustPressed(ebiten.KeyR) { + aw.camera.Rotation += math.Pi / 6 + } aw.MoveX(aw.vx, func() { aw.vx = -aw.vx * bounceDampen }) aw.MoveY(aw.vy, func() { aw.vy = -aw.vy * bounceDampen }) + // aw.Pos is top-left corner, so add half size to get centre aw.camera.Centre = aw.Pos.Add(aw.Size.Div(2)) return aw.Sprite.Update() }