58 lines
1.2 KiB
Go
Raw Normal View History

2024-03-28 13:53:03 +01:00
package components
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/mlange-42/arche/ecs"
)
// the Bond components binds two different entities together, one
// manipulates the other
type Bond struct {
ecs.Relation
Id, Ref string
2024-03-28 13:53:03 +01:00
}
// A door has a relation to a switch using the Bond component. The
// Switch opens or closes the door, depending on player actions. The
// door itself is merely dump and just does what being told.
type Door struct {
IsOpen bool
OpenSprite *ebiten.Image
CloseSprite *ebiten.Image
Id string
2024-03-28 13:53:03 +01:00
}
func (door *Door) Toggle() {
door.IsOpen = !door.IsOpen
2024-03-28 13:53:03 +01:00
}
func (door *Door) Sprite() *ebiten.Image {
if door.IsOpen {
return door.OpenSprite
}
2024-03-28 13:53:03 +01:00
return door.CloseSprite
}
// the switch is being activated when the player runs over it, it can
// either use a timeout or just stay in its switching position
type Switch struct {
IsOpen bool
OpenSprite *ebiten.Image
CloseSprite *ebiten.Image
Ref string // the IId of the door
2024-03-28 13:53:03 +01:00
}
func (switcher *Switch) Toggle() {
switcher.IsOpen = !switcher.IsOpen
}
func (switcher *Switch) Sprite() *ebiten.Image {
if switcher.IsOpen {
return switcher.OpenSprite
}
return switcher.CloseSprite
}