camera improvements
This commit is contained in:
parent
c43a1edb74
commit
a6508de705
2 changed files with 25 additions and 5 deletions
|
@ -26,7 +26,16 @@ func (c *Camera) Scan() []interface{} { return []interface{}{c.Scene} }
|
||||||
func (c *Camera) Prepare(game *Game) { c.game = game }
|
func (c *Camera) Prepare(game *Game) { c.game = game }
|
||||||
|
|
||||||
func (c *Camera) Centre(p image.Point) {
|
func (c *Camera) Centre(p image.Point) {
|
||||||
|
// Currently the centre of the screen c is A^-1.c in world coordinates
|
||||||
|
// So it is off by (p - A^-1.c)
|
||||||
t := c.Transform.GeoM()
|
t := c.Transform.GeoM()
|
||||||
t.Reset()
|
t.Invert()
|
||||||
t.Translate(float64(c.game.ScreenWidth/2-p.X), float64(c.game.ScreenHeight/2-p.Y))
|
wcx, wcy := t.Apply(float64(c.game.ScreenWidth/2), float64(c.game.ScreenHeight/2))
|
||||||
|
t.Translate(float64(p.X)-wcx, float64(p.Y)-wcy)
|
||||||
|
t.Invert()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Camera) Zoom(f float64) {
|
||||||
|
t := c.Transform.GeoM()
|
||||||
|
t.Scale(f, f)
|
||||||
}
|
}
|
||||||
|
|
17
game/aw.go
17
game/aw.go
|
@ -67,11 +67,22 @@ func (aw *Awakeman) Update() error {
|
||||||
aw.SetAnim(aw.animIdleLeft)
|
aw.SetAnim(aw.animIdleLeft)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
zc := false
|
||||||
|
if inpututil.IsKeyJustPressed(ebiten.KeyShift) {
|
||||||
|
aw.camera.Zoom(2)
|
||||||
|
zc = true
|
||||||
|
}
|
||||||
|
if inpututil.IsKeyJustReleased(ebiten.KeyShift) {
|
||||||
|
aw.camera.Zoom(0.5)
|
||||||
|
zc = true
|
||||||
|
}
|
||||||
|
|
||||||
|
p := aw.Pos
|
||||||
aw.MoveX(aw.vx, func() { aw.vx = -aw.vx * bounceDampen })
|
aw.MoveX(aw.vx, func() { aw.vx = -aw.vx * bounceDampen })
|
||||||
aw.MoveY(aw.vy, func() { aw.vy = -aw.vy * bounceDampen })
|
aw.MoveY(aw.vy, func() { aw.vy = -aw.vy * bounceDampen })
|
||||||
|
if zc || aw.Pos != p {
|
||||||
aw.camera.Centre(aw.Pos.Add(aw.Size.Div(2)))
|
aw.camera.Centre(aw.Pos.Add(aw.Size.Div(2)))
|
||||||
|
}
|
||||||
return aw.Sprite.Update()
|
return aw.Sprite.Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue