From 519bbe75fdf8f16cd9dcc19c01759b700a0a29ed Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Fri, 31 Dec 2021 17:23:37 -0500 Subject: [PATCH] colors stay the same --- fireworks/fireworks.go | 6 ++---- simulation/simulation.go | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fireworks/fireworks.go b/fireworks/fireworks.go index 9a21a81..1e9a116 100644 --- a/fireworks/fireworks.go +++ b/fireworks/fireworks.go @@ -50,18 +50,16 @@ func SpawnShoot(width, height int) *simulation.Particle { ), Char: lipgloss.NewStyle().Foreground(color).Render(head), TailChar: lipgloss.NewStyle().Foreground(color).Render(tail), + Color: color, Shooting: true, ExplosionCall: SpawnExplosion, } return &p } -func SpawnExplosion(x, y float64, width, height int) []*simulation.Particle { - color := lipgloss.Color(array.Sample(colors)) +func SpawnExplosion(color lipgloss.Color, x, y float64, width, height int) []*simulation.Particle { v := float64(rand.Intn(10) + 20.0) - particles := []*simulation.Particle{} - for i := 0; i < numParticles; i++ { p := simulation.Particle{ Physics: harmonica.NewProjectile( diff --git a/simulation/simulation.go b/simulation/simulation.go index 812003f..b1edc05 100644 --- a/simulation/simulation.go +++ b/simulation/simulation.go @@ -6,6 +6,7 @@ import ( "time" "github.com/charmbracelet/harmonica" + "github.com/charmbracelet/lipgloss" ) type System struct { @@ -15,11 +16,12 @@ type System struct { type Particle struct { Char string + Color lipgloss.Color TailChar string Physics *harmonica.Projectile Hidden bool Shooting bool - ExplosionCall func(x, y float64, width, height int) []*Particle + ExplosionCall func(color lipgloss.Color, x, y float64, width, height int) []*Particle } type Frame struct { @@ -46,7 +48,7 @@ func (s *System) Update() { if !p.Hidden && p.Shooting && p.Physics.Velocity().Y > -3 { p.Hidden = true if p.ExplosionCall != nil { - s.Particles = append(s.Particles, p.ExplosionCall(pos.X, pos.Y, s.Frame.Width, s.Frame.Height)...) + s.Particles = append(s.Particles, p.ExplosionCall(p.Color, pos.X, pos.Y, s.Frame.Width, s.Frame.Height)...) } }