Move bullets into own data type

This commit is contained in:
2022-07-16 21:15:25 +01:00
parent 22adcb89e0
commit 301946ff8f
21 changed files with 216 additions and 108 deletions
+18 -3
View File
@@ -2,6 +2,7 @@
{- Bullet update. -}
module Dodge.Particle.Bullet.Update
( mvBullet
, mvSpark
) where
import Dodge.Data
--import Dodge.Base
@@ -12,15 +13,29 @@ import LensHelp
import Data.Bifunctor
{- Update for a generic bullet. -}
mvBullet :: World -> Particle -> (World, Maybe Particle)
mvBullet :: World -> Bullet -> (World, Maybe Bullet)
mvBullet w bt'
| t <= 0 || magV (_ptVel bt) < 1 = (w,Nothing)
| t <= 0 || magV (_buVel bt) < 1 = (w,Nothing)
| otherwise = second (fmap dodrag) $
hiteff bt (thingsHit p (p +.+ vel) w) w
where
bt = foldr (\mg b -> _mgField mg mg b) bt' $ _magnets w
dodrag = buVel .*.*~ drag
drag = _buDrag bt
(p:_) = _buTrail bt
vel = _buVel bt
hiteff = _buHitEff bt
t = _buTimer bt
mvSpark :: World -> Particle -> (World, Maybe Particle)
mvSpark w bt'
| t <= 0 || magV (_ptVel bt) < 1 = (w,Nothing)
| otherwise = second (fmap dodrag) $
hiteff bt (thingsHit p (p +.+ vel) w) w
where
bt = bt'
dodrag = ptVel .*.*~ drag
drag = _btDrag bt
drag = _ptDrag bt
(p:_) = _ptTrail bt
vel = _ptVel bt
hiteff = _ptHitEff bt