pituicat/src/Affection/Particle.hs
nek0 1f946624ef introducing particles
first little drafts
2016-12-12 03:34:57 +01:00

33 lines
1.2 KiB
Haskell

-- | 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_