2024-11-21 13:20:17 -05:00
|
|
|
package elements
|
|
|
|
|
|
|
|
|
|
import (
|
2024-11-21 16:26:25 -05:00
|
|
|
"image"
|
|
|
|
|
"mover/assets"
|
2024-11-21 13:20:17 -05:00
|
|
|
"mover/gamedata"
|
|
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Laser struct {
|
2024-11-21 16:26:25 -05:00
|
|
|
Sprite *ebiten.Image
|
|
|
|
|
position gamedata.Coordinates
|
|
|
|
|
angle float64
|
|
|
|
|
cycle int
|
|
|
|
|
firing bool
|
|
|
|
|
numcycles int
|
2024-11-21 13:20:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewLaser(pos gamedata.Coordinates, angle float64) *Laser {
|
|
|
|
|
l := &Laser{
|
2024-11-21 16:26:25 -05:00
|
|
|
Sprite: ebiten.NewImage(200, 20),
|
|
|
|
|
angle: angle,
|
|
|
|
|
cycle: 0,
|
|
|
|
|
position: pos,
|
|
|
|
|
firing: false,
|
|
|
|
|
numcycles: 5,
|
2024-11-21 13:20:17 -05:00
|
|
|
}
|
|
|
|
|
return l
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *Laser) Update() error {
|
|
|
|
|
l.cycle++
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *Laser) Draw() {
|
|
|
|
|
l.Sprite.Clear()
|
2024-11-21 16:26:25 -05:00
|
|
|
//l.Sprite.Fill(color.White)
|
|
|
|
|
|
|
|
|
|
idx := (l.cycle / 4) % l.numcycles
|
|
|
|
|
x0 := 0
|
|
|
|
|
y0 := 20 * idx
|
|
|
|
|
x1 := 200
|
|
|
|
|
y1 := y0 + 20
|
|
|
|
|
|
|
|
|
|
l.Sprite.DrawImage(assets.ImageBank[assets.LaserBeam].SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), nil)
|
|
|
|
|
|
2024-11-21 13:20:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *Laser) GetPosition() gamedata.Coordinates {
|
|
|
|
|
return l.position
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *Laser) SetPosition(pos gamedata.Coordinates) {
|
|
|
|
|
l.position = pos
|
|
|
|
|
}
|
|
|
|
|
func (l *Laser) GetAngle() float64 {
|
|
|
|
|
return l.angle
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *Laser) SetAngle(a float64) {
|
|
|
|
|
l.angle = a
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *Laser) SetFiring(b bool) {
|
|
|
|
|
l.firing = b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *Laser) IsFiring() bool {
|
|
|
|
|
return l.firing
|
|
|
|
|
}
|