Randomize spark movement

This commit is contained in:
2025-06-08 21:15:05 +01:00
parent feb9ce08cc
commit 7e8eaaa34e
4 changed files with 7 additions and 12 deletions
+1 -6
View File
@@ -43,11 +43,7 @@ import Shape
import ShapePicture
-- this can almost certainly be made more efficient
foldCr ::
[Creature -> World -> World] ->
Creature ->
World ->
World
foldCr :: [Creature -> World -> World] -> Creature -> World -> World
foldCr xs cr w = foldl' f w xs
where
f w' g = case w' ^? cWorld . lWorld . creatures . ix (_crID cr) of
@@ -256,7 +252,6 @@ trySynthBullet loc w = fromMaybe w $ do
where
itm = loc ^. locLDT . ldtValue . _1
updateHeldRootItem :: Creature -> World -> World
updateHeldRootItem cr = fromMaybe id $ do
invid <- cr ^? crManipulation . manObject . imRootSelectedItem
-1
View File
@@ -50,7 +50,6 @@ collectDamageTypes :: [Damage] -> M.Map DamageType Int
collectDamageTypes = foldl' (flip f) M.empty
where
f dm = at (dmType dm) . non 0 +~ _dmAmount dm
--f dm = M.insertWith (+) (dmType dm) (_dmAmount dm)
maxDamageType :: [Damage] -> Maybe (DamageType, Int)
maxDamageType = safeMinimumOn (negate . snd) . M.assocs . collectDamageTypes
-3
View File
@@ -33,6 +33,3 @@ data Damage
makeLenses ''Damage
deriveJSON defaultOptions ''Damage
--deriveJSON defaultOptions ''DamageType
--instance ToJSONKey DamageType
--instance FromJSONKey DamageType
+6 -2
View File
@@ -18,17 +18,21 @@ updateSpark :: World -> Spark -> (World, Maybe Spark)
updateSpark w sk
| magV (_skVel sk) < 1 = (w, Nothing)
| otherwise = case thingHit sp ep w of
Nothing -> (w, Just $ sk & skPos .~ ep & skVel *~ 0.9 & skOldPos .~ sp)
Nothing -> (w & randGen .~ g, Just $ sk & skPos .~ ep & skVel *~ 0.9
& skVel %~ rotateV a
& skOldPos .~ sp)
Just (hp, hthing) ->
( sparkDam sk hthing w
, Just $ sk & skPos .~ hp & skOldPos .~ sp & skVel .~ 0
)
where
(a,g) = randomR (-x,x) (_randGen w)
x = 1
sp = _skPos sk
ep = sp + _skVel sk
sparkDam :: Spark -> Either Creature Wall -> World -> World
sparkDam sk = damageCrWl (sparkToDamage sk)
sparkDam = damageCrWl . sparkToDamage
sparkToDamage :: Spark -> Damage
sparkToDamage sp = case _skType sp of