Move bullet trajectory into bullet update function
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
module Dodge.Particle.Bullet.Spawn
|
||||
( aBulAt
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Particle.Bullet.Update
|
||||
import Geometry
|
||||
import LensHelp
|
||||
|
||||
import Data.Maybe
|
||||
import Data.Bifunctor
|
||||
|
||||
aBulAt
|
||||
:: Maybe Float -- ^ Start velocity step factor
|
||||
-> (Bullet -> Bullet)
|
||||
-> Point2 -- ^ Start position
|
||||
-> Point2 -- ^ Velocity
|
||||
-> Float -- ^ Drag
|
||||
-> HitEffect'
|
||||
-> Float -- ^ Bullet width
|
||||
-> Bullet
|
||||
aBulAt vfact updatemod pos vel drag hiteff width = Bullet
|
||||
{ _buUpdate = theupdate
|
||||
, _buVel = fromMaybe 1 vfact *.* vel
|
||||
, _buDrag = drag
|
||||
, _buPos = pos
|
||||
, _buOldPos = pos
|
||||
, _buWidth = width
|
||||
, _buTimer = 100
|
||||
, _buHitEff = hiteff
|
||||
}
|
||||
where
|
||||
theupdate = case vfact of
|
||||
Just _ -> \w -> resetVel . mvBullet w . updatemod
|
||||
Nothing -> \w -> mvBullet w . updatemod
|
||||
resetVel = second $ fmap $ (buUpdate .~ (\w -> mvBullet w . updatemod)) . (buVel .~ vel)
|
||||
@@ -2,10 +2,11 @@
|
||||
{- Bullet update. -}
|
||||
module Dodge.Particle.Bullet.Update
|
||||
( mvBullet
|
||||
, mvBulletSlow
|
||||
, mvSpark
|
||||
) where
|
||||
import Dodge.Data
|
||||
--import Dodge.Base
|
||||
import Dodge.Movement.Turn
|
||||
import Dodge.WorldEvent.ThingsHit
|
||||
--import Picture
|
||||
import Geometry
|
||||
@@ -20,13 +21,34 @@ mvBullet w bt'
|
||||
hiteff bt (thingsHit p (p +.+ vel) w) w
|
||||
where
|
||||
bt = foldr (\mg b -> _mgField mg mg b) bt' $ _magnets w
|
||||
dodrag = buVel .*.*~ drag
|
||||
dodrag = case _buTrajectory bt of
|
||||
BasicBulletTrajectory -> buVel .*.*~ drag
|
||||
MagnetTrajectory tpos -> buVel .+.+~ 5 *.* normalizeV (tpos -.- _buPos bt)
|
||||
FlechetteTrajectory tpos -> buVel %~ vecTurnTo 0.2 (_buPos bt) tpos
|
||||
BezierTrajectory spos tpos xpos ->
|
||||
let bf tm = bQuadToF (spos,xpos,tpos) $ (100 - tm) * 0.05
|
||||
in buVel .~ bf (fromIntegral $ _buTimer bt - 1) -.- bf (fromIntegral $ _buTimer bt)
|
||||
drag = _buDrag bt
|
||||
p = _buPos bt
|
||||
vel = _buVel bt
|
||||
hiteff = _buHitEff bt
|
||||
t = _buTimer bt
|
||||
|
||||
mvBulletSlow :: Float -> World -> Bullet -> (World, Maybe Bullet)
|
||||
mvBulletSlow x w bt'
|
||||
| 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)
|
||||
. (buState .~ NormalBulletState)
|
||||
drag = _buDrag bt
|
||||
p = _buPos bt
|
||||
vel = x *.* _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)
|
||||
|
||||
@@ -23,7 +23,7 @@ destroyAt hitp pt = Just $ pt
|
||||
& ptTimer %~ (min 3 . subtract 1)
|
||||
destroyAt' :: Point2 -> Bullet -> Maybe Bullet
|
||||
destroyAt' hitp pt = Just $ pt
|
||||
& buUpdate .~ (\w -> const (w,Nothing))
|
||||
& buState .~ DyingBulletState
|
||||
& buPos .~ hitp
|
||||
& buOldPos .~ _buPos pt
|
||||
& buTimer %~ (min 3 . subtract 1)
|
||||
|
||||
Reference in New Issue
Block a user