Allow for bullet drag

This commit is contained in:
2021-12-02 18:29:46 +00:00
parent 85ededc158
commit 8b8d75b016
35 changed files with 362 additions and 228 deletions
+3 -3
View File
@@ -56,7 +56,7 @@ bulBounceArmCr' bt p cr w
pOut = p +.+ 2 *.* newDir
reflectVel = magV bulVel *.* newDir
addBouncer = worldEvents %~ ( over particles (bouncer :) . )
bouncer = (aGenBulAt Nothing pOut reflectVel
bouncer = (aGenBulAt Nothing pOut reflectVel (_btDrag bt)
(_btHitEffect' bt) (_btWidth' bt)
) {_btTimer' = _btTimer' bt - 1}
{- | Bullet pass through creatures. -}
@@ -79,7 +79,7 @@ bulPenCr' bt p cr w
sp = head $ _btTrail' bt
ep = sp +.+ _btVel' bt
addPiercer = over particles (piercer :)
piercer = (aGenBulAt (Just cid) p (_btVel' bt)
piercer = (aGenBulAt (Just cid) p (_btVel' bt) (_btDrag bt)
(_btHitEffect' bt) (_btWidth' bt)
) {_btTimer' = _btTimer' bt - 1}
{- | Heavy bullet effects when hitting creature:
@@ -138,7 +138,7 @@ bulBounceWall bt p wl = damageWall (Blunt 50 sp p ep) wl . over worldEvents addB
ep = sp +.+ _btVel' bt
sp = head $ _btTrail' bt
pOut = p +.+ squashNormalizeV (sp -.- p)
bouncer = (aGenBulAt Nothing pOut reflectVel (_btHitEffect' bt) (_btWidth' bt)
bouncer = (aGenBulAt Nothing pOut reflectVel 0.5 (_btHitEffect' bt) (_btWidth' bt)
) {_btTimer' = _btTimer' bt - 1}
reflectVel = reflVelWall wl (_btVel' bt)
addBouncer = ( over particles (bouncer : ) . )
+8 -3
View File
@@ -16,13 +16,15 @@ aGenBulAt
:: Maybe Int -- ^ Pass-through creature id
-> Point2 -- ^ Start position
-> Point2 -- ^ Velocity
-> Float -- ^ Slowdown
-> HitEffect
-> Float -- ^ Bullet width
-> Particle
aGenBulAt maycid pos vel hiteff width = BulletPt
aGenBulAt maycid pos vel drag hiteff width = BulletPt
{ _ptDraw = drawBul
, _ptUpdate = mvBullet
, _btVel' = vel
, _btVel' = vel
, _btDrag = drag
, _btColor' = V4 2 2 2 2
, _btTrail' = [pos]
, _btPassThrough' = maycid
@@ -35,13 +37,15 @@ aDelayedBulAt
-> Maybe Int -- ^ Pass-through creature id
-> Point2 -- ^ Start position
-> Point2 -- ^ Velocity
-> Float -- ^ Drag
-> HitEffect
-> Float -- ^ Bullet width
-> Particle
aDelayedBulAt vfact maycid pos vel hiteff width = BulletPt
aDelayedBulAt vfact maycid pos vel drag hiteff width = BulletPt
{ _ptDraw = drawBul
, _ptUpdate = \w -> resetVel . mvBullet w
, _btVel' = vfact *.* vel
, _btDrag = drag
, _btColor' = V4 2 2 2 2
, _btTrail' = [pos]
, _btPassThrough' = maycid
@@ -65,6 +69,7 @@ aCurveBulAt maycid col pos control targ hiteff width = BulletPt
{ _ptDraw = drawBul
, _ptUpdate = \w -> mvBullet w . setVel
, _btVel' = V2 0 0
, _btDrag = 1
, _btColor' = col
, _btTrail' = [pos]
, _btPassThrough' = maycid
+6 -8
View File
@@ -10,23 +10,21 @@ import Dodge.WorldEvent.ThingsHit
import Geometry
--import Geometry.Vector3D
import Data.Bifunctor
import Control.Lens
{-
Update for a generic bullet.
-}
mvBullet :: World -> Particle -> (World, Maybe Particle)
mvBullet w bt
| t <= 0 = wAnd Nothing
| t < 4 = wAnd $ Just $ bt
& btPassThrough' .~ Nothing
& btTrail' .~ (p:p:ps)
& btTimer' -~ 1
-- | otherwise = hiteff bt (thingsHitExceptCr3D' mcr (addZ 20 p) (addZ 20 (p +.+ vel)) w) w
| otherwise = hiteff bt (thingsHitExceptCr mcr p (p +.+ vel) w) w
| t <= 0 || magV (_btVel' bt) < 1 = wAnd Nothing
| otherwise = second (fmap dodrag) $ hiteff bt (thingsHitExceptCr mcr p (p +.+ vel) w) w
where
dodrag = btVel' %~ (drag *.*)
drag = _btDrag bt
wAnd = (w,)
mcr = _btPassThrough' bt
(p:ps) = _btTrail' bt
(p:_) = _btTrail' bt
vel = _btVel' bt
hiteff = _btHitEffect' bt
t = _btTimer' bt
+1
View File
@@ -25,6 +25,7 @@ colSpark' randDir time col pos baseDir w = w
spark = BulletPt
{ _ptDraw = drawBul
, _ptUpdate = mvBullet
, _btDrag = 0.9
, _btVel' = rotateV dir (V2 5 0)
, _btColor' = col
, _btTrail' = [pos]