Cloud layer.
This commit is contained in:
62
elements/cloud.go
Normal file
62
elements/cloud.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"math"
|
||||
"mover/assets"
|
||||
"mover/gamedata"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type Cloud struct {
|
||||
Sprite *ebiten.Image
|
||||
position gamedata.Coordinates
|
||||
angle float64
|
||||
velocity float64
|
||||
Alpha float64
|
||||
}
|
||||
|
||||
func NewCloud(a gamedata.Area, angle, velocity float64) *Cloud {
|
||||
c := &Cloud{
|
||||
Sprite: ebiten.NewImage(a.Width, a.Height),
|
||||
angle: angle, //rand.Float64() * (math.Pi * 2),
|
||||
velocity: velocity,
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Cloud) Update() error {
|
||||
|
||||
c.position.X += c.velocity * math.Cos(c.angle)
|
||||
c.position.Y += c.velocity * math.Sin(c.angle)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cloud) Draw() {
|
||||
c.Sprite.Clear()
|
||||
//c.Sprite.Fill(color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff})
|
||||
//c.Sprite.Fill(color.White)
|
||||
|
||||
cloudsprite := assets.ImageBank[assets.Cloud]
|
||||
|
||||
spritex := cloudsprite.Bounds().Dx()
|
||||
spritey := cloudsprite.Bounds().Dy()
|
||||
|
||||
cloudx := c.Sprite.Bounds().Dx()
|
||||
cloudy := c.Sprite.Bounds().Dy()
|
||||
|
||||
scalex := float64(cloudx) / float64(spritex)
|
||||
scaley := float64(cloudy) / float64(spritey)
|
||||
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Scale(scalex, scaley)
|
||||
c.Sprite.DrawImage(assets.ImageBank[assets.Cloud], op)
|
||||
}
|
||||
|
||||
func (c *Cloud) SetPosition(p gamedata.Coordinates) {
|
||||
c.position = p
|
||||
}
|
||||
|
||||
func (c *Cloud) GetPosition() gamedata.Coordinates {
|
||||
return c.position
|
||||
}
|
||||
Reference in New Issue
Block a user