package elements

import (
	"math"
	"mover/assets"
	"mover/gamedata"

	"github.com/hajimehoshi/ebiten/v2"
)

type WeaponDrop struct {
	Sprite     *ebiten.Image
	position   gamedata.Coordinates
	weapontype gamedata.WeaponType
	cycle      int
	collected  bool
}

func NewWeaponDrop(wt gamedata.WeaponType) *WeaponDrop {
	wp := &WeaponDrop{
		Sprite:     ebiten.NewImage(32, 32),
		weapontype: wt,
		cycle:      0,
		collected:  false,
	}
	return wp
}

func (wp *WeaponDrop) SetPosition(pos gamedata.Coordinates) {
	wp.position = pos
}

func (wp *WeaponDrop) GetPosition() gamedata.Coordinates {
	return wp.position
}

func (wp *WeaponDrop) GetWeaponType() gamedata.WeaponType {
	return wp.weapontype
}

func (wp *WeaponDrop) Update() error {
	wp.cycle++
	return nil
}

func (wp *WeaponDrop) Draw() {
	wp.Sprite.Clear()

	dy := 2 * math.Sin(float64(wp.cycle)/(math.Pi*2))
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(0, dy)

	switch wp.weapontype {
	case gamedata.WeaponTypeLaser:
		wp.Sprite.DrawImage(assets.ImageBank[assets.ItemLaser], op)
	}

}

func (wp *WeaponDrop) SetCollected(c bool) {
	wp.collected = c
}

func (wp *WeaponDrop) IsCollected() bool {
	return wp.collected
}
