Playing around with a laser weapon.
This commit is contained in:
60
elements/laser.go
Normal file
60
elements/laser.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"mover/gamedata"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type Laser struct {
|
||||
Sprite *ebiten.Image
|
||||
position gamedata.Coordinates
|
||||
angle float64
|
||||
cycle int
|
||||
firing bool
|
||||
}
|
||||
|
||||
func NewLaser(pos gamedata.Coordinates, angle float64) *Laser {
|
||||
l := &Laser{
|
||||
Sprite: ebiten.NewImage(200, 20),
|
||||
angle: angle,
|
||||
cycle: 0,
|
||||
position: pos,
|
||||
firing: false,
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
func (l *Laser) Update() error {
|
||||
l.cycle++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *Laser) Draw() {
|
||||
l.Sprite.Clear()
|
||||
l.Sprite.Fill(color.White)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user