2021-08-08 22:07:55 +10:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2021-08-18 16:34:51 +10:00
|
|
|
"encoding/gob"
|
2021-08-08 22:07:55 +10:00
|
|
|
"image"
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
)
|
|
|
|
|
2021-08-18 16:34:51 +10:00
|
|
|
// Ensure Camera satisfies interfaces.
|
2021-08-27 11:49:11 +10:00
|
|
|
var _ interface {
|
|
|
|
Identifier
|
|
|
|
Prepper
|
|
|
|
} = &Camera{}
|
2021-08-18 16:34:51 +10:00
|
|
|
|
|
|
|
func init() {
|
2021-08-25 15:04:38 +10:00
|
|
|
gob.Register(&Camera{})
|
2021-08-18 16:34:51 +10:00
|
|
|
}
|
|
|
|
|
2021-08-28 18:07:53 +10:00
|
|
|
// Camera models a camera that is viewing a scene. (Camera is a child of the
|
|
|
|
// scene it is viewing, for various reasons.) Changes to the fields take effect
|
|
|
|
// immediately.
|
2021-08-08 22:07:55 +10:00
|
|
|
type Camera struct {
|
|
|
|
ID
|
2021-08-10 14:56:01 +10:00
|
|
|
|
2021-08-12 15:01:37 +10:00
|
|
|
// Camera controls
|
2021-08-20 13:45:01 +10:00
|
|
|
Centre image.Point // world coordinates
|
2021-08-12 14:16:09 +10:00
|
|
|
Filter ebiten.Filter
|
2021-08-18 15:41:03 +10:00
|
|
|
Zoom float64 // unitless
|
2021-08-12 14:06:01 +10:00
|
|
|
|
2021-08-18 15:23:02 +10:00
|
|
|
game *Game
|
2021-08-08 22:07:55 +10:00
|
|
|
}
|
|
|
|
|
2021-08-20 15:52:01 +10:00
|
|
|
// Prepare grabs a copy of game (needed for screen dimensions)
|
2021-08-27 14:52:24 +10:00
|
|
|
func (c *Camera) Prepare(game *Game) error {
|
|
|
|
c.game = game
|
|
|
|
return nil
|
|
|
|
}
|