mirror of
https://github.com/maaslalani/confetty.git
synced 2024-11-22 07:36:40 +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
|
return m, nil
|
||||||
case frameMsg:
|
case frameMsg:
|
||||||
m.system.Update()
|
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()
|
return m, animate()
|
||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
m.system.Frame.Width = msg.Width
|
m.system.Frame.Width = msg.Width
|
||||||
|
@ -94,14 +94,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
case frameMsg:
|
case frameMsg:
|
||||||
m.system.Update()
|
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()
|
return m, animate()
|
||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
m.system.Frame.Width = msg.Width
|
m.system.Frame.Width = msg.Width
|
||||||
|
@ -29,8 +29,13 @@ func RemoveParticleFromArray(s []Particle, i int) []Particle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *System) Update() {
|
func (s *System) Update() {
|
||||||
for _, p := range s.Particles {
|
for i := len(s.Particles) - 1; i >= 0; i-- {
|
||||||
p.Physics.Update()
|
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