From 13db112d35b1385cdb1b9fdc034179a2ee9fd76a Mon Sep 17 00:00:00 2001 From: silva guimaraes Date: Sat, 23 Aug 2025 19:56:35 -0300 Subject: [PATCH] particles --- particle.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 particle.go diff --git a/particle.go b/particle.go new file mode 100644 index 0000000..3c7db49 --- /dev/null +++ b/particle.go @@ -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 +}