Files
survive/elements/fireball.go
2024-11-16 19:03:07 -05:00

119 lines
1.9 KiB
Go

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
}