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
}
