added hidden doors/destroyable walls, fixed game reloading (tile clone)

This commit is contained in:
2024-02-25 14:05:44 +01:00
parent ab07bc23e3
commit b0a8060d5b
15 changed files with 271 additions and 39 deletions

29
components/destroyable.go Normal file
View File

@@ -0,0 +1,29 @@
package components
import (
"log"
"github.com/hajimehoshi/ebiten/v2"
)
// A hidden door in a wall. If the player bumps into it once, it shows
// damage and it vanishes the next time.
type Destroyable struct {
Activated bool
Sprites []*ebiten.Image
Current int // sprite index
}
func (door *Destroyable) GetNext() *ebiten.Image {
if len(door.Sprites) > door.Current {
door.Current++
return door.Sprites[door.Current]
}
log.Fatalf("not enough sprites in transient tile, have %d sprites, index requested: %d",
len(door.Sprites), door.Current+1,
)
return nil
}