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
|
||||
}
|
||||
58
elements/rainsplash.go
Normal file
58
elements/rainsplash.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"image"
|
||||
"math/rand/v2"
|
||||
"mover/assets"
|
||||
"mover/gamedata"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type RainSplash struct {
|
||||
Sprite *ebiten.Image
|
||||
position gamedata.Coordinates
|
||||
cycle int
|
||||
counter int
|
||||
}
|
||||
|
||||
func NewRainSplash() *RainSplash {
|
||||
rd := &RainSplash{
|
||||
Sprite: ebiten.NewImage(10, 4),
|
||||
cycle: rand.IntN(4),
|
||||
counter: 0,
|
||||
}
|
||||
return rd
|
||||
}
|
||||
|
||||
func (rd *RainSplash) Update() error {
|
||||
rd.counter++
|
||||
rd.cycle++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rd *RainSplash) Draw() {
|
||||
rd.Sprite.Clear()
|
||||
//rd.Sprite.Fill(color.White)
|
||||
|
||||
idx := (rd.cycle / 8) % 4
|
||||
x0 := idx * 10
|
||||
y0 := 0
|
||||
x1 := x0 + 10
|
||||
y1 := 4
|
||||
|
||||
rd.Sprite.DrawImage(assets.ImageBank[assets.RainSplash].SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), nil)
|
||||
|
||||
}
|
||||
|
||||
func (rd *RainSplash) GetPosition() gamedata.Coordinates {
|
||||
return rd.position
|
||||
}
|
||||
|
||||
func (rd *RainSplash) SetPosition(pos gamedata.Coordinates) {
|
||||
rd.position = pos
|
||||
}
|
||||
|
||||
func (rd *RainSplash) Expired() bool {
|
||||
return rd.counter > 30
|
||||
}
|
||||
@@ -77,6 +77,26 @@ func (sp *Splash) Draw() {
|
||||
sp.Sprite.DrawImage(assets.ImageBank[assets.Splash], op)
|
||||
}
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
|
||||
percent := float64(5-i) / 5
|
||||
|
||||
a := 9.8
|
||||
time := float64(sp.cycle) / 8
|
||||
v0 := 10.
|
||||
dy := 1/2.*a*math.Pow(time-float64(i), 2) - v0*time
|
||||
dx := -float64(sp.cycle)
|
||||
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Translate(-48/2, -48/2)
|
||||
op.GeoM.Scale(percent, percent)
|
||||
op.GeoM.Rotate(-float64(sp.cycle) / (math.Pi * 4))
|
||||
op.GeoM.Translate(SPLASH_DIM/2, SPLASH_DIM/2)
|
||||
op.GeoM.Translate(dx, dy)
|
||||
sp.Sprite.DrawImage(assets.ImageBank[assets.Splash], op)
|
||||
op.GeoM.Translate(-2*dx, 0)
|
||||
sp.Sprite.DrawImage(assets.ImageBank[assets.Splash], op)
|
||||
}
|
||||
}
|
||||
|
||||
func (sp *Splash) GetPosition() gamedata.Coordinates {
|
||||
|
||||
Reference in New Issue
Block a user