Fireballs and shadows.
This commit is contained in:
@@ -3,6 +3,7 @@ package elements
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"math/rand/v2"
|
||||
"mover/assets"
|
||||
"mover/gamedata"
|
||||
|
||||
@@ -14,20 +15,23 @@ const (
|
||||
)
|
||||
|
||||
type FlyGoblin struct {
|
||||
Sprite *ebiten.Image
|
||||
Maks *ebiten.Image
|
||||
MaksDest *ebiten.Image
|
||||
position gamedata.Coordinates
|
||||
target gamedata.Coordinates
|
||||
state gamedata.EnemyState
|
||||
cycle int
|
||||
health int
|
||||
damageduration int
|
||||
right bool
|
||||
touched bool
|
||||
toggle bool
|
||||
sploding bool
|
||||
damage bool
|
||||
Sprite *ebiten.Image
|
||||
Maks *ebiten.Image
|
||||
MaksDest *ebiten.Image
|
||||
position gamedata.Coordinates
|
||||
target gamedata.Coordinates
|
||||
state gamedata.EnemyState
|
||||
cycle int
|
||||
health int
|
||||
damageduration int
|
||||
right bool
|
||||
touched bool
|
||||
toggle bool
|
||||
sploding bool
|
||||
damage bool
|
||||
called bool
|
||||
deathcallback func()
|
||||
fireballcallback func()
|
||||
}
|
||||
|
||||
func NewFlyGoblin() *FlyGoblin {
|
||||
@@ -37,6 +41,7 @@ func NewFlyGoblin() *FlyGoblin {
|
||||
MaksDest: ebiten.NewImage(96, 96),
|
||||
health: FG_MAXHEALTH,
|
||||
damageduration: 0,
|
||||
called: false,
|
||||
}
|
||||
fg.Maks.Fill(color.White)
|
||||
return fg
|
||||
@@ -61,6 +66,22 @@ func (f *FlyGoblin) Update() error {
|
||||
f.position.X += dx / 48
|
||||
f.position.Y += dy / 48
|
||||
|
||||
//10% chance to summon fireball
|
||||
fb := rand.Float64() >= 0.9
|
||||
|
||||
if (f.cycle/8)%4 == 0 && fb {
|
||||
if f.fireballcallback != nil {
|
||||
f.fireballcallback()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if f.state == gamedata.EnemyStateDead && !f.called {
|
||||
f.called = true
|
||||
if f.deathcallback != nil {
|
||||
f.deathcallback()
|
||||
}
|
||||
}
|
||||
|
||||
f.cycle++
|
||||
@@ -107,6 +128,7 @@ func (f *FlyGoblin) Draw() {
|
||||
f.Sprite.DrawImage(assets.ImageBank[assets.FlyEyeDying].SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), op)
|
||||
if idx == 3 {
|
||||
f.state = gamedata.EnemyStateDead
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,3 +204,15 @@ func (f *FlyGoblin) Health() int {
|
||||
func (f *FlyGoblin) MaxHealth() int {
|
||||
return FG_MAXHEALTH
|
||||
}
|
||||
|
||||
func (f *FlyGoblin) SetDeathEvent(somefunc func()) {
|
||||
f.deathcallback = somefunc
|
||||
}
|
||||
|
||||
func (f *FlyGoblin) SetFireballCallback(somefunc func()) {
|
||||
f.fireballcallback = somefunc
|
||||
}
|
||||
|
||||
func (f *FlyGoblin) GetAngle() float64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user