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
|
||||
}
|
||||
92
elements/splash.go
Normal file
92
elements/splash.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"math"
|
||||
"mover/assets"
|
||||
"mover/gamedata"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
SPLASH_DIM = 128
|
||||
SPLASH_ELEMS = 10
|
||||
SPLASH_PRIMARY_SIZE = 46
|
||||
)
|
||||
|
||||
type Splash struct {
|
||||
Sprite *ebiten.Image
|
||||
position gamedata.Coordinates
|
||||
cycle int
|
||||
opacity float32
|
||||
}
|
||||
|
||||
func NewSplash() *Splash {
|
||||
sp := &Splash{
|
||||
Sprite: ebiten.NewImage(SPLASH_DIM, SPLASH_DIM),
|
||||
cycle: 0,
|
||||
opacity: 1,
|
||||
}
|
||||
return sp
|
||||
}
|
||||
|
||||
func (sp *Splash) Update() error {
|
||||
sp.cycle++
|
||||
|
||||
sp.opacity = sp.opacity - float32(sp.cycle)/(60*60)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sp *Splash) Draw() {
|
||||
sp.Sprite.Clear()
|
||||
|
||||
/*
|
||||
for i := SPLASH_ELEMS; i > 0; i-- {
|
||||
|
||||
percent := float64(i) / SPLASH_ELEMS
|
||||
|
||||
dx := 1 / percent * math.Cos(float64(sp.cycle)/(math.Pi*2))
|
||||
dy := -float64(i - SPLASH_ELEMS) //math.Sin(float64(sp.cycle) / (math.Pi * 2))
|
||||
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Translate(-SPLASH_DIM/2, -SPLASH_DIM/2)
|
||||
op.GeoM.Scale(percent, percent)
|
||||
//op.GeoM.Rotate(-(float64(sp.cycle - i*30)) / (math.Pi * 2))
|
||||
op.GeoM.Translate(SPLASH_DIM/2+dx, SPLASH_DIM/2+dy)
|
||||
//op.ColorScale.ScaleAlpha(float32(percent))
|
||||
sp.Sprite.DrawImage(assets.ImageBank[assets.Splash], op)
|
||||
}*/
|
||||
|
||||
for i := 0; i < SPLASH_ELEMS; i++ {
|
||||
|
||||
percent := float64(SPLASH_ELEMS-i) / SPLASH_ELEMS
|
||||
|
||||
dy := -float64(i)*4 - float64(sp.cycle)/60
|
||||
dx := 2 / percent * math.Cos(float64(sp.cycle-i*10)/(math.Pi*2))
|
||||
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Translate(-48/2, -48/2)
|
||||
op.GeoM.Scale(percent, percent)
|
||||
op.GeoM.Rotate(-float64(sp.cycle) / (math.Pi * 4))
|
||||
op.GeoM.Translate(SPLASH_DIM/2, SPLASH_DIM/2)
|
||||
op.GeoM.Translate(dx, dy)
|
||||
|
||||
op.ColorScale.ScaleAlpha(sp.opacity)
|
||||
|
||||
sp.Sprite.DrawImage(assets.ImageBank[assets.Splash], op)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (sp *Splash) GetPosition() gamedata.Coordinates {
|
||||
return sp.position
|
||||
}
|
||||
|
||||
func (sp *Splash) SetPosition(pos gamedata.Coordinates) {
|
||||
sp.position = pos
|
||||
}
|
||||
|
||||
func (sp *Splash) GetAlpha() float32 {
|
||||
return sp.opacity
|
||||
}
|
||||
Reference in New Issue
Block a user