Cleanup, touchups, new death animation on hero.
This commit is contained in:
26
hero.go
26
hero.go
@@ -14,9 +14,13 @@ import (
|
||||
|
||||
var (
|
||||
heroImage *ebiten.Image
|
||||
heroDeath *ebiten.Image
|
||||
|
||||
//go:embed hero.png
|
||||
hero_img []byte
|
||||
|
||||
//go:embed herodeath.png
|
||||
herodeath_img []byte
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -36,6 +40,12 @@ func init() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
heroImage = ebiten.NewImageFromImage(img)
|
||||
|
||||
img, _, err = image.Decode(bytes.NewReader(herodeath_img))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
heroDeath = ebiten.NewImageFromImage(img)
|
||||
}
|
||||
|
||||
type Hero struct {
|
||||
@@ -98,6 +108,17 @@ func (m *Hero) Draw() {
|
||||
switch m.Action {
|
||||
case HeroActionDefault:
|
||||
m.Sprite.DrawImage(heroImage.SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), nil)
|
||||
case HeroActionDying:
|
||||
m.dyingcount++
|
||||
|
||||
m.Sprite.DrawImage(heroDeath.SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), nil)
|
||||
|
||||
if m.dyingcount > 60 {
|
||||
m.cycles = 0
|
||||
m.Action++
|
||||
}
|
||||
case HeroActionExploding:
|
||||
m.Sprite.DrawImage(heroDeath.SubImage(image.Rect(48*3, 0, 48*4, 48)).(*ebiten.Image), nil)
|
||||
default:
|
||||
}
|
||||
}
|
||||
@@ -106,8 +127,11 @@ func (m *Hero) Update() {
|
||||
m.cycles++
|
||||
}
|
||||
|
||||
// one hit death for the hero
|
||||
func (m *Hero) SetHit() {
|
||||
m.Action++ // = (m.Action + 1) % HeroActionMax
|
||||
m.Action = MoverActionDying
|
||||
m.Angle = 0
|
||||
m.cycles = 0
|
||||
}
|
||||
|
||||
func (m *Hero) ToggleColor() {
|
||||
|
||||
Reference in New Issue
Block a user