diff --git a/src/Dodge/Base.hs b/src/Dodge/Base.hs index fe3666ed7..c38abc786 100644 --- a/src/Dodge/Base.hs +++ b/src/Dodge/Base.hs @@ -537,3 +537,6 @@ evenOddSplit :: [a] -> ([a],[a]) evenOddSplit = foldr f ([],[]) where f a (ls,rs) = (rs, a : ls) + +dbArg :: (a -> a -> b) -> a -> b +dbArg f x = f x x diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 6aa6b5321..59d1d33ae 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -384,7 +384,7 @@ data Projectile { _pjPos :: Point2 , _pjStartPos :: Point2 , _pjVel :: Point2 - , _pjPict :: Picture + , _pjDraw :: Projectile -> Picture , _pjID :: Int , _pjUpdate :: World -> World } @@ -392,7 +392,7 @@ data Projectile { _pjPos :: Point2 , _pjStartPos :: Point2 , _pjVel :: Point2 - , _pjPict :: Picture + , _pjDraw :: Projectile -> Picture , _pjID :: Int , _pjUpdate :: World -> World , _pjPayload :: Point2-> World -> World diff --git a/src/Dodge/Debug.hs b/src/Dodge/Debug.hs index e9220f326..d2a4943be 100644 --- a/src/Dodge/Debug.hs +++ b/src/Dodge/Debug.hs @@ -14,7 +14,7 @@ drawCircleAtFor p t w = w & projectiles %~ { _pjPos = p , _pjStartPos = p , _pjVel = (0,0) - , _pjPict = onLayer PtLayer $ uncurry translate p $ color white $ circleSolid 20 + , _pjDraw = \_ -> onLayer PtLayer $ uncurry translate p $ color white $ circleSolid 20 , _pjID = k , _pjUpdate = pjTimer t k } @@ -26,7 +26,7 @@ drawCircleAtForCol p t col w = w & projectiles %~ { _pjPos = p , _pjStartPos = p , _pjVel = (0,0) - , _pjPict = onLayer PtLayer $ uncurry translate p $ color col $ circleSolid 20 + , _pjDraw = \_ -> onLayer PtLayer $ uncurry translate p $ color col $ circleSolid 20 , _pjID = k , _pjUpdate = pjTimer t k } @@ -38,7 +38,7 @@ drawLineForCol ps t col w = w & projectiles %~ { _pjPos = head ps , _pjStartPos = head ps , _pjVel = (0,0) - , _pjPict = onLayer PtLayer $ color col $ lineOfThickness 5 ps + , _pjDraw = \_ -> onLayer PtLayer $ color col $ lineOfThickness 5 ps , _pjID = k , _pjUpdate = pjTimer t k } diff --git a/src/Dodge/Default.hs b/src/Dodge/Default.hs index 9977b00bb..d9818d27c 100644 --- a/src/Dodge/Default.hs +++ b/src/Dodge/Default.hs @@ -206,7 +206,7 @@ defaultPT = Projectile { _pjPos = (0,0) , _pjStartPos = (0,0) , _pjVel = (0,0) - , _pjPict = blank + , _pjDraw = \_ -> blank , _pjID = 0 , _pjUpdate = id } diff --git a/src/Dodge/Item/Weapon.hs b/src/Dodge/Item/Weapon.hs index 864e7697b..888010f78 100644 --- a/src/Dodge/Item/Weapon.hs +++ b/src/Dodge/Item/Weapon.hs @@ -638,7 +638,7 @@ makeShellAt pl i cid pos dir = Shell { _pjPos = pos , _pjStartPos = pos , _pjVel = rotateV dir (1,0) - , _pjPict = blank + , _pjDraw = \_ -> blank , _pjID = i , _pjUpdate = moveShell 50 i cid 0 (rotateV dir (3,0)) , _pjPayload = pl @@ -656,21 +656,21 @@ moveShell time i cid rot accel w then doExplode else w & projectiles . ix i . pjPos %~ (+.+ vel) - & projectiles . ix i . pjPict .~ piclow + & projectiles . ix i . pjDraw .~ (\_ -> piclow) & projectiles . ix i . pjUpdate .~ moveShell (time-1) i cid rot (rotateV rot accel) | isJust thingHit = doExplode | time == 35 = w & projectiles . ix i . pjPos %~ (+.+ vel) - & projectiles . ix i . pjPict .~ pic + & projectiles . ix i . pjDraw .~ (\_ -> pic) & projectiles . ix i . pjUpdate .~ moveShell (time-1) i cid spin accel | time >= 20 = w & projectiles . ix i . pjPos %~ (+.+ vel) - & projectiles . ix i . pjPict .~ pic + & projectiles . ix i . pjDraw .~ (\_ -> pic) & projectiles . ix i . pjUpdate .~ moveShell (time-1) i cid rot' (rotateV rot accel) | time > -99 = w & projectiles . ix i . pjPos %~ (+.+ vel) & randGen .~ g - & projectiles . ix i . pjPict .~ pic + & projectiles . ix i . pjDraw .~ (\_ -> pic) & projectiles . ix i . pjUpdate .~ moveShell (time-1) i cid rot' (rotateV rot accel) & projectiles . ix i . pjVel %~ (\v -> accel +.+ frict *.* v) & soundFromPos (ShellSound i) newPos (fromIntegral smokeTrailSound) 1 250 @@ -678,7 +678,7 @@ moveShell time i cid rot accel w & smokeGen | time > -200 = w & projectiles . ix i . pjPos %~ (+.+ vel) - & projectiles . ix i . pjPict .~ pic + & projectiles . ix i . pjDraw .~ (\_ -> pic) & projectiles . ix i . pjUpdate .~ moveShell (time-1) i cid rot' (rotateV rot accel) | otherwise = doExplode where @@ -828,8 +828,8 @@ moveRemoteBomb itid time pID w f x | x < -369 = -10 | otherwise = x - 1 updatePicture = - set (projectiles . ix pID.pjPict) - (onLayer PtLayer $ uncurry translate newPos $ remoteBombPic time) + set (projectiles . ix pID . pjDraw) + (\_ -> onLayer PtLayer $ uncurry translate newPos $ remoteBombPic time) . lowLightDirected (withAlpha 0.1 red) newPos @@ -914,7 +914,7 @@ fireRemoteLauncher cr w = setLocation { _pjPos = pos , _pjStartPos = pos , _pjVel = rotateV dir (1,0) - , _pjPict = blank + , _pjDraw = \_ -> blank , _pjID = i , _pjUpdate = moveRemoteShell 50 i cid itid dir } @@ -936,7 +936,7 @@ moveRemoteShell time i cid itid _ w | time > 40 = if circOnSomeWall oldPos 4 w then doExplosion w else over (projectiles . ix i . pjPos) (+.+ vel) - $ set (projectiles . ix i . pjPict) piclow + $ set (projectiles . ix i . pjDraw) (\_ -> piclow) $ set (projectiles . ix i . pjUpdate) (moveRemoteShell (time-1) i cid itid newdir) $ setScope @@ -944,7 +944,7 @@ moveRemoteShell time i cid itid _ w | time >= 20 = case thingHit of Just _ -> doExplosion w Nothing -> over (projectiles . ix i . pjPos) (+.+ vel) - $ set (projectiles . ix i . pjPict) pic + $ set (projectiles . ix i . pjDraw) (\_ -> pic) $ set (projectiles . ix i . pjUpdate) (moveRemoteShell (time-1) i cid itid newdir) $ setScope @@ -955,7 +955,7 @@ moveRemoteShell time i cid itid _ w w Nothing -> over (projectiles . ix i . pjPos) (+.+ vel) $ set randGen g - $ set (projectiles . ix i . pjPict) pic + $ set (projectiles . ix i . pjDraw) (\_ -> pic) $ set (projectiles . ix i . pjUpdate) (moveRemoteShell (time-1) i cid itid newdir) $ over (projectiles . ix i . pjVel) (\v -> accel +.+ frict *.* v) $ soundFromPos (ShellSound i) newPos (fromIntegral smokeTrailSound) 1 250 @@ -968,7 +968,7 @@ moveRemoteShell time i cid itid _ w $ stopSoundFrom (ShellSound i) w Nothing -> over (projectiles . ix i . pjPos) (+.+ vel) - $ set (projectiles . ix i . pjPict) pic + $ set (projectiles . ix i . pjDraw) (\_ -> pic) $ set (projectiles . ix i . pjUpdate) (moveRemoteShell (time-1) i cid itid newdir) $ setScope w @@ -1014,7 +1014,7 @@ explodeRemoteRocket -> World explodeRemoteRocket itid pjid w = set (projectiles . ix pjid . pjUpdate) (retireRemoteRocket itid 30 pjid) - $ set (projectiles . ix pjid . pjPict) blank + $ set (projectiles . ix pjid . pjDraw) (\_ -> blank) $ set (itPoint . itUse) (const id) $ resetName $ makeExplosionAt (_pjPos (_projectiles w IM.! pjid)) w @@ -1034,7 +1034,7 @@ throwRemoteBomb cr w = setLocation { _pjPos = p , _pjStartPos = p , _pjVel = v - , _pjPict = blank + , _pjDraw = \_ -> blank , _pjID = i , _pjUpdate = moveRemoteBomb itid 50 i } @@ -1062,7 +1062,7 @@ throwRemoteBomb cr w = setLocation explodeRemoteBomb :: Int -> Int -> Creature -> World -> World explodeRemoteBomb itid pjid cr w = set (projectiles . ix pjid . pjUpdate) (retireRemoteBomb itid 30 pjid) - $ set (projectiles . ix pjid . pjPict) blank + $ set (projectiles . ix pjid . pjDraw) (\_ -> blank) $ set (creatures . ix cid . crInv . ix j . itUse) (const id) $ resetName $ resetPict diff --git a/src/Dodge/Item/Weapon/Grenade.hs b/src/Dodge/Item/Weapon/Grenade.hs index 1283d2d88..4f72b5226 100644 --- a/src/Dodge/Item/Weapon/Grenade.hs +++ b/src/Dodge/Item/Weapon/Grenade.hs @@ -32,8 +32,8 @@ moveGrenade time dir pID w = case hitWl of _ -> updatedWorld where updatedWorld = updateV $ set (projectiles . ix pID . pjPos) finalPos - $ set (projectiles .ix pID.pjPict) - (onLayer PtLayer $ uncurry translate newPos + $ set (projectiles .ix pID. pjDraw) + (\ _ -> onLayer PtLayer $ uncurry translate newPos $ rotate dir $ grenadePic time) $ set (projectiles .ix pID.pjUpdate) (moveGrenade (time-1) dir pID) w pj = _projectiles w IM.! pID @@ -67,7 +67,7 @@ throwGrenade explosion cr w = setWp $ removePict $ over projectiles addG w { _pjPos = p , _pjStartPos = p , _pjVel = v - , _pjPict = onLayer PtLayer $ uncurry translate p $ grenadePic 0 + , _pjDraw = \_ -> onLayer PtLayer $ uncurry translate p $ grenadePic 0 , _pjID = i , _pjUpdate = moveGrenade fuseTime dir i , _pjPayload = explosion diff --git a/src/Dodge/Item/Weapon/UseEffect.hs b/src/Dodge/Item/Weapon/UseEffect.hs index 09d4270f3..0cf33ce4c 100644 --- a/src/Dodge/Item/Weapon/UseEffect.hs +++ b/src/Dodge/Item/Weapon/UseEffect.hs @@ -126,7 +126,7 @@ tractorBeamAt colID i pos dir = Projectile { _pjPos = pos , _pjStartPos = p' , _pjVel = d - , _pjPict = blank + , _pjDraw = \_ -> blank , _pjID = i , _pjUpdate = updateTractor colID 10 i } @@ -139,7 +139,7 @@ The interaction of this with objects, walls etc needs more thought. -} updateTractor :: Int -> Int -> Int -> World -> World updateTractor colID time i w | time > 0 = set (projectiles . ix i . pjUpdate) (updateTractor colID (time-1) i) - $ set (projectiles . ix i . pjPict) pic + $ set (projectiles . ix i . pjDraw) (\_ -> pic) $ over creatures (IM.map tractCr) $ over floorItems (IM.map tractFlIt) w diff --git a/src/Dodge/Render/Picture.hs b/src/Dodge/Render/Picture.hs index 8f84cee16..011e31ca9 100644 --- a/src/Dodge/Render/Picture.hs +++ b/src/Dodge/Render/Picture.hs @@ -16,13 +16,13 @@ import qualified Data.IntMap.Strict as IM worldPictures :: World -> Picture worldPictures w = pictures $ concat [ IM.elems $ _decorations w - , map _pjPict . IM.elems $ _projectiles w + , map (dbArg _pjDraw) . IM.elems $ _projectiles w , map drawItem . IM.elems $ _floorItems w , map crDraw . IM.elems $ _creatures w , map clDraw . reverse . IM.elems $ _clouds w , map ppDraw . IM.elems $ _pressPlates w , map btDraw (IM.elems (_buttons w)) - , map (\pt -> _ptDraw pt pt) $ _particles w + , map (dbArg _ptDraw) $ _particles w , map drawWallFloor (wallFloorsToDraw w) , testPic w ] diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index 10f172cf8..52b5b245e 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -42,7 +42,7 @@ For most menus the only way to change the world is using event handling. -} update' :: World -> World update' w = case _menuLayers w of (WaitMessage s i: _) - | i < 1 -> w & doubleArgumentFor _worldEvents + | i < 1 -> w & dbArg _worldEvents | otherwise -> w & menuLayers %~ ( (WaitMessage s (i-1) :) . tail ) (GameOverMenu : _) -> updateParticles . updateProjectiles @@ -60,7 +60,7 @@ update' w = case _menuLayers w of . zoneCreatures . updateWalls . set worldEvents id - . doubleArgumentFor _worldEvents + . dbArg _worldEvents . updateParticles . updateProjectiles . updateLightSources @@ -83,7 +83,6 @@ update' w = case _menuLayers w of where (x,y) = cloudZoneOfPoint $ _clPos cr cid = _clID cr - doubleArgumentFor f x = f x x updateCreatureGroups :: World -> World updateCreatureGroups w = w & creatureGroups %~ diff --git a/src/Dodge/WorldEvent/SpawnParticle.hs b/src/Dodge/WorldEvent/SpawnParticle.hs index 78968fb82..d5b05bd31 100644 --- a/src/Dodge/WorldEvent/SpawnParticle.hs +++ b/src/Dodge/WorldEvent/SpawnParticle.hs @@ -246,7 +246,7 @@ makeTeslaArcAt i pos dir = Projectile { _pjPos = pos , _pjStartPos = pos , _pjVel = (0,0) - , _pjPict = onLayer PtLayer $ line [(0,0),(0,0)] + , _pjDraw = \_ -> onLayer PtLayer $ line [(0,0),(0,0)] , _pjID = i , _pjUpdate = moveTeslaArc pos dir i } @@ -258,7 +258,7 @@ moveTeslaArc -> World -> World moveTeslaArc p d i w = - set (projectiles . ix i . pjPict) pic + set (projectiles . ix i . pjDraw) (\_ -> pic) $ set (projectiles . ix i . pjUpdate) (pjTimer 2 i) $ set randGen g