Skip to content

Instantly share code, notes, and snippets.

@eikaas
Created June 23, 2015 08:24
Show Gist options
  • Save eikaas/4f5578ff670aeb59c0ea to your computer and use it in GitHub Desktop.
Save eikaas/4f5578ff670aeb59c0ea to your computer and use it in GitHub Desktop.
Particle Count #2
package main
import "fmt"
type Particle struct {
x int
y int
}
type ParticleEmitter struct {
x int
y int
Particles []Particle
}
func main() {
var emitters []ParticleEmitter
emitters = append(emitters, ParticleEmitter{x: 1, y: 1})
emitters = append(emitters, ParticleEmitter{x: 2, y: 2})
for _, e := range emitters {
e.Particles = append(e.Particles, Particle{x: 32, y: 32})
e.Particles = append(e.Particles, Particle{x: 32, y: 32})
e.Particles = append(e.Particles, Particle{x: 32, y: 32})
}
// There should be two emitters with three particles each
particle_count := 0
emitter_count := 0
for _, e := range emitters {
emitter_count++
for _, p := range e.Particles {
fmt.Println(p.x)
particle_count++
}
}
fmt.Println("There are", emitter_count, "emitters and", particle_count, "particles")
// Output: There are 2 emitters and 0 particles
// Expected outpit: There are 2 emitters and 6 particles
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment