Refactoring in explosion sounds.

This commit is contained in:
2024-11-15 16:46:20 -05:00
parent cbc4ba5eb3
commit a4a532edec
3 changed files with 19 additions and 0 deletions

View File

@@ -20,4 +20,6 @@ type Enemies interface {
SetTouched() SetTouched()
ClearTouched() ClearTouched()
IsTouched() bool IsTouched() bool
ExplosionInitiated() bool
SetExplosionInitiated()
} }

View File

@@ -22,6 +22,7 @@ type FlyEye struct {
hit bool hit bool
touched bool touched bool
toggle bool toggle bool
sploding bool
} }
func NewFlyEye() *FlyEye { func NewFlyEye() *FlyEye {
@@ -34,6 +35,7 @@ func NewFlyEye() *FlyEye {
hit: false, hit: false,
touched: false, touched: false,
toggle: false, toggle: false,
sploding: false,
} }
f.Maks.Fill(color.White) f.Maks.Fill(color.White)
return f return f
@@ -151,3 +153,11 @@ func (f *FlyEye) GetEnemyState() gamedata.EnemyState {
func (f *FlyEye) SetPosition(p gamedata.Coordinates) { func (f *FlyEye) SetPosition(p gamedata.Coordinates) {
f.position = p f.position = p
} }
func (f *FlyEye) ExplosionInitiated() bool {
return f.sploding
}
func (f *FlyEye) SetExplosionInitiated() {
f.sploding = true
}

View File

@@ -327,6 +327,13 @@ func (c *Canvas) UpdateEnemies() {
for _, e := range c.enemies { for _, e := range c.enemies {
if !c.gameover { if !c.gameover {
e.SetTarget(c.hero.Pos) e.SetTarget(c.hero.Pos)
if e.GetEnemyState() == gamedata.EnemyStateExploding && !e.ExplosionInitiated() {
if c.eventmap[gamedata.GameEventExplosion] != nil {
c.eventmap[gamedata.GameEventExplosion]()
}
e.SetExplosionInitiated()
}
} else { } else {
e.SetTarget(e.GetPosition()) e.SetTarget(e.GetPosition())
} }