Simplify bullets

This commit is contained in:
2024-12-24 13:59:06 +00:00
parent 15317882e6
commit 37da73bf6d
7 changed files with 70 additions and 70 deletions
+17 -15
View File
@@ -21,7 +21,8 @@ import Data.Bifunctor
updateBullet :: World -> Bullet -> (World, Maybe Bullet)
updateBullet w bu
| magV (_buVel bu) < 1 || _buTimer bu <= 0 = (endspawn w, Nothing)
-- | magV (_buVel bu) < 1 || _buTimer bu <= 0 = (endspawn w, Nothing)
| magV (_buVel bu) < 1 = (endspawn w, Nothing)
| otherwise =
second (fmap updateBulVel)
. hitEffFromBul w
@@ -59,16 +60,17 @@ doMagnetBuBu mg bu = if isclose
isclose = d < 100
updateBulVel :: Bullet -> Bullet
updateBulVel bt = case _buTrajectory bt of
BasicBulletTrajectory -> bt & buVel .*.*~ _buDrag bt
MagnetTrajectory tpos -> bt
& buVel %~ (clipV 20 . (+.+ 5 *.* normalizeV (tpos -.- _buPos bt)))
FlechetteTrajectory tpos -> bt & buVel %~ vecTurnTo 0.2 (_buPos bt) tpos
BezierTrajectory spos tpos xpos ->
let bf tm = bQuadToF (spos, xpos, tpos) $ (100 - tm) * 0.05
in bt & buVel .~ bf (fromIntegral $ t - 1) -.- bf (fromIntegral t)
where
t = _buTimer bt
updateBulVel bt = bt & buVel .*.*~ _buDrag bt
--case _buTrajectory bt of
-- BasicBulletTrajectory -> bt & buVel .*.*~ _buDrag bt
-- MagnetTrajectory tpos -> bt
-- & buVel %~ (clipV 20 . (+.+ 5 *.* normalizeV (tpos -.- _buPos bt)))
-- FlechetteTrajectory tpos -> bt & buVel %~ vecTurnTo 0.2 (_buPos bt) tpos
-- BezierTrajectory spos tpos xpos ->
-- let bf tm = bQuadToF (spos, xpos, tpos) $ (100 - tm) * 0.05
-- in bt & buVel .~ bf (fromIntegral $ t - 1) -.- bf (fromIntegral t)
-- where
-- t = _buTimer bt
-- NOTE THE FOLLOWING HAS BEZIER CURE/FLECHETTE STUFF THAT MIGHT BE USEFUL
--shootBullet :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
@@ -146,7 +148,7 @@ makeFlak bu _ w = w & cWorld . lWorld . bullets .++~ [f x | x <- xs]
s = min 10 (0.5 * magV (_buVel bu))
xs = take 5 $ randomRs (-s,s) $ _randGen w
f x = bu & buVel %~ g x
& buTimer .~ 97
-- & buTimer .~ 97
& buPayload .~ BulSpark
& buWidth .~ 0.5
& buDamages .~
@@ -170,8 +172,8 @@ hitEffFromBul w bu = case _buEffect bu of
bu
& buPos .~ hp +.+ normalizeV (_buPos bu -.- hp)
& buVel %~ reflectIn dir
& buTrajectory .~ BasicBulletTrajectory
& buTimer -~ 1
-- & buTrajectory .~ BasicBulletTrajectory
-- & buTimer -~ 1
)
DestroyBullet -> expireAndDamage bu hitstream w
where
@@ -206,7 +208,7 @@ moveBullet pt =
pt
& buPos %~ (+.+ _buVel pt)
& buOldPos .~ _buPos pt
& buTimer -~ 1
-- & buTimer -~ 1
destroyAt :: Point2 -> Bullet -> Maybe Bullet
destroyAt hitp pt =
+2 -2
View File
@@ -17,13 +17,13 @@ import Geometry.Data
data Bullet = Bullet
{ _buEffect :: BulletEffect
, _buPayload :: BulletPayload
, _buTrajectory :: BulletTrajectory
-- , _buTrajectory :: BulletTrajectory
, _buVel :: Point2
, _buDrag :: Float
, _buPos :: Point2
, _buOldPos :: Point2
, _buWidth :: Float
, _buTimer :: Int
-- , _buTimer :: Int
, _buDamages :: [Damage]
}
deriving (Show, Eq, Ord, Read) --Generic, Flat)
+7 -7
View File
@@ -414,16 +414,16 @@ getBulletType ::
Maybe Bullet
getBulletType itmtree magtree mz cr w =
magtree ^? ldtValue . itConsumables . magParams . ampBullet
<&> buTrajectory .~ btraj
-- <&> buTrajectory .~ btraj
<&> buPayload .~ bpayload
<&> buEffect .~ beffect
where
btraj = fromMaybe BasicBulletTrajectory $ do
targetingtree <- lookup WeaponTargetingLink (itmtree ^. ldtRight) -- left or right for these?
tp <- targetingtree ^? ldtValue . itTargeting . itTgPos . _Just
attree <- lookup AmmoTargetingLink (magtree ^. ldtLeft)
bt <- attree ^? ldtValue . itUse . ubMod . bmTrajectory
return $ getBulletTrajectory mz (itmtree ^. ldtValue) bt tp cr w
-- btraj = fromMaybe BasicBulletTrajectory $ do
-- targetingtree <- lookup WeaponTargetingLink (itmtree ^. ldtRight) -- left or right for these?
-- tp <- targetingtree ^? ldtValue . itTargeting . itTgPos . _Just
-- attree <- lookup AmmoTargetingLink (magtree ^. ldtLeft)
-- bt <- attree ^? ldtValue . itUse . ubMod . bmTrajectory
-- return $ getBulletTrajectory mz (itmtree ^. ldtValue) bt tp cr w
bpayload = fromMaybe BulSpark $ do
attree <- lookup AmmoPayloadLink (magtree ^. ldtLeft)
attree ^? ldtValue . itUse . ubMod . bmPayload
+2 -2
View File
@@ -12,13 +12,13 @@ defaultBullet =
Bullet
{ _buEffect = DestroyBullet
, _buPayload = BulSpark
, _buTrajectory = BasicBulletTrajectory
-- , _buTrajectory = BasicBulletTrajectory
, _buVel = V2 50 0
, _buDrag = 1
, _buPos = 0
, _buOldPos = 0
, _buWidth = 2
, _buTimer = 100
-- , _buTimer = 100
, _buDamages = basicBulDams
}
+2 -2
View File
@@ -28,8 +28,8 @@ import qualified Data.Map.Strict as M
testStringInit :: Universe -> [String]
testStringInit u =
(map show $ u ^. uvWorld . cWorld . lWorld . oldMagnets)
<>
(foldMap prettyShort $ u ^. uvWorld . cWorld . lWorld . bullets)
-- <>
-- (foldMap prettyShort $ u ^. uvWorld . cWorld . lWorld . bullets)
-- fromMaybe mempty $ do
-- cr <- u ^? uvWorld . cWorld . lWorld . creatures . ix 0
-- let itms = IM.elems $ cr ^. crInv