47 lines
723 B
Go
47 lines
723 B
Go
|
|
package elements
|
||
|
|
|
||
|
|
import (
|
||
|
|
"image/color"
|
||
|
|
"math/rand/v2"
|
||
|
|
"mover/gamedata"
|
||
|
|
|
||
|
|
"github.com/hajimehoshi/ebiten/v2"
|
||
|
|
)
|
||
|
|
|
||
|
|
type RainDrop struct {
|
||
|
|
Sprite *ebiten.Image
|
||
|
|
position gamedata.Coordinates
|
||
|
|
cycle int
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewRainDrop() *RainDrop {
|
||
|
|
rd := &RainDrop{
|
||
|
|
Sprite: ebiten.NewImage(2, 10),
|
||
|
|
cycle: rand.IntN(30),
|
||
|
|
}
|
||
|
|
return rd
|
||
|
|
}
|
||
|
|
|
||
|
|
func (rd *RainDrop) Update() error {
|
||
|
|
rd.position.Y += 5
|
||
|
|
rd.cycle++
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (rd *RainDrop) Draw() {
|
||
|
|
rd.Sprite.Clear()
|
||
|
|
rd.Sprite.Fill(color.White)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (rd *RainDrop) GetPosition() gamedata.Coordinates {
|
||
|
|
return rd.position
|
||
|
|
}
|
||
|
|
|
||
|
|
func (rd *RainDrop) SetPosition(pos gamedata.Coordinates) {
|
||
|
|
rd.position = pos
|
||
|
|
}
|
||
|
|
|
||
|
|
func (rd *RainDrop) Expired() bool {
|
||
|
|
return rd.cycle > 30
|
||
|
|
}
|