44 lines
924 B
Go
44 lines
924 B
Go
package main
|
|
|
|
import (
|
|
"math"
|
|
"math/rand"
|
|
|
|
rl "github.com/gen2brain/raylib-go/raylib"
|
|
)
|
|
|
|
type particle struct {
|
|
pos, speed rl.Vector2
|
|
}
|
|
|
|
type particleSpawner struct {
|
|
particles []particle
|
|
}
|
|
|
|
func (p *particle) update(g *game) {
|
|
p.pos = rl.Vector2Add(p.pos, rl.Vector2Scale(p.speed, rl.GetFrameTime()*g.gameSpeed))
|
|
p.pos.Y = float32(math.Mod(float64(p.pos.Y), float64(g.arenaHeight)))
|
|
rl.DrawPixelV(p.pos, rl.White)
|
|
}
|
|
|
|
func (s *particleSpawner) update(g *game) {
|
|
for i := range s.particles {
|
|
(&s.particles[i]).update(g)
|
|
}
|
|
}
|
|
|
|
func starsBackground(g *game) *particleSpawner {
|
|
s := new(particleSpawner)
|
|
n := 2000
|
|
s.particles = make([]particle, n)
|
|
for i := range n {
|
|
rWidth := float32(rand.Int31n(g.arenaWidth))
|
|
rHeight := float32(rand.Int31n(g.arenaHeight))
|
|
s.particles[i] = particle{
|
|
pos: rl.Vector2{X: rWidth, Y: rHeight},
|
|
speed: rl.Vector2{X: 0, Y: rand.Float32()*123 + 87},
|
|
}
|
|
|
|
}
|
|
return s
|
|
}
|