Added weapon drops and collection. New laser item asset.

This commit is contained in:
2024-11-22 17:57:16 -05:00
parent b3a8ef8c0f
commit 253c708d45
6 changed files with 151 additions and 4 deletions

66
elements/weapondrop.go Normal file
View File

@@ -0,0 +1,66 @@
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
}