Work on time scrolling

This commit is contained in:
2022-10-27 10:23:52 +01:00
parent 4ffd361f11
commit 35f2992fe4
12 changed files with 127 additions and 83 deletions
+3 -3
View File
@@ -105,9 +105,9 @@ updateRenderSplit u = do
return $! updateUniverse u return $! updateUniverse u
playSoundUnlessRewinding :: Universe -> IO (M.Map SoundOrigin Sound) playSoundUnlessRewinding :: Universe -> IO (M.Map SoundOrigin Sound)
playSoundUnlessRewinding u playSoundUnlessRewinding u = case w ^. timeFlow of
| _timeFlow w == RewindingNow = return M.empty NormalTimeFlow -> playSoundAndUpdate (_soundData $ _preloadData u) (_playingSounds w) (_toPlaySounds w)
| otherwise = playSoundAndUpdate (_soundData $ _preloadData u) (_playingSounds w) (_toPlaySounds w) _ -> return M.empty
where where
w = _uvWorld u w = _uvWorld u
+1
View File
@@ -110,6 +110,7 @@ data EquipItemType
data LeftItemType data LeftItemType
= BOOSTER = BOOSTER
| REWINDER | REWINDER
| TIMESCROLLER
| BLINKER | BLINKER
| BLINKERUNSAFE | BLINKERUNSAFE
| SHRINKER | SHRINKER
+2 -2
View File
@@ -19,8 +19,8 @@ data ItEffect = ItEffect
data ItInvEffect data ItInvEffect
= NoInvEffect = NoInvEffect
| RewindEffect | ChargeIfEquipped
| TimeScrollEffect | ChargeIfInInventory
| EffectIfHeld ItInvEffect ItInvEffect | EffectIfHeld ItInvEffect ItInvEffect
| CreateHeldLight | CreateHeldLight
| CreateShieldWall | CreateShieldWall
+1
View File
@@ -47,6 +47,7 @@ data Euse
data Luse data Luse
= LDoNothing = LDoNothing
| LRewind | LRewind
| LTimeScroll
| LShrink | LShrink
| LBlink | LBlink
| LUnsafeBlink | LUnsafeBlink
+6 -3
View File
@@ -55,8 +55,12 @@ data TimeFlowStatus
| RewindingLastFrame | RewindingLastFrame
| NormalTimeFlow | NormalTimeFlow
| ScrollTimeFlow | ScrollTimeFlow
{ _scrollSmoothing :: Int } { _scrollSmoothing :: Int
deriving (Eq, Ord, Show, Read) --Generic, Flat) , _reverseAmount :: Int
, _futureWorlds :: [CWorld]
, _scrollItemLocation :: Int
}
-- deriving (Eq, Ord, Show, Read) --Generic, Flat)
data WorldHammer data WorldHammer
= SubInvHam = SubInvHam
@@ -67,7 +71,6 @@ data CWTime = CWTime
{ _maybeWorld :: Maybe' CWorld { _maybeWorld :: Maybe' CWorld
, _pastWorlds :: [CWorld] , _pastWorlds :: [CWorld]
, _pastWorldsNum :: Int , _pastWorldsNum :: Int
, _futureWorlds :: [CWorld]
, _worldClock :: Int , _worldClock :: Int
, _deathDelay :: Maybe Int , _deathDelay :: Maybe Int
} }
-1
View File
@@ -137,7 +137,6 @@ defaultCWTime =
, _maybeWorld = Nothing' , _maybeWorld = Nothing'
, _pastWorlds = [] , _pastWorlds = []
, _pastWorldsNum = 0 , _pastWorldsNum = 0
, _futureWorlds = []
, _deathDelay = Nothing , _deathDelay = Nothing
} }
+28 -19
View File
@@ -8,8 +8,8 @@ import Dodge.LightSource.Torch
doInvEffect :: ItInvEffect -> Item -> Creature -> World -> World doInvEffect :: ItInvEffect -> Item -> Creature -> World -> World
doInvEffect iie = case iie of doInvEffect iie = case iie of
NoInvEffect -> const $ const id NoInvEffect -> const $ const id
RewindEffect -> rewindEffect ChargeIfEquipped -> chargeIfEquipped
TimeScrollEffect -> timeScrollEffect ChargeIfInInventory -> chargeIfInInventory
EffectIfHeld f g -> onOffEff f g EffectIfHeld f g -> onOffEff f g
CreateHeldLight -> createHeldLight CreateHeldLight -> createHeldLight
CreateShieldWall -> createShieldWall CreateShieldWall -> createShieldWall
@@ -24,24 +24,33 @@ onOffEff f g it
| _itIsHeld it = doInvEffect f it | _itIsHeld it = doInvEffect f it
| otherwise = doInvEffect g it | otherwise = doInvEffect g it
timeScrollEffect :: Item -> Creature -> World -> World --timeScrollEffect :: Item -> Creature -> World -> World
timeScrollEffect _ _ w = w & timeFlow .~ ScrollTimeFlow 0 --timeScrollEffect itm _ w = w & timeFlow .~ ScrollTimeFlow
-- { _scrollSmoothing = 0
-- , _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
-- , _futureWorlds = []
-- }
chargeIfInInventory :: Item -> Creature -> World -> World
chargeIfInInventory itm cr w =
w & ptrWpCharge %~ (min maxcharge . (+ 1))
where
invid = _ipInvID $ _itLocation itm
ptrWpCharge = cWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . leftConsumption . wpCharge
maxcharge = itm ^?! itUse . leftConsumption . wpMaxCharge
chargeIfEquipped :: Item -> Creature -> World -> World
chargeIfEquipped itm cr w
| Just invid == _crLeftInvSel cr =
w & ptrWpCharge %~ (min maxcharge . (+ 1))
| otherwise =
w & ptrWpCharge .~ 0
where
invid = _ipInvID $ _itLocation itm
ptrWpCharge = cWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . leftConsumption . wpCharge
maxcharge = itm ^?! itUse . leftConsumption . wpMaxCharge
rewindEffect :: Item -> Creature -> World -> World
rewindEffect _ _ w = w
--rewindEffect itm cr w =
-- | Just invid == _crLeftInvSel cr =
-- w & cwTime . rewindWorlds %~ (take maxcharge . (cw :))
-- & ptrWpCharge .~ length (w ^. cwTime . rewindWorlds)
-- | otherwise =
-- w & cwTime . rewindWorlds .~ []
-- & ptrWpCharge .~ 0
-- where
-- invid = _ipInvID $ _itLocation itm
-- ptrWpCharge = cWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . leftConsumption . wpCharge
-- maxcharge = itm ^?! itUse . leftConsumption . wpMaxCharge
-- cw =
-- _cWorld w
--resetAttachmentEffect :: Item -> Creature -> World -> World --resetAttachmentEffect :: Item -> Creature -> World -> World
--resetAttachmentEffect itm cr w --resetAttachmentEffect itm cr w
+1
View File
@@ -49,6 +49,7 @@ itemFromLeftType :: LeftItemType -> Item
itemFromLeftType lt = case lt of itemFromLeftType lt = case lt of
BOOSTER -> boosterGun BOOSTER -> boosterGun
REWINDER -> rewindGun REWINDER -> rewindGun
TIMESCROLLER -> timeScrollGun
BLINKER -> blinkGun BLINKER -> blinkGun
BLINKERUNSAFE -> unsafeBlinkGun BLINKERUNSAFE -> unsafeBlinkGun
SHRINKER -> shrinkGun SHRINKER -> shrinkGun
+19 -8
View File
@@ -1,11 +1,11 @@
module Dodge.Item.Weapon.Utility where module Dodge.Item.Weapon.Utility where
import Dodge.Default.Item.Use
import Control.Lens import Control.Lens
import Data.Maybe import Data.Maybe
import Dodge.Base.Coordinate import Dodge.Base.Coordinate
import Dodge.Data.World import Dodge.Data.World
import Dodge.Default import Dodge.Default
--import Dodge.Default.Item.Use
import Dodge.Wall.ForceField import Dodge.Wall.ForceField
import Dodge.Wall.Move import Dodge.Wall.Move
import Geometry import Geometry
@@ -16,23 +16,35 @@ import ShapePicture
timeScrollGun :: Item timeScrollGun :: Item
timeScrollGun = timeScrollGun =
defaultHeldItem defaultLeftItem
& itEffect . ieWhileAiming .~ TimeScrollEffect & itUse
.~ ( defaultLeftUse
& leftUse .~ LTimeScroll
& equipEffect . eeSite .~ GoesOnWrist
)
& itInvColor .~ cyan
& itEffect . ieInv .~ ChargeIfInInventory
& itType . iyBase .~ LEFT TIMESCROLLER
& itUse . leftConsumption
.~ ChargeableAmmo
{ _wpMaxCharge = 100
, _wpCharge = 0
}
rewindGun :: Item rewindGun :: Item
rewindGun = rewindGun =
defaultLeftItem defaultLeftItem
& itUse .~ & itUse
(defaultLeftUse .~ ( defaultLeftUse
& leftUse .~ LRewind --useRewindGun & leftUse .~ LRewind --useRewindGun
& equipEffect . eeSite .~ GoesOnWrist & equipEffect . eeSite .~ GoesOnWrist
) )
& itInvColor .~ cyan & itInvColor .~ cyan
& itEffect . ieInv .~ RewindEffect & itEffect . ieInv .~ ChargeIfEquipped
& itType . iyBase .~ LEFT REWINDER & itType . iyBase .~ LEFT REWINDER
& itUse . leftConsumption & itUse . leftConsumption
.~ ChargeableAmmo .~ ChargeableAmmo
{ _wpMaxCharge = 250 { _wpMaxCharge = 100
, _wpCharge = 0 , _wpCharge = 0
} }
@@ -66,7 +78,6 @@ unsafeBlinkGun =
& itUse . leftUse .~ LUnsafeBlink --hammerCheckL (shootL $ const unsafeBlinkAction) & itUse . leftUse .~ LUnsafeBlink --hammerCheckL (shootL $ const unsafeBlinkAction)
& itUse . equipEffect . eeViewDist ?~ 400 & itUse . equipEffect . eeViewDist ?~ 400
-- I believe because the targeting returns to nothing straight after you release -- I believe because the targeting returns to nothing straight after you release
-- the rmb, it is possible for this to do nothing -- the rmb, it is possible for this to do nothing
-- TODO investigate more and fix -- TODO investigate more and fix
+9
View File
@@ -14,11 +14,20 @@ useL :: Luse -> Item -> Creature -> World -> World
useL lu = case lu of useL lu = case lu of
LDoNothing -> const $ const id LDoNothing -> const $ const id
LRewind -> useRewindGun LRewind -> useRewindGun
LTimeScroll -> useTimeScrollGun
LShrink -> hammerCheckL useShrinkGun LShrink -> hammerCheckL useShrinkGun
LBlink -> hammerCheckL (shootL $ const blinkActionMousePos) LBlink -> hammerCheckL (shootL $ const blinkActionMousePos)
LUnsafeBlink -> hammerCheckL (shootL $ const unsafeBlinkAction) LUnsafeBlink -> hammerCheckL (shootL $ const unsafeBlinkAction)
LBoost -> boostSelfL 10 LBoost -> boostSelfL 10
useTimeScrollGun :: Item -> Creature -> World -> World
useTimeScrollGun itm _ w = w & timeFlow .~ ScrollTimeFlow
{ _scrollSmoothing = 0
, _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
, _futureWorlds = []
, _scrollItemLocation = _itID itm
}
useRewindGun :: Item -> Creature -> World -> World useRewindGun :: Item -> Creature -> World -> World
useRewindGun _ _ w = w useRewindGun _ _ w = w
--useRewindGun _ _ w = case w ^. cwTime . rewindWorlds of --useRewindGun _ _ w = case w ^. cwTime . rewindWorlds of
+37 -27
View File
@@ -6,7 +6,6 @@ Description : Simulation update
-} -}
module Dodge.Update (updateUniverse) where module Dodge.Update (updateUniverse) where
import StrictHelp
import Color import Color
--import Dodge.Zone --import Dodge.Zone
@@ -28,6 +27,7 @@ import Dodge.Flame
import Dodge.Flare import Dodge.Flare
import Dodge.Hammer import Dodge.Hammer
import Dodge.Inventory import Dodge.Inventory
import Dodge.Item.Location
import Dodge.Laser.Update import Dodge.Laser.Update
import Dodge.LightSource.Update import Dodge.LightSource.Update
import Dodge.LinearShockwave.Update import Dodge.LinearShockwave.Update
@@ -60,6 +60,7 @@ import LensHelp
--import MaybeHelp --import MaybeHelp
import SDL import SDL
import Sound.Data import Sound.Data
import StrictHelp
{- For most menus the only way to change the world is using event handling. -} {- For most menus the only way to change the world is using event handling. -}
updateUniverse :: Universe -> Universe updateUniverse :: Universe -> Universe
@@ -88,25 +89,15 @@ functionalUpdate'' = advanceScrollAmount . functionalUpdate'
functionalUpdate' :: Universe -> Universe functionalUpdate' :: Universe -> Universe
functionalUpdate' u = case u ^. uvWorld . timeFlow of functionalUpdate' u = case u ^. uvWorld . timeFlow of
NormalTimeFlow -> functionalUpdate u NormalTimeFlow -> functionalUpdate u
ScrollTimeFlow smoothing -> over uvWorld (doTimeScroll smoothing) u ScrollTimeFlow smoothing _ _ _ -> over uvWorld (doTimeScroll smoothing) u
_ -> u _ -> u
timeScrollAmount :: World -> Int
timeScrollAmount w
| x == 0 = 0
| x > 0 && y > 0 = x * y
| x < 0 && y < 0 = negate (x * y)
| otherwise = x
where
x = w ^. scrollAmount
y = w ^. previousScrollAmount
doTimeScroll :: Int -> World -> World doTimeScroll :: Int -> World -> World
doTimeScroll smoothing w = case timeScrollAmount w of doTimeScroll smoothing w = case w ^. scrollAmount of
x | x > 1 -> (foldr ($) w $ replicate x scrollTimeBack) & timeFlow . scrollSmoothing .~ 20 x | x > 1 -> w & scrollTimeBack & timeFlow . scrollSmoothing .~ 20
x | x > 0 -> foldr ($) w $ replicate x scrollTimeBack x | x > 0 -> w & scrollTimeBack & timeFlow . scrollSmoothing %~ max 0
x | x < (-1) -> (foldr ($) w $ replicate x scrollTimeForward) & timeFlow . scrollSmoothing .~ negate 20 x | x < (-1) -> w & scrollTimeForward & timeFlow . scrollSmoothing .~ negate 20
x | x < 0 -> foldr ($) w $ replicate (negate x) scrollTimeForward x | x < 0 -> w & scrollTimeForward & timeFlow . scrollSmoothing %~ min 0
_ | smoothing > 0 -> scrollTimeBack w & timeFlow . scrollSmoothing -~ 1 _ | smoothing > 0 -> scrollTimeBack w & timeFlow . scrollSmoothing -~ 1
_ | smoothing < 0 -> scrollTimeForward w & timeFlow . scrollSmoothing +~ 1 _ | smoothing < 0 -> scrollTimeForward w & timeFlow . scrollSmoothing +~ 1
_ -> w _ -> w
@@ -114,20 +105,33 @@ doTimeScroll smoothing w = case timeScrollAmount w of
scrollTimeBack :: World -> World scrollTimeBack :: World -> World
scrollTimeBack w = case w ^? cwTime . pastWorlds . _head of scrollTimeBack w = case w ^? cwTime . pastWorlds . _head of
Nothing -> w Nothing -> w
Just cw -> w & cwTime . pastWorlds %~ tail Just cw -> case w ^?! timeFlow . reverseAmount of
& cwTime . futureWorlds .:~ _cWorld w x | x > 0 ->
w & cwTime . pastWorlds %~ tail
& timeFlow . futureWorlds .:~ _cWorld w
& timeFlow . reverseAmount -~ 1
& cWorld .~ cw & cWorld .~ cw
& pointerToItemLocation (w ^?! cWorld . itemLocations . ix i) . itUse . leftConsumption . wpCharge .~ (x -1)
_ -> w
where
i = w ^?! timeFlow . scrollItemLocation
scrollTimeForward :: World -> World scrollTimeForward :: World -> World
scrollTimeForward w = case w ^? cwTime . futureWorlds . _head of scrollTimeForward w = case w ^? timeFlow . futureWorlds . _head of
Nothing -> w Nothing -> w
Just cw -> w & cwTime . futureWorlds %~ tail Just cw ->
w & timeFlow . futureWorlds %~ tail
& cwTime . pastWorlds .:~ _cWorld w & cwTime . pastWorlds .:~ _cWorld w
& cWorld .~ cw & cWorld .~ cw
& timeFlow . reverseAmount +~ 1
& pointerToItemLocation (w ^?! cWorld . itemLocations . ix i) . itUse . leftConsumption . wpCharge +~ 1
where
i = w ^?! timeFlow . scrollItemLocation
-- | The update step. -- | The update step.
functionalUpdate :: Universe -> Universe functionalUpdate :: Universe -> Universe
functionalUpdate w = checkEndGame functionalUpdate w =
checkEndGame
-- . updateRandGen -- . updateRandGen
. over uvWorld (mouseButtons . each .~ True) -- to determine if the mouse button is held . over uvWorld (mouseButtons . each .~ True) -- to determine if the mouse button is held
. over uvWorld (cwTime . worldClock +~ 1) . over uvWorld (cwTime . worldClock +~ 1)
@@ -186,7 +190,8 @@ functionalUpdate w = checkEndGame
$ over uvWorld updatePastWorlds w $ over uvWorld updatePastWorlds w
advanceScrollAmount :: Universe -> Universe advanceScrollAmount :: Universe -> Universe
advanceScrollAmount u = u advanceScrollAmount u =
u
& uvWorld . previousScrollAmount .~ _scrollAmount (_uvWorld u) & uvWorld . previousScrollAmount .~ _scrollAmount (_uvWorld u)
& uvWorld . scrollAmount .~ 0 & uvWorld . scrollAmount .~ 0
@@ -196,6 +201,7 @@ updatePastWorlds w = w & cwTime . pastWorlds %~ (forceFoldable . take 100 . (_cW
moveHammersUp :: Universe -> Universe moveHammersUp :: Universe -> Universe
--moveHammersUp = uvWorld . hammers .~ M.empty --moveHammersUp = uvWorld . hammers .~ M.empty
moveHammersUp = uvWorld . hammers %~ M.map moveHammerUp moveHammersUp = uvWorld . hammers %~ M.map moveHammerUp
--moveHammersUp = uvWorld . hammers . each %~ (moveHammerUp $!) --moveHammersUp = uvWorld . hammers . each %~ (moveHammerUp $!)
--moveHammersUp = uvWorld %~ ( (hammers . each %~ (moveHammerUp $!)) $!) --moveHammersUp = uvWorld %~ ( (hammers . each %~ (moveHammerUp $!)) $!)
--moveHammersUp uv = uv { _uvWorld = w' } --moveHammersUp uv = uv { _uvWorld = w' }
@@ -225,13 +231,17 @@ zoneClouds w =
updateWorldSelect :: World -> World updateWorldSelect :: World -> World
updateWorldSelect w = f . g $ case (w ^? mouseButtons . ix ButtonLeft, w ^? mouseButtons . ix ButtonRight) of updateWorldSelect w = f . g $ case (w ^? mouseButtons . ix ButtonLeft, w ^? mouseButtons . ix ButtonRight) of
(Just False, Nothing) -> w & lLine . _1 .~ mwp (Just False, Nothing) ->
w & lLine . _1 .~ mwp
& lrLine . _1 .~ mwp & lrLine . _1 .~ mwp
(Just True, Nothing) -> w & lLine . _2 .~ mwp (Just True, Nothing) ->
w & lLine . _2 .~ mwp
& lrLine . _1 .~ mwp & lrLine . _1 .~ mwp
(Nothing,Just False) -> w & rLine . _1 .~ mwp (Nothing, Just False) ->
w & rLine . _1 .~ mwp
& lrLine . _2 .~ mwp & lrLine . _2 .~ mwp
(Nothing,Just True) -> w & rLine . _2 .~ mwp (Nothing, Just True) ->
w & rLine . _2 .~ mwp
& lrLine . _2 .~ mwp & lrLine . _2 .~ mwp
_ -> w _ -> w
where where
+2 -2
View File
@@ -53,10 +53,10 @@ pressedMBEffectsNoInventory :: M.Map MouseButton Bool -> World -> World
pressedMBEffectsNoInventory pkeys w pressedMBEffectsNoInventory pkeys w
| isDown ButtonLeft && isDown ButtonRight && inTopInv = | isDown ButtonLeft && isDown ButtonRight && inTopInv =
useItem (you w) w & hammers . ix DoubleMouseHam .~ HammerDown useItem (you w) w & hammers . ix DoubleMouseHam .~ HammerDown
| isDown ButtonLeft && (inTopInv || _timeFlow w == RewindingLastFrame) | isDown ButtonLeft && inTopInv
&& w ^?! hammers . ix DoubleMouseHam == HammerUp = && w ^?! hammers . ix DoubleMouseHam == HammerUp =
useLeftItem (_yourID (_cWorld w)) w useLeftItem (_yourID (_cWorld w)) w
| isDown ButtonLeft && (inTopInv || _timeFlow w == RewindingLastFrame) = | isDown ButtonLeft && inTopInv =
w & hammers . ix DoubleMouseHam .~ HammerDown w & hammers . ix DoubleMouseHam .~ HammerDown
| isDown ButtonRight && inTopInv = w | isDown ButtonRight && inTopInv = w
| isDown ButtonMiddle = | isDown ButtonMiddle =