2024-11-11 09:54:30 -05:00
|
|
|
package elements
|
2024-11-05 06:28:08 -05:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"image"
|
2024-11-11 09:54:30 -05:00
|
|
|
"mover/assets"
|
|
|
|
|
"mover/gamedata"
|
2024-11-05 06:28:08 -05:00
|
|
|
|
|
|
|
|
_ "embed"
|
|
|
|
|
"image/color"
|
|
|
|
|
_ "image/png"
|
|
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
MoverActionDefault = iota
|
|
|
|
|
MoverActionDamaged
|
|
|
|
|
MoverActionDying
|
|
|
|
|
MoverActionExploding
|
|
|
|
|
MoverActionDead
|
|
|
|
|
MoverActionMax
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type MoverAction uint
|
|
|
|
|
|
|
|
|
|
type Mover struct {
|
2024-11-11 14:07:02 -05:00
|
|
|
Sprite *ebiten.Image
|
|
|
|
|
Maks *ebiten.Image
|
|
|
|
|
MaksDest *ebiten.Image
|
|
|
|
|
Angle float64
|
|
|
|
|
Pos gamedata.Coordinates
|
|
|
|
|
Origin gamedata.Coordinates
|
|
|
|
|
Action MoverAction
|
|
|
|
|
cycles int
|
|
|
|
|
rotating bool
|
|
|
|
|
Toggled bool
|
|
|
|
|
Hit bool
|
|
|
|
|
Touched bool
|
|
|
|
|
SplodeInitiated bool
|
|
|
|
|
dyingcount int
|
2024-11-05 06:28:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewMover() *Mover {
|
|
|
|
|
m := &Mover{
|
2024-11-11 14:07:02 -05:00
|
|
|
Sprite: ebiten.NewImage(MOVER_WIDTH, MOVER_HEIGHT),
|
|
|
|
|
Maks: ebiten.NewImage(MOVER_WIDTH, MOVER_HEIGHT),
|
|
|
|
|
MaksDest: ebiten.NewImage(MOVER_WIDTH, MOVER_HEIGHT),
|
|
|
|
|
Action: MoverActionDefault,
|
|
|
|
|
cycles: 4,
|
|
|
|
|
Angle: 0,
|
|
|
|
|
rotating: false,
|
|
|
|
|
Toggled: false,
|
|
|
|
|
dyingcount: 0,
|
|
|
|
|
SplodeInitiated: false,
|
2024-11-05 06:28:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m.Maks.Fill(color.White)
|
|
|
|
|
return m
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *Mover) ToggleRotate() {
|
|
|
|
|
m.rotating = !m.rotating
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *Mover) SetAngle(a float64) {
|
|
|
|
|
m.Angle = a
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-11 09:54:30 -05:00
|
|
|
func (m *Mover) SetOrigin(coords gamedata.Coordinates) {
|
2024-11-05 06:28:08 -05:00
|
|
|
m.Origin = coords
|
|
|
|
|
m.Pos = coords
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *Mover) Draw() {
|
|
|
|
|
m.Sprite.Clear()
|
|
|
|
|
m.MaksDest.Clear()
|
|
|
|
|
|
|
|
|
|
idx := (m.cycles / 8) % 4
|
|
|
|
|
|
|
|
|
|
y0 := 0
|
|
|
|
|
y1 := 48
|
|
|
|
|
x0 := 48 * idx
|
|
|
|
|
x1 := x0 + 48
|
|
|
|
|
|
|
|
|
|
switch m.Action {
|
|
|
|
|
case MoverActionDefault:
|
2024-11-11 09:54:30 -05:00
|
|
|
m.Sprite.DrawImage(assets.ImageBank[assets.FlyEyeNormal].SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), nil)
|
2024-11-05 06:28:08 -05:00
|
|
|
case MoverActionDamaged:
|
2024-11-11 09:54:30 -05:00
|
|
|
m.Sprite.DrawImage(assets.ImageBank[assets.FlyEyeDamaged].SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), nil)
|
2024-11-05 06:28:08 -05:00
|
|
|
case MoverActionDying:
|
2024-11-07 15:02:21 -05:00
|
|
|
|
2024-11-05 06:28:08 -05:00
|
|
|
if (m.cycles/5)%2 == 0 {
|
|
|
|
|
|
2024-11-11 09:54:30 -05:00
|
|
|
m.MaksDest.DrawImage(assets.ImageBank[assets.FlyEyeDamaged].SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), nil)
|
2024-11-05 06:28:08 -05:00
|
|
|
op := &ebiten.DrawImageOptions{}
|
|
|
|
|
op.GeoM.Reset()
|
|
|
|
|
op.Blend = ebiten.BlendSourceAtop
|
|
|
|
|
m.MaksDest.DrawImage(m.Maks, op)
|
|
|
|
|
m.Sprite.DrawImage(m.MaksDest, nil)
|
|
|
|
|
|
|
|
|
|
} else {
|
2024-11-11 09:54:30 -05:00
|
|
|
m.Sprite.DrawImage(assets.ImageBank[assets.FlyEyeDamaged].SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), nil)
|
2024-11-05 06:28:08 -05:00
|
|
|
}
|
2024-11-07 15:02:21 -05:00
|
|
|
if m.dyingcount >= 31 {
|
2024-11-05 06:28:08 -05:00
|
|
|
m.cycles = 0
|
|
|
|
|
m.SetHit()
|
|
|
|
|
}
|
|
|
|
|
case MoverActionExploding:
|
2024-11-11 09:54:30 -05:00
|
|
|
m.Sprite.DrawImage(assets.ImageBank[assets.FlyEyeDying].SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), nil)
|
2024-11-05 06:28:08 -05:00
|
|
|
if idx == 3 {
|
|
|
|
|
m.SetHit()
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *Mover) Update() {
|
|
|
|
|
/*
|
|
|
|
|
dx := 0. //40 * math.Cos(float64(m.cycles)/16)
|
|
|
|
|
dy := 0. //40 * math.Sin(float64(m.cycles)/16)
|
|
|
|
|
|
|
|
|
|
m.Pos = Coordinates{X: m.Origin.X + dx, Y: m.Origin.Y + dy}
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
if m.rotating {
|
|
|
|
|
m.Angle = float64(m.cycles) / (math.Pi * 2)
|
|
|
|
|
}
|
|
|
|
|
*/
|
2024-11-07 15:02:21 -05:00
|
|
|
if m.Action == MoverActionDying {
|
|
|
|
|
m.dyingcount++
|
|
|
|
|
}
|
2024-11-05 06:28:08 -05:00
|
|
|
m.cycles++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *Mover) SetHit() {
|
|
|
|
|
m.Action++ // = (m.Action + 1) % MoverActionMax
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *Mover) ToggleColor() {
|
2024-11-05 06:49:34 -05:00
|
|
|
//m.Toggled = !m.Toggled
|
|
|
|
|
if m.Action == MoverActionDefault {
|
|
|
|
|
m.Action = MoverActionDamaged
|
|
|
|
|
} else if m.Action == MoverActionDamaged {
|
|
|
|
|
m.Action = MoverActionDefault
|
|
|
|
|
}
|
2024-11-05 06:28:08 -05:00
|
|
|
}
|