rotato
This commit is contained in:
parent
88fa4f5a6e
commit
8b076efcc4
2 changed files with 14 additions and 5 deletions
|
@ -11,18 +11,22 @@ type Camera struct {
|
|||
Scene *Scene
|
||||
|
||||
// camera controls
|
||||
Zoom float64
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue