particles

This commit is contained in:
silva guimaraes 2025-08-23 19:56:35 -03:00
parent d50bed0777
commit 13db112d35

44
particle.go Normal file
View file

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