mirror of
https://github.com/maaslalani/confetty.git
synced 2024-11-21 15:16:39 +00:00
Include off-screen detection in simulation update loop
This commit is contained in:
parent
78a718424f
commit
6bc31f21b1
@ -93,14 +93,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
case frameMsg:
|
||||
m.system.Update()
|
||||
|
||||
for i := len(m.system.Particles) - 1; i >= 0; i-- {
|
||||
p := m.system.Particles[i].Physics.Position()
|
||||
if p.X > float64(m.system.Frame.Width) || p.X < 0 || p.Y > float64(m.system.Frame.Height) {
|
||||
m.system.Particles = simulation.RemoveParticleFromArray(m.system.Particles, i)
|
||||
}
|
||||
}
|
||||
|
||||
return m, animate()
|
||||
case tea.WindowSizeMsg:
|
||||
m.system.Frame.Width = msg.Width
|
||||
|
@ -94,14 +94,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
case frameMsg:
|
||||
m.system.Update()
|
||||
|
||||
for i := len(m.system.Particles) - 1; i >= 0; i-- {
|
||||
p := m.system.Particles[i].Physics.Position()
|
||||
if p.X > float64(m.system.Frame.Width) || p.X < 0 || p.Y > float64(m.system.Frame.Height) {
|
||||
m.system.Particles = simulation.RemoveParticleFromArray(m.system.Particles, i)
|
||||
}
|
||||
}
|
||||
|
||||
return m, animate()
|
||||
case tea.WindowSizeMsg:
|
||||
m.system.Frame.Width = msg.Width
|
||||
|
@ -29,8 +29,13 @@ func RemoveParticleFromArray(s []Particle, i int) []Particle {
|
||||
}
|
||||
|
||||
func (s *System) Update() {
|
||||
for _, p := range s.Particles {
|
||||
p.Physics.Update()
|
||||
for i := len(s.Particles) - 1; i >= 0; i-- {
|
||||
p := s.Particles[i].Physics.Position()
|
||||
if p.X > float64(s.Frame.Width) || p.X < 0 || p.Y > float64(s.Frame.Height) {
|
||||
s.Particles = RemoveParticleFromArray(s.Particles, i)
|
||||
} else {
|
||||
s.Particles[i].Physics.Update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user