more wrappers around bool values
This commit is contained in:
parent
94db859faf
commit
1d3327cb1c
8 changed files with 42 additions and 9 deletions
|
@ -11,10 +11,10 @@ var _ Drawer = &Fill{}
|
||||||
|
|
||||||
// Fill fills the screen with a colour.
|
// Fill fills the screen with a colour.
|
||||||
type Fill struct {
|
type Fill struct {
|
||||||
Color color.Color
|
|
||||||
ZOrder
|
|
||||||
Hidden bool
|
|
||||||
ID
|
ID
|
||||||
|
Color color.Color
|
||||||
|
Hidden
|
||||||
|
ZOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fill) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
func (f *Fill) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ func init() {
|
||||||
// Image draws an image at a position.
|
// Image draws an image at a position.
|
||||||
type Image struct {
|
type Image struct {
|
||||||
ID
|
ID
|
||||||
|
Hidden
|
||||||
Parallax
|
Parallax
|
||||||
Pos image.Point
|
Pos image.Point
|
||||||
Src ImageRef
|
Src ImageRef
|
||||||
|
@ -31,6 +32,9 @@ type Image struct {
|
||||||
|
|
||||||
// Draw draws the image.
|
// Draw draws the image.
|
||||||
func (i *Image) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
func (i *Image) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
||||||
|
if i.Hidden {
|
||||||
|
return
|
||||||
|
}
|
||||||
var geom ebiten.GeoM
|
var geom ebiten.GeoM
|
||||||
geom.Translate(float64(i.Pos.X), float64(i.Pos.Y))
|
geom.Translate(float64(i.Pos.X), float64(i.Pos.Y))
|
||||||
geom.Concat(opts.GeoM)
|
geom.Concat(opts.GeoM)
|
||||||
|
|
|
@ -17,6 +17,13 @@ type Collider interface {
|
||||||
CollidesWith(image.Rectangle) bool
|
CollidesWith(image.Rectangle) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disabler components can be disabled.
|
||||||
|
type Disabler interface {
|
||||||
|
IsDisabled() bool
|
||||||
|
Disable()
|
||||||
|
Enable()
|
||||||
|
}
|
||||||
|
|
||||||
// Drawer components can draw themselves. Draw is called often.
|
// Drawer components can draw themselves. Draw is called often.
|
||||||
// Each component is responsible for calling Draw on its child components
|
// Each component is responsible for calling Draw on its child components
|
||||||
// (so that hiding the parent can hide the children, etc).
|
// (so that hiding the parent can hide the children, etc).
|
||||||
|
@ -88,6 +95,7 @@ type Scener interface {
|
||||||
// It seems cleaner to let the engine assert only for the interface it needs at that moment.
|
// It seems cleaner to let the engine assert only for the interface it needs at that moment.
|
||||||
|
|
||||||
Bounder
|
Bounder
|
||||||
|
Disabler
|
||||||
Drawer
|
Drawer
|
||||||
DrawOrderer
|
DrawOrderer
|
||||||
Hider
|
Hider
|
||||||
|
|
|
@ -14,6 +14,18 @@ type Bounds image.Rectangle
|
||||||
// BoundingRect returns b as an image.Rectangle.
|
// BoundingRect returns b as an image.Rectangle.
|
||||||
func (b Bounds) BoundingRect() image.Rectangle { return image.Rectangle(b) }
|
func (b Bounds) BoundingRect() image.Rectangle { return image.Rectangle(b) }
|
||||||
|
|
||||||
|
// Disabled implements Disabler directly (as a bool).
|
||||||
|
type Disabled bool
|
||||||
|
|
||||||
|
// IsHidden returns h as a bool.
|
||||||
|
func (d Disabled) IsDisabled() bool { return bool(d) }
|
||||||
|
|
||||||
|
// Hide sets h to true.
|
||||||
|
func (d *Disabled) Disable() { *d = true }
|
||||||
|
|
||||||
|
// Show sets h to false.
|
||||||
|
func (d *Disabled) Enable() { *d = false }
|
||||||
|
|
||||||
// Hidden implements Hider directly (as a bool).
|
// Hidden implements Hider directly (as a bool).
|
||||||
type Hidden bool
|
type Hidden bool
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ type Scene struct {
|
||||||
ID
|
ID
|
||||||
Bounds // world coordinates
|
Bounds // world coordinates
|
||||||
Components []interface{}
|
Components []interface{}
|
||||||
Disabled bool
|
Disabled
|
||||||
Hidden
|
Hidden
|
||||||
ZOrder
|
ZOrder
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,15 @@ func (r *SceneRef) Load(assets fs.FS) error {
|
||||||
// BoundingRect returns the Bounds from the scene.
|
// BoundingRect returns the Bounds from the scene.
|
||||||
func (r SceneRef) BoundingRect() image.Rectangle { return r.scene.BoundingRect() }
|
func (r SceneRef) BoundingRect() image.Rectangle { return r.scene.BoundingRect() }
|
||||||
|
|
||||||
|
// IsDisabled returns the value of IsDisabled from the scene.
|
||||||
|
func (r SceneRef) IsDisabled() bool { return r.scene.IsDisabled() }
|
||||||
|
|
||||||
|
// Disable calls Disable on the scene.
|
||||||
|
func (r SceneRef) Disable() { r.scene.Disable() }
|
||||||
|
|
||||||
|
// Enable calls Enable on the scene.
|
||||||
|
func (r SceneRef) Enable() { r.scene.Enable() }
|
||||||
|
|
||||||
// Draw draws the scene.
|
// Draw draws the scene.
|
||||||
func (r SceneRef) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
func (r SceneRef) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
||||||
r.scene.Draw(screen, opts)
|
r.scene.Draw(screen, opts)
|
||||||
|
|
|
@ -22,13 +22,13 @@ func init() {
|
||||||
|
|
||||||
// Sprite combines an Actor with the ability to Draw from a single spritesheet.
|
// Sprite combines an Actor with the ability to Draw from a single spritesheet.
|
||||||
type Sprite struct {
|
type Sprite struct {
|
||||||
|
ID
|
||||||
Actor
|
Actor
|
||||||
ZOrder
|
|
||||||
FrameSize image.Point
|
FrameSize image.Point
|
||||||
FrameOffset image.Point
|
FrameOffset image.Point
|
||||||
Hidden bool
|
Hidden
|
||||||
ID
|
|
||||||
Src ImageRef
|
Src ImageRef
|
||||||
|
ZOrder
|
||||||
|
|
||||||
anim *Anim
|
anim *Anim
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,14 @@ func init() {
|
||||||
// Tilemap renders a grid of tiles.
|
// Tilemap renders a grid of tiles.
|
||||||
type Tilemap struct {
|
type Tilemap struct {
|
||||||
ID
|
ID
|
||||||
Disabled bool
|
Disabled
|
||||||
ZOrder
|
|
||||||
Hidden
|
Hidden
|
||||||
Map map[image.Point]Tile
|
Map map[image.Point]Tile
|
||||||
Ersatz bool // "fake wall"
|
Ersatz bool // "fake wall"
|
||||||
Offset image.Point // world coordinates
|
Offset image.Point // world coordinates
|
||||||
Src ImageRef
|
Src ImageRef
|
||||||
TileSize int
|
TileSize int
|
||||||
|
ZOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
// CollidesWith implements Collider.
|
// CollidesWith implements Collider.
|
||||||
|
|
Loading…
Reference in a new issue