2023-09-17 13:34:03 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
_ "embed"
|
|
|
|
|
"image"
|
|
|
|
|
_ "image/png"
|
|
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
FLAME_ANIMATION_CYCLES = 8
|
|
|
|
|
FLAME_WIDTH = 24
|
|
|
|
|
FLAME_HEIGHT = 32
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
//go:embed resources/images/hot.png
|
|
|
|
|
flameAssets_png []byte
|
|
|
|
|
assetsFlame *ebiten.Image
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Flame struct {
|
|
|
|
|
Sprite *ebiten.Image //our principle sprite representing the flame
|
|
|
|
|
cycle int //current animation cycle for the character
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewFlame() *Flame {
|
|
|
|
|
return &Flame{
|
|
|
|
|
cycle: 0,
|
|
|
|
|
Sprite: ebiten.NewImage(FLAME_WIDTH, FLAME_HEIGHT),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (f *Flame) CycleUpdate() {
|
|
|
|
|
f.cycle = (f.cycle + 1) % CHARACTER_ANIMATION_CYCLES
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (f *Flame) Animate() {
|
|
|
|
|
|
|
|
|
|
//compute start and end location of asset to use for animation frame cycle
|
|
|
|
|
sx := FLAME_WIDTH * f.cycle
|
|
|
|
|
sy := 0
|
|
|
|
|
ex := FLAME_WIDTH * (f.cycle + 1)
|
|
|
|
|
ey := FLAME_HEIGHT
|
|
|
|
|
|
|
|
|
|
f.Sprite.Clear()
|
|
|
|
|
f.Sprite.DrawImage(assetsFlame.SubImage(image.Rect(sx, sy, ex, ey)).(*ebiten.Image), nil)
|
|
|
|
|
|
|
|
|
|
f.CycleUpdate()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (f *Flame) GetWidth() int {
|
|
|
|
|
return f.Sprite.Bounds().Dx()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (f *Flame) GetHeight() int {
|
|
|
|
|
return f.Sprite.Bounds().Dy()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
img, _, err := image.Decode(bytes.NewReader(flameAssets_png))
|
|
|
|
|
if err != nil {
|
2023-10-02 14:38:49 -04:00
|
|
|
DashLogger.Fatal(err)
|
2023-09-17 13:34:03 -04:00
|
|
|
}
|
|
|
|
|
assetsFlame = ebiten.NewImageFromImage(img)
|
|
|
|
|
}
|