Added a rain layer for atmosphere.
This commit is contained in:
46
elements/raindrop.go
Normal file
46
elements/raindrop.go
Normal file
@@ -0,0 +1,46 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user