Move bullet trajectory into bullet update function

This commit is contained in:
2022-07-17 10:31:34 +01:00
parent c9f7f39f22
commit 7d6407bebc
15 changed files with 159 additions and 121 deletions
+75
View File
@@ -0,0 +1,75 @@
module Dodge.Bullet where
import Dodge.Data
import Dodge.Particle.Bullet.Update
import Dodge.Creature.HandPos
import Dodge.Base.Coordinate
import Geometry
import LensHelp
import Data.Maybe
updateBullet :: World -> Bullet -> (World,Maybe Bullet)
updateBullet w bu = case _buState bu of
DyingBulletState -> (w,Nothing)
DelayedBullet x -> mvBulletSlow x w bu
_ -> mvBullet w bu
aBulAt
:: Maybe Float -- ^ Start velocity step factor
-- -> (Bullet -> Bullet)
-> Point2 -- ^ Start position
-> Point2 -- ^ Velocity
-> Float -- ^ Drag
-> HitEffect'
-> Float -- ^ Bullet width
-> BulletTrajectory
-> Bullet
aBulAt vfact --updatemod
pos vel drag hiteff width butraj = Bullet
{ _buState = bulstate
, _buUpdateMod = NoBulletUpdateMod
, _buTrajectory = butraj
, _buVel = vel
, _buDrag = drag
, _buPos = pos
, _buOldPos = pos
, _buWidth = width
, _buTimer = 100
, _buHitEff = hiteff
}
where
bulstate = fromMaybe NormalBulletState $ DelayedBullet <$> vfact
useAmmoParams :: Maybe Float -> Item -> Creature -> World -> World
useAmmoParams vfact it cr w = w & instantBullets .:~ aBulAt
vfact
-- thetraj -- extra update
sp
(rotateV dir (muzvel *.* _amBulVel bultype)) -- vel
(_rifling $ _itParams it) -- drag
(_amBulEff bultype)
(_amBulWth bultype)
thetraj
-- (_amBulTraj bultype)
where
sp = _crPos cr +.+ (muzlength + 10) *.* unitVectorAtAngle dir
dir = _crDir cr
bultype = _laAmmoType $ _itConsumption it
muzvel = _muzVel $ _itParams it
muzlength = aimingMuzzlePos cr it
thetraj = case _amBulTraj bultype of
BasicBulletTrajectory -> BasicBulletTrajectory
MagnetTrajectory{} -> fromMaybe BasicBulletTrajectory $ do
tpos <- it ^? itTargeting . tgPos . _Just
return $ MagnetTrajectory tpos
--return $ \pt -> pt & buVel .+.+~ 5 *.* normalizeV (tpos -.- _buPos pt)
FlechetteTrajectory{} -> fromMaybe BasicBulletTrajectory $ do
tpos <- it ^? itTargeting . tgPos . _Just
return $ FlechetteTrajectory tpos
--return $ \pt -> pt & buVel %~ vecTurnTo 0.2 (_buPos pt) tpos
BezierTrajectory{} -> fromMaybe BasicBulletTrajectory $ do
tpos <- it ^? itTargeting . tgPos . _Just
return $ BezierTrajectory sp tpos (mouseWorldPos w)
-- let bf t = bQuadToF (sp,mouseWorldPos w,tpos) $ (100 - t) * 0.05
-- return $ \pt -> pt
-- & buVel .~ bf (fromIntegral $ _buTimer pt - 1) -.- bf (fromIntegral $ _buTimer pt)