added variable refresh rate support
This commit is contained in:
parent
84fe6fe9eb
commit
f75618ec44
3 changed files with 113 additions and 67 deletions
|
@ -18,20 +18,23 @@ var topColor = rl.Color{R: 0x20, G: 0x0F, B: 0x3C, A: 0xFF} // #200F3C top
|
|||
var bottomColor = rl.Color{R: 0x3B, G: 0x0B, B: 0x42, A: 0xFF} // #3B0B42 bottom
|
||||
var particleColor = rl.Color{R: 0xD4, G: 0xB0, B: 0xB5, A: 0x80} // D4B0B5 with some transparency
|
||||
|
||||
var rng = rand.New(rand.NewSource(time.Now().UnixNano())) // Local RNG
|
||||
|
||||
func InitBackground(width, height int) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
particles = make([]Particle, 100)
|
||||
for i := range particles {
|
||||
particles[i].Pos = rl.Vector2{X: float32(rand.Intn(width)), Y: float32(rand.Intn(height))}
|
||||
particles[i].Vel = rl.Vector2{X: (rand.Float32() - 0.5) * 0.2, Y: (rand.Float32() - 0.5) * 0.2}
|
||||
particles[i].Size = rand.Float32()*1.5 + 0.5 // Particles size ~0.5-2.0
|
||||
particles[i].Pos = rl.Vector2{X: float32(rng.Intn(width)), Y: float32(rng.Intn(height))}
|
||||
particles[i].Vel = rl.Vector2{X: (rng.Float32() - 0.5) * 0.2, Y: (rng.Float32() - 0.5) * 0.2}
|
||||
particles[i].Size = rng.Float32()*1.5 + 0.5 // Particles size ~0.5-2.0
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateBackground(screenWidth, screenHeight int) {
|
||||
deltaTime := rl.GetFrameTime() // Time in seconds since the last frame
|
||||
for i := range particles {
|
||||
particles[i].Pos.X += particles[i].Vel.X
|
||||
particles[i].Pos.Y += particles[i].Vel.Y
|
||||
particles[i].Pos.X += particles[i].Vel.X * deltaTime * 60 // Adjust for frame rate
|
||||
particles[i].Pos.Y += particles[i].Vel.Y * deltaTime * 60
|
||||
|
||||
// Wrap around screen
|
||||
if particles[i].Pos.X < 0 {
|
||||
particles[i].Pos.X += float32(screenWidth)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue