affection/src/Affection/Particle.hs

33 lines
1.2 KiB
Haskell
Raw Normal View History

-- | This module introduces a simple particle system to Affection
module Affection.Particle
( updateParticles
, drawParticles
) where
import Affection.Types
-- This function updates particles through a specified function. Particle ageing
-- and death is being handled by 'updateParticles' itself and does not need to
-- bother you.
updateParticles
:: Double -- ^ Elapsed time in seconds
-> (Double -> Particle -> Particle) -- ^ Update function for a single 'Particle'
-- This Function should take the elapsed time
-- in seconds and the initial particle as arguments.
-> [Particle] -- ^ List of 'Particle's to be processed
-> [Particle] -- ^ resulting list of particles
updateParticles _ _ [] = []
updateParticles time funct (p:ps) =
if particleLife p - time < 0
then
updateParticles time funct ps
else
(funct time $ p { particleLife = particleLife p - time }) :
updateparticles time funct ps
drawParticles
:: (Particle -> Affection us ())
-> [Particle]
-> Affection us ()
drawParticles = mapM_