Fireballs and shadows.
This commit is contained in:
@@ -24,4 +24,5 @@ type Enemies interface {
|
||||
SetExplosionInitiated()
|
||||
Health() int
|
||||
MaxHealth() int
|
||||
GetAngle() float64
|
||||
}
|
||||
|
||||
118
elements/fireball.go
Normal file
118
elements/fireball.go
Normal file
@@ -0,0 +1,118 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"image"
|
||||
"math"
|
||||
"mover/assets"
|
||||
"mover/gamedata"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type FireBall struct {
|
||||
Sprite *ebiten.Image
|
||||
position gamedata.Coordinates
|
||||
angle float64
|
||||
velocity float64
|
||||
cycle int
|
||||
}
|
||||
|
||||
func NewFireBall(angle, velocity float64) *FireBall {
|
||||
fb := &FireBall{
|
||||
Sprite: ebiten.NewImage(50, 50),
|
||||
cycle: 0,
|
||||
angle: angle,
|
||||
velocity: velocity,
|
||||
}
|
||||
return fb
|
||||
}
|
||||
|
||||
func (fb *FireBall) Update() error {
|
||||
|
||||
fb.position.X += fb.velocity * math.Cos(fb.angle)
|
||||
fb.position.Y += fb.velocity * math.Sin(fb.angle)
|
||||
|
||||
fb.cycle++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fb *FireBall) Draw() {
|
||||
fb.Sprite.Clear()
|
||||
//fb.Sprite.Fill(color.RGBA{R: 0xff, G: 0x00, B: 0x00, A: 0xff})
|
||||
|
||||
idx := fb.cycle / 8 % 5
|
||||
x0 := idx * 50
|
||||
x1 := x0 + 50
|
||||
y0 := 0
|
||||
y1 := 50
|
||||
|
||||
fb.Sprite.DrawImage(assets.ImageBank[assets.Fireball].SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), nil)
|
||||
}
|
||||
|
||||
func (fb *FireBall) GetPosition() gamedata.Coordinates {
|
||||
return fb.position
|
||||
}
|
||||
|
||||
func (fb *FireBall) SetPosition(pos gamedata.Coordinates) {
|
||||
fb.position = pos
|
||||
}
|
||||
|
||||
func (fb *FireBall) SetTarget(gamedata.Coordinates) {
|
||||
|
||||
}
|
||||
|
||||
func (fb *FireBall) GetAngle() float64 {
|
||||
return fb.angle
|
||||
}
|
||||
|
||||
func (fb *FireBall) GetVelocity() float64 {
|
||||
return fb.velocity
|
||||
}
|
||||
|
||||
func (fb *FireBall) GetSprite() *ebiten.Image {
|
||||
return fb.Sprite
|
||||
}
|
||||
|
||||
func (fb *FireBall) ClearTouched() {
|
||||
|
||||
}
|
||||
|
||||
func (fb *FireBall) ExplosionInitiated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (fb *FireBall) GetEnemyState() gamedata.EnemyState {
|
||||
return gamedata.EnemyStateDefault
|
||||
}
|
||||
|
||||
func (fb *FireBall) SetHit() {
|
||||
|
||||
}
|
||||
|
||||
func (fb *FireBall) SetToggle() {
|
||||
|
||||
}
|
||||
|
||||
func (fb *FireBall) IsToggled() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (fb *FireBall) SetTouched() {
|
||||
|
||||
}
|
||||
|
||||
func (fb *FireBall) IsTouched() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (fb *FireBall) SetExplosionInitiated() {
|
||||
|
||||
}
|
||||
|
||||
func (fb *FireBall) Health() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (fb *FireBall) MaxHealth() int {
|
||||
return 1
|
||||
}
|
||||
@@ -171,3 +171,7 @@ func (f *FlyEye) Health() int {
|
||||
func (f *FlyEye) MaxHealth() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (f *FlyEye) GetAngle() float64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -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