Refactoring, linting

This commit is contained in:
2021-04-30 15:22:24 +02:00
parent c8e84c775f
commit 83c2220813
6 changed files with 205 additions and 263 deletions
+2 -3
View File
@@ -265,9 +265,8 @@ Items you start with.
startInventory = IM.fromList (zip [0..20] startInventory = IM.fromList (zip [0..20]
( (
[lasGun [lasGun
,autoGun ,remoteLauncher
,flamer ,grenade
--,blinkGun
--,spawnGun lamp --,spawnGun lamp
--,poisonSprayer --,poisonSprayer
--,autoGun --,autoGun
-1
View File
@@ -15,7 +15,6 @@ data ItAttachment
,_scopeIsCamera :: Bool ,_scopeIsCamera :: Bool
} }
| ItFuse {_itFuseTime :: Int} | ItFuse {_itFuseTime :: Int}
| ItPhaseV {_itPhaseV :: Float}
| ItMode {_itMode :: Int} | ItMode {_itMode :: Int}
| ItCharMode {_itCharMode :: Seq.Seq Char } | ItCharMode {_itCharMode :: Seq.Seq Char }
| ItTargetPos { _itTargetPos :: Point2 } | ItTargetPos { _itTargetPos :: Point2 }
+101 -246
View File
@@ -220,7 +220,7 @@ forceFieldGun = defaultGun
, _wpReloadState = 0 , _wpReloadState = 0
, _wpFireRate = 10 , _wpFireRate = 10
, _wpFireState = 0 , _wpFireState = 0
, _wpFire = forceFieldFire , _wpFire = undefined
, _wpSpread = 0.02 , _wpSpread = 0.02
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = onLayer FlItLayer $ polygon [(-4,-4),(-4,4),(4,4),(4,0),(0,0),(0,-4)] , _itFloorPict = onLayer FlItLayer $ polygon [(-4,-4),(-4,4),(4,4),(4,0),(0,0),(0,-4)]
@@ -364,7 +364,7 @@ remoteLauncher = defaultGun
, _wpReloadState = 0 , _wpReloadState = 0
, _wpFireRate = 10 , _wpFireRate = 10
, _wpFireState = 0 , _wpFireState = 0
, _wpFire = fireRemoteLauncher , _wpFire = hammerCheck $ fireRemoteLauncher
, _wpSpread = 0.02 , _wpSpread = 0.02
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = onLayer FlItLayer $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5) , _itFloorPict = onLayer FlItLayer $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5)
@@ -386,7 +386,6 @@ hvAutoGun = defaultAutoGun
, _wpFireState = 0 , _wpFireState = 0
, _wpFire = rateIncAB 24 10 (torqueBeforeForced 0.1 mkHvBul) , _wpFire = rateIncAB 24 10 (torqueBeforeForced 0.1 mkHvBul)
$ torqueAfter 0.2 mkHvBul $ torqueAfter 0.2 mkHvBul
, _wpSpread = autogunSpread
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = onLayer FlItLayer $ color orange $ polygon $ rectNESW 5 5 (-5) (-5) , _itFloorPict = onLayer FlItLayer $ color orange $ polygon $ rectNESW 5 5 (-5) (-5)
, _itAmount = 1 , _itAmount = 1
@@ -442,7 +441,6 @@ miniGun = defaultAutoGun
. withMuzFlare . withMuzFlare
. withVelWthHiteff (30,0) 2 . withVelWthHiteff (30,0) 2
$ destroyOnImpact bulBounceArmCr' bulHitWall' bulHitFF' $ destroyOnImpact bulBounceArmCr' bulHitWall' bulHitFF'
, _wpSpread = autogunSpread
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = onLayer FlItLayer $ color red $ polygon $ rectNESW 9 5 (-9) (-5) , _itFloorPict = onLayer FlItLayer $ color red $ polygon $ rectNESW 9 5 (-9) (-5)
, _itAmount = 1 , _itAmount = 1
@@ -593,7 +591,7 @@ flamer = defaultAutoGun
, _wpReloadState = 0 , _wpReloadState = 0
, _wpFireRate = 0 , _wpFireRate = 0
, _wpFireState = 0 , _wpFireState = 0
, _wpFire = shoot $ withSidePushAfter 10 $ randWalkAngle 0.5 0.05 aFlame , _wpFire = shoot $ withSidePush 5 $ withSidePushAfter 10 $ randWalkAngle 0.5 0.05 aFlame
, _wpSpread = 0 , _wpSpread = 0
, _wpRange = 8 , _wpRange = 8
, _itFloorPict = onLayer FlItLayer $ color yellow $ polygon $ rectNESW 4 4 (-4) (-4) , _itFloorPict = onLayer FlItLayer $ color yellow $ polygon $ rectNESW 4 4 (-4) (-4)
@@ -659,16 +657,6 @@ charToPhaseV 'V' = 0.2
charToPhaseV '/' = 1 charToPhaseV '/' = 1
charToPhaseV 'Z' = 5 charToPhaseV 'Z' = 5
aTractorBeam :: Int -> Int -> World -> World
aTractorBeam col cid w
= set (creatures . ix cid . crInv . ix itRef . wpFire)
(shoot $ aTractorBeam ((col + 1) `mod` 10))
$ over projectiles (IM.insert i (tractorBeamAt col i pos dir)) w
where i = newProjectileKey w
cr = (_creatures w IM.! cid)
pos = _crPos cr +.+ ((_crRad cr +10) *.* unitVectorAtAngle dir)
dir = _crDir cr
itRef = _crInvSel cr
aRocketWithPayload aRocketWithPayload
:: (Point2 -> World -> World) :: (Point2 -> World -> World)
@@ -779,19 +767,6 @@ remoteShellPic i | rem (i+200) 20 < 9 = polygon [(-6,4),(-6,-4),(6,-4),(8,0),(6,
shellExplosionAt = makeExplosionAt shellExplosionAt = makeExplosionAt
tractorBeamAt :: Int -> Int -> Point2 -> Float -> Projectile
tractorBeamAt colID i pos dir = Projectile
{ _pjPos = pos
, _pjStartPos = p'
, _pjVel = d
, _pjPict = blank
, _pjID = i
, _pjUpdate = updateTractor colID 10 i
}
where
d = unitVectorAtAngle dir
p' = pos +.+ 400 *.* d
aGasCloud :: Int -> World -> World aGasCloud :: Int -> World -> World
aGasCloud cid w aGasCloud cid w
= insertCloud $ set randGen g $ = insertCloud $ set randGen g $
@@ -857,7 +832,7 @@ retireRemoteRocket itid 0 pjid w
= set (pointToItem (_itemPositions w IM.! itid) . itAttachment . _Just . scopePos) = set (pointToItem (_itemPositions w IM.! itid) . itAttachment . _Just . scopePos)
(0,0) (0,0)
$ set (pointToItem (_itemPositions w IM.! itid) . wpFire) $ set (pointToItem (_itemPositions w IM.! itid) . wpFire)
fireRemoteLauncher (hammerCheck fireRemoteLauncher)
(w & projectiles %~ IM.delete pjid) (w & projectiles %~ IM.delete pjid)
retireRemoteRocket itid t pjid w = setScope w & projectiles . ix pjid . pjUpdate .~ retireRemoteRocket itid (t-1) pjid retireRemoteRocket itid t pjid w = setScope w & projectiles . ix pjid . pjUpdate .~ retireRemoteRocket itid (t-1) pjid
where where
@@ -875,7 +850,7 @@ retireRemoteBomb itid 0 pjid w
$ set (pointToItem (_itemPositions w IM.! itid) . itZoom) $ set (pointToItem (_itemPositions w IM.! itid) . itZoom)
defaultItZoom defaultItZoom
$ set (pointToItem (_itemPositions w IM.! itid) . twFire) $ set (pointToItem (_itemPositions w IM.! itid) . twFire)
throwRemoteBomb (hammerCheck throwRemoteBomb)
(w & projectiles %~ IM.delete pjid) (w & projectiles %~ IM.delete pjid)
retireRemoteBomb itid t pjid w retireRemoteBomb itid t pjid w
= setScope w & projectiles . ix pjid . pjUpdate .~ retireRemoteBomb itid (t-1) pjid = setScope w & projectiles . ix pjid . pjUpdate .~ retireRemoteBomb itid (t-1) pjid
@@ -1101,7 +1076,7 @@ grenade = Throwable
, _itFloorPict = onLayer FlItLayer $ polygon [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = onLayer FlItLayer $ polygon [(-3,-3),(-3,3),(3,3),(3,-3)]
, _twMaxRange = 150 , _twMaxRange = 150
, _twAccuracy = 30 , _twAccuracy = 30
, _twFire = throwGrenade fuseTime , _twFire = throwGrenade' makeExplosionAt fuseTime
, _itAimingSpeed = 1 , _itAimingSpeed = 1
, _itAimingRange = 0 , _itAimingRange = 0
, _itZoom = defaultItZoom {_itAimZoomMax = (f fuseTime), _itAimZoomMin = (f fuseTime)} , _itZoom = defaultItZoom {_itAimZoomMax = (f fuseTime), _itAimZoomMin = (f fuseTime)}
@@ -1139,7 +1114,6 @@ teslaGrenade = grenade {
increaseFuse :: Int -> Int -> World -> World increaseFuse :: Int -> Int -> World -> World
increaseFuse fuse i w = w & creatures . ix 0 . crInv . ix itRef . itScrollUp .~ decreaseFuse newTime increaseFuse fuse i w = w & creatures . ix 0 . crInv . ix itRef . itScrollUp .~ decreaseFuse newTime
& creatures . ix 0 . crInv . ix itRef . itScrollDown .~ increaseFuse newTime & creatures . ix 0 . crInv . ix itRef . itScrollDown .~ increaseFuse newTime
& creatures . ix 0 . crInv . ix itRef . twFire .~ throwGrenade newTime
& creatures . ix 0 . crInv . ix itRef . itName .~ "GRENADE " ++ show newTime & creatures . ix 0 . crInv . ix itRef . itName .~ "GRENADE " ++ show newTime
& creatures . ix 0 . crInv . ix itRef . itAttachment .~ Just (ItFuse newTime) & creatures . ix 0 . crInv . ix itRef . itAttachment .~ Just (ItFuse newTime)
& creatures . ix 0 . crInv . ix itRef . itZoom & creatures . ix 0 . crInv . ix itRef . itZoom
@@ -1151,7 +1125,6 @@ increaseFuse fuse i w = w & creatures . ix 0 . crInv . ix itRef . itScrollUp .~
decreaseFuse :: Int -> Int -> World -> World decreaseFuse :: Int -> Int -> World -> World
decreaseFuse fuse i w = w & creatures . ix 0 . crInv . ix itRef . itScrollUp .~ decreaseFuse newTime decreaseFuse fuse i w = w & creatures . ix 0 . crInv . ix itRef . itScrollUp .~ decreaseFuse newTime
& creatures . ix 0 . crInv . ix itRef . itScrollDown .~ increaseFuse newTime & creatures . ix 0 . crInv . ix itRef . itScrollDown .~ increaseFuse newTime
& creatures . ix 0 . crInv . ix itRef . twFire .~ throwGrenade newTime
& creatures . ix 0 . crInv . ix itRef . itName .~ "GRENADE " ++ show newTime & creatures . ix 0 . crInv . ix itRef . itName .~ "GRENADE " ++ show newTime
& creatures . ix 0 . crInv . ix itRef . itAttachment .~ Just (ItFuse newTime) & creatures . ix 0 . crInv . ix itRef . itAttachment .~ Just (ItFuse newTime)
& creatures . ix 0 . crInv . ix itRef . itZoom & creatures . ix 0 . crInv . ix itRef . itZoom
@@ -1169,9 +1142,9 @@ remoteBomb = defaultThrowable
, _itFloorPict = onLayer FlItLayer $ polygon [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = onLayer FlItLayer $ polygon [(-3,-3),(-3,3),(3,3),(3,-3)]
, _twMaxRange = 150 , _twMaxRange = 150
, _twAccuracy = 30 , _twAccuracy = 30
, _twFire = throwRemoteBomb , _twFire = hammerCheck $ throwRemoteBomb
, _itAttachment = Just $ ItScope (0,0) 0 1 True , _itAttachment = Just $ ItScope (0,0) 0 1 True
, _itEquipPict = drawWeapon $ remoteBombUnarmedPic , _itEquipPict = drawWeapon remoteBombUnarmedPic
} }
@@ -1204,36 +1177,34 @@ throwGrenade' explosion fuseTime n w = setWp $ removePict $ over projectiles add
setWp :: World -> World setWp :: World -> World
setWp w' = w' & creatures . ix n . crInv . ix j . itEffect .~ throwArmReset 20 setWp w' = w' & creatures . ix n . crInv . ix j . itEffect .~ throwArmReset 20
throwGrenade :: Int -> Int -> World -> World
throwGrenade = throwGrenade' makeExplosionAt
throwArmReset :: Int -> ItEffect throwArmReset :: Int -> ItEffect
throwArmReset x = throwArmReset x = ItInvEffect {_itInvEffect = f ,_itEffectCounter = x }
ItInvEffect {_itInvEffect = f where
,_itEffectCounter = x f cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust counterDown i
} counterDown it
where f cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust counterDown i | _itEffectCounter (_itEffect it) == 0 = it
counterDown it | _itEffectCounter (_itEffect it) == 0 & itHammer .~ HammerUp
= it & itHammer .~ HammerUp & itEquipPict .~ drawWeapon (grenadePic 50)
& itEquipPict .~ (drawWeapon $ grenadePic 50) | otherwise = it & itEffect . itEffectCounter -~ 1
| otherwise = it & itEffect . itEffectCounter %~ (\x -> x - 1)
(grenadeAccL, grenadeAccA) = (0.1, 0.1) (grenadeAccL, grenadeAccA) = (0.1, 0.1)
grenadePic :: Int -> Picture grenadePic :: Int -> Picture
grenadePic x = pictures [ color (dark $ dark green) $ circleSolid 5 grenadePic x = pictures
, color green $ arc [ color (dark $ dark green) $ circleSolid 5
(degToRad $ (179 * fromIntegral x / 50) - 180 ) , color green $ arc (degToRad $ (179 * fromIntegral x / 50) - 180 )
(degToRad $ 180 - (179 * fromIntegral x / 50) ) (degToRad $ 180 - (179 * fromIntegral x / 50) )
5 5
, translate (-2) 2 $ rotate (pi*0.5) , translate (-2) 2 $ rotate (pi*0.5)
$ scale 0.05 0.05 $ color green $ text $ show $ 1 + quot x 20 $ scale 0.05 0.05 $ color green $ text $ show $ 1 + quot x 20
] ]
fireRemoteLauncher :: Int -> World -> World fireRemoteLauncher :: Int -> World -> World
fireRemoteLauncher cid w = setLocation $ resetFire $ resetName fireRemoteLauncher cid w = setLocation
$ soundOnce (fromIntegral launcherSound) $ resetFire
$ over projectiles remRocket w $ resetName
$ soundOnce (fromIntegral launcherSound)
$ over projectiles remRocket w
where where
i = newKey $ _projectiles w i = newKey $ _projectiles w
cr = _creatures w IM.! cid cr = _creatures w IM.! cid
@@ -1250,13 +1221,14 @@ fireRemoteLauncher cid w = setLocation $ resetFire $ resetName
j = _crInvSel $ _creatures w IM.! cid j = _crInvSel $ _creatures w IM.! cid
newitid = newKey $ _itemPositions w newitid = newKey $ _itemPositions w
maybeitid = w ^? creatures . ix cid . crInv . ix j . itID . _Just maybeitid = w ^? creatures . ix cid . crInv . ix j . itID . _Just
resetFire = set (creatures . ix cid . crInv . ix j . wpFire) $ explodeRemoteRocket itid i resetFire = set (creatures . ix cid . crInv . ix j . wpFire)
$ hammerCheck $ explodeRemoteRocket itid i
resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTEROCKET" resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTEROCKET"
setLocation :: World -> World setLocation :: World -> World
setLocation w' = case maybeitid of setLocation w' = case maybeitid of
Nothing -> w' & creatures . ix cid . crInv . ix j . itID .~ Just newitid Nothing -> w' & creatures . ix cid . crInv . ix j . itID ?~ newitid
& itemPositions %~ IM.insert newitid (InInv cid j) & itemPositions %~ IM.insert newitid (InInv cid j)
_ -> w' _ -> w'
itid = fromMaybe newitid maybeitid itid = fromMaybe newitid maybeitid
moveRemoteShell :: Int -> Int -> Int -> Int -> Float -> World -> World moveRemoteShell :: Int -> Int -> Int -> Int -> Float -> World -> World
@@ -1270,68 +1242,64 @@ moveRemoteShell time i cid itid dir w
$ setScope $ setScope
w w
| time >= 20 = case thingHit of | time >= 20 = case thingHit of
Just p -> doExplosion w Just p -> doExplosion w
Nothing -> over (projectiles . ix i . pjPos) (+.+ vel) Nothing -> over (projectiles . ix i . pjPos) (+.+ vel)
$ set (projectiles . ix i . pjPict) pic $ set (projectiles . ix i . pjPict) pic
$ set (projectiles . ix i . pjUpdate) $ set (projectiles . ix i . pjUpdate)
(moveRemoteShell (time-1) i cid itid newdir) (moveRemoteShell (time-1) i cid itid newdir)
$ setScope $ setScope
w w
| time > -99 | time > -99 = case thingHit of
= case thingHit of Just p -> doExplosion
Just p -> doExplosion $ stopSoundFrom (ShellSound i)
$ stopSoundFrom (ShellSound i) w
w Nothing -> over (projectiles . ix i . pjPos) (+.+ vel)
Nothing -> over (projectiles . ix i . pjPos) (+.+ vel) $ set randGen g
$ set randGen g $ set (projectiles . ix i . pjPict) pic
$ set (projectiles . ix i . pjPict) pic $ set (projectiles . ix i . pjUpdate) (moveRemoteShell (time-1) i cid itid newdir)
$ set (projectiles . ix i . pjUpdate) $ over (projectiles . ix i . pjVel) (\v -> accel +.+ frict *.* v)
(moveRemoteShell (time-1) i cid itid newdir) $ soundFromPos (ShellSound i) newPos (fromIntegral smokeTrailSound) 1 250
$ over (projectiles . ix i . pjVel) (\v -> accel +.+ frict *.* v) $ smokeGen
$ soundFromPos (ShellSound i) newPos (fromIntegral smokeTrailSound) (1) 250 $ makeFlameletTimed oldPos (0.5 *.* rotateV (pi+sparkD) accel) Nothing 3 10
$ smokeGen $ setScope
$ makeFlameletTimed oldPos w
(0.5 *.* rotateV (pi+sparkD) accel) Nothing 3 10
$ setScope
w
| time > -200 = case thingHit of | time > -200 = case thingHit of
Just p -> doExplosion Just p -> doExplosion
$ stopSoundFrom (ShellSound i) $ stopSoundFrom (ShellSound i)
w w
Nothing -> over (projectiles . ix i . pjPos) (+.+ vel) Nothing -> over (projectiles . ix i . pjPos) (+.+ vel)
$ set (projectiles . ix i . pjPict) pic $ set (projectiles . ix i . pjPict) pic
$ set (projectiles . ix i . pjUpdate) $ set (projectiles . ix i . pjUpdate) (moveRemoteShell (time-1) i cid itid newdir)
(moveRemoteShell (time-1) i cid itid newdir) $ setScope
$ setScope w
w
| otherwise = doExplosion | otherwise = doExplosion
$ stopSoundFrom (ShellSound i) $ stopSoundFrom (ShellSound i)
w w
where where
pj = _projectiles w IM.! i pj = _projectiles w IM.! i
oldPos = _pjPos pj oldPos = _pjPos pj
vel = _pjVel pj vel = _pjVel pj
newPos = oldPos +.+ vel newPos = oldPos +.+ vel
newdir newdir
| SDL.ButtonRight `S.member` (_mouseButtons w) | SDL.ButtonRight `S.member` _mouseButtons w
&& w ^? creatures . ix cid . crInvSel == w ^? itemPositions . ix itid . itInvId && w ^? creatures . ix cid . crInvSel == w ^? itemPositions . ix itid . itInvId
= _cameraRot w + (argV $ _mousePos w) = _cameraRot w + argV (_mousePos w)
| otherwise = dir | otherwise = dir
accel = rotateV newdir (2,0) accel = rotateV newdir (2,0)
(frict,g) = randomR (0.6,0.9) $ _randGen w (frict,g) = randomR (0.6,0.9) $ _randGen w
(sparkD,_) = randomR (-0.5,0.5) $ _randGen w (sparkD,_) = randomR (-0.5,0.5) $ _randGen w
dir = argV $ vel dir = argV vel
pic = onLayer PtLayer $ uncurry translate newPos pic = onLayer PtLayer $ uncurry translate newPos
$ rotate (argV accel) $ remoteShellPic time $ rotate (argV accel) $ remoteShellPic time
piclow = onLayerL [levLayer CrLayer - 2] piclow = onLayerL [levLayer CrLayer - 2]
$ uncurry translate newPos $ rotate (argV accel) $ uncurry translate newPos $ rotate (argV accel)
$ remoteShellPic time $ remoteShellPic time
hitCr = fmap fst $ collideCircCrsPoint oldPos newPos 4 w hitCr = fst <$> collideCircCrsPoint oldPos newPos 4 w
hitWl = fmap fst $ collideCircWalls' oldPos newPos 2 $ wallsNearPoint newPos w hitWl = fst <$> collideCircWalls' oldPos newPos 2 (wallsNearPoint newPos w)
thingHit = hitCr <|> hitWl thingHit = hitCr <|> hitWl
r1 = _randGen w & evalState (randInCirc 10) r1 = _randGen w & evalState (randInCirc 10)
smokeGen = makeSmokeCloudAt (oldPos +.+ r1 +.+ 30 *.* (normalizeV (oldPos -.- newPos))) smokeGen = makeSmokeCloudAt $ oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos)
doExplosion = explodeRemoteRocket itid i cid doExplosion = explodeRemoteRocket itid i cid
setScope w' = case _itemPositions w' IM.! itid of setScope w' = case _itemPositions w' IM.! itid of
InInv cid invid InInv cid invid
@@ -1368,12 +1336,14 @@ throwRemoteBomb n w = setLocation $ removePict $ resetFire
--(l, _) = randomR (1 - grenadeAccL,1+grenadeAccL) (_randGen w) --(l, _) = randomR (1 - grenadeAccL,1+grenadeAccL) (_randGen w)
--(a, g) = randomR (-grenadeAccA,grenadeAccA) (_randGen w) --(a, g) = randomR (-grenadeAccA,grenadeAccA) (_randGen w)
v' = 0.02 / _cameraZoom w *.* rotateV (_cameraRot w) ( _mousePos w) v' = 0.02 / _cameraZoom w *.* rotateV (_cameraRot w) ( _mousePos w)
v | magV v' > 6 = 6 *.* normalizeV v' v | magV v' > 6 = 6 *.* normalizeV v'
| otherwise = v'
-- zoom = 1 / _cameraZoom w -- zoom = 1 / _cameraZoom w
j = _crInvSel $ _creatures w IM.! n j = _crInvSel $ _creatures w IM.! n
resetName = set (creatures . ix n . crInv . ix j . itName) "REMOTE" resetName = set (creatures . ix n . crInv . ix j . itName) "REMOTE"
removePict = set (creatures . ix n . crInv . ix j . itEquipPict) $ \ _ _ -> blank removePict = set (creatures . ix n . crInv . ix j . itEquipPict) $ \ _ _ -> blank
resetFire = set (creatures . ix n . crInv . ix j . twFire) $ explodeRemoteBomb itid i resetFire = set (creatures . ix n . crInv . ix j . twFire)
$ hammerCheck $ explodeRemoteBomb itid i
cr = _creatures w IM.! n cr = _creatures w IM.! n
p' = _crPos cr +.+ rotateV (_crDir cr) (_crRad cr,0) p' = _crPos cr +.+ rotateV (_crDir cr) (_crRad cr,0)
p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (_crRad cr-4,0) p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (_crRad cr-4,0)
@@ -1381,13 +1351,12 @@ throwRemoteBomb n w = setLocation $ removePict $ resetFire
maybeitid = w ^? creatures . ix n . crInv . ix j . itID . _Just maybeitid = w ^? creatures . ix n . crInv . ix j . itID . _Just
setLocation :: World -> World setLocation :: World -> World
setLocation w' = case maybeitid of setLocation w' = case maybeitid of
Nothing -> w' & creatures . ix n . crInv . ix j . itID .~ Just newitid Nothing -> w' & creatures . ix n . crInv . ix j . itID ?~ newitid
& itemPositions %~ IM.insert newitid (InInv n j) & itemPositions %~ IM.insert newitid (InInv n j)
_ -> w' _ -> w'
newitid = newKey $ _itemPositions w newitid = newKey $ _itemPositions w
itid = fromMaybe newitid maybeitid itid = fromMaybe newitid maybeitid
explodeRemoteBomb :: Int -> Int -> Int -> World -> World explodeRemoteBomb :: Int -> Int -> Int -> World -> World
explodeRemoteBomb itid pjid n w explodeRemoteBomb itid pjid n w
= set (projectiles . ix pjid . pjUpdate) (retireRemoteBomb itid 30 pjid) = set (projectiles . ix pjid . pjUpdate) (retireRemoteBomb itid 30 pjid)
@@ -1401,28 +1370,19 @@ explodeRemoteBomb itid pjid n w
where where
resetName = set (creatures . ix n . crInv . ix j . itName) "REMOTEBOMB" resetName = set (creatures . ix n . crInv . ix j . itName) "REMOTEBOMB"
resetPict = set (creatures . ix n . crInv . ix j . itEquipPict ) resetPict = set (creatures . ix n . crInv . ix j . itEquipPict )
(drawWeapon $ remoteBombUnarmedPic) (drawWeapon remoteBombUnarmedPic)
-- resetScope = creatures . ix n . crInv . ix j . itScope . _Just . scopePos .~ (0,0) -- resetScope = creatures . ix n . crInv . ix j . itScope . _Just . scopePos .~ (0,0)
j = _crInvSel $ _creatures w IM.! n j = _crInvSel $ _creatures w IM.! n
remoteBombPic :: Int -> Picture remoteBombPic :: Int -> Picture
remoteBombPic x = pictures [ color (dark $ dark orange) $ circleSolid 5 remoteBombPic x = pictures
, rotate (0 - degToRad (fromIntegral x * 10 + 45)) $ color red $ arc 0 (pi/2) 5 [ color (dark $ dark orange) $ circleSolid 5
, rotate (0 - degToRad (fromIntegral x * 10 + 45)) $ color (withAlpha 0.05 red) ]
$ arcSolid 0 90 50
, rotate (0 - degToRad (fromIntegral x * 10 + 20)) $ color (withAlpha 0.05 red)
$ arcSolid 0 40 40
, rotate (0 - degToRad (fromIntegral x * 10 + 10)) $ color (withAlpha 0.05 red)
$ arcSolid 0 20 20
]
remoteBombUnarmedPic :: Picture remoteBombUnarmedPic :: Picture
remoteBombUnarmedPic = color (dark $ dark orange) $ circleSolid 5 remoteBombUnarmedPic = color (dark $ dark orange) $ circleSolid 5
spreadGunSpread,autogunSpread :: Float spreadGunSpread,autogunSpread :: Float
spreadGunSpread = 0.5 spreadGunSpread = 0.5
autogunSpread = 0.07 autogunSpread = 0.07
pipe = Craftable pipe = Craftable
{ _itIdentity = Generic { _itIdentity = Generic
, _itName = "PIPE" , _itName = "PIPE"
@@ -1449,155 +1409,52 @@ flameShield = defaultEquipment
, _itMaxStack = 1 , _itMaxStack = 1
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = onLayer FlItLayer $ polygon [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = onLayer FlItLayer $ polygon [(-3,-3),(-3,3),(3,3),(3,-3)]
, _itEquipPict = (\cr _ -> onLayer CrLayer $ , _itEquipPict = \cr _ -> onLayer CrLayer $ pictures [color cyan $ circle (_crRad cr+2)]
pictures [color cyan $ circle (_crRad cr+2)]
)
, _itID = Nothing , _itID = Nothing
} }
{- |
Slows you down, blocks forward projectiles. -}
frontArmour = defaultEquipment frontArmour = defaultEquipment
{ _itIdentity = FrontArmour { _itIdentity = FrontArmour
, _itName = "FARMOUR" , _itName = "FARMOUR"
, _itMaxStack = 1 , _itMaxStack = 1
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = onLayer FlItLayer $ translate 0 (-5) , _itFloorPict = onLayer FlItLayer $ translate 0 (-5) $ pictures
$ pictures [color (greyN 0.1) $ thickArc 0 (pi/2) 10 5 [color (greyN 0.1) $ thickArc 0 (pi/2) 10 5
,color (greyN 0.1) $ thickArc (3*pi/2) (2*pi) 10 5 ,color (greyN 0.1) $ thickArc (3*pi/2) (2*pi) 10 5
] ]
, _itEquipPict = (\cr _ -> onLayer CrLayer , _itEquipPict = \cr _ -> onLayer CrLayer $ pictures
$ pictures [color (greyN 0.1) $ thickArc 0 (pi/2) 10 5 [color (greyN 0.1) $ thickArc 0 (pi/2) 10 5
,color (greyN 0.1) $ thickArc (3*pi/2) (2*pi) 10 5 ,color (greyN 0.1) $ thickArc (3*pi/2) (2*pi) 10 5
] ]
)
, _itEffect = NoItEffect , _itEffect = NoItEffect
, _itID = Nothing , _itID = Nothing
} }
{- |
Increases speed, reduces friction, cannot only move forwards. -}
jetPack = defaultEquipment jetPack = defaultEquipment
{ _itIdentity = JetPack { _itIdentity = JetPack
, _itName = "JETPACK" , _itName = "JETPACK"
, _itMaxStack = 1 , _itMaxStack = 1
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = onLayer FlItLayer $ color yellow $ polygon [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = onLayer FlItLayer $ color yellow $ polygon [(-3,-3),(-3,3),(3,3),(3,-3)]
, _itEquipPict = (\cr _ -> onLayer CrLayer , _itEquipPict = \_ _ -> onLayer CrLayer
$ pictures [color yellow $ polygon $ rectNSEW 5 (-5) (-3) (-11) $ pictures [color yellow $ polygon $ rectNSEW 5 (-5) (-3) (-11) ]
]
)
, _itEffect = NoItEffect , _itEffect = NoItEffect
, _itID = Nothing , _itID = Nothing
} }
{- |
Current thickness: 2 -}
-- }}}
forceFieldFire :: Int -> World -> World
forceFieldFire cid w = w
--shatterGunFire :: Int -> World -> World
--shatterGunFire n w | fireCondition = -- soundOnce 0
-- set (creatures . ix n . crInv . ix itRef . wpFireState)
-- (_wpFireRate (_crInv cr IM.! itRef))
-- $ over (creatures . ix n . crInv . ix itRef . wpLoadedAmmo)
-- (\x -> x - 1)
-- $ over projectiles (IM.insert i $ makeTremorAt i pos dir) w
-- | reloadCondition = let remAmmo = _crAmmo cr M.! _wpAmmoType item
-- (newA,newTotalA) = moveInt (_wpMaxAmmo item) remAmmo
-- in set (pointerToItem . wpReloadState) rTime
-- $ set (pointerToItem . wpLoadedAmmo) newA
-- $ over (creatures . ix n . crAmmo )
-- (M.insert (_wpAmmoType item) newTotalA) w
-- | emptyCondition = soundOnce 1 w
-- | otherwise = w
-- where i = newProjectileKey w
-- cr = (_creatures w IM.! n)
-- pos = _crPos cr +.+ ((_crRad cr +1) *.* unitVectorAtAngle dir)
-- dir = _crDir cr
-- --(colID, _) = randomR (0,11) (_randGen w)
-- itRef = _crInvSel cr
-- item = _crInv cr IM.! itRef
-- pointerToItem = creatures . ix n . crInv . ix itRef
-- rTime = _wpReloadTime (_crInv cr IM.! itRef)
-- fireCondition = _wpReloadState (_crInv cr IM.! itRef) == 0
-- && _wpFireState (_crInv cr IM.! itRef) == 0
-- && _wpLoadedAmmo (_crInv cr IM.! itRef) > 0
-- reloadCondition = _wpReloadState (_crInv cr IM.! itRef) == 0
-- && _wpLoadedAmmo (_crInv cr IM.! itRef) == 0
-- && someJust (_crAmmo cr M.!? PistolBullet)
-- emptyCondition = _wpLoadedAmmo (_crInv cr IM.! itRef) == 0
--for reloading, we take from the total ammo
moveInt :: Int -> Int -> (Int,Int)
moveInt toReload totalAmmo = (x, totalAmmo-x)
where x = min toReload totalAmmo
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
$ over creatures (IM.map tractCr)
$ over floorItems (IM.map tractFlIt)
w
| otherwise = over projectiles (IM.delete i) w
where tractCr cr | circOnSeg p1 p2 cP 10
= over crPos (\p ->
p -.- m *.* ((0.3/ x) *.* q +.+ (f y *.* p4))
) cr
| otherwise = cr
where x = abs y + 1
y = errorClosestPointOnLineParam 1 p1 p3 cP
cP = _crPos cr
m | dist cP p1 < 350 = 1
| otherwise = (400 - dist cP p1) / 50
tractFlIt it | circOnSeg p1 p2 iP 10
= over flItPos (\p -> p -.- m *.*
( (0.3/ x) *.* q +.+ (f y *.* p4))
) it
| otherwise = it
where x = abs y + 1
y = errorClosestPointOnLineParam 2 p1 p3 iP
iP = _flItPos it
m | dist iP p1 < 350 = 1
| otherwise = (410 - dist iP p1) / 60
pj = _projectiles w IM.! i
q = _pjVel pj
p1 = _pjPos pj
p' = _pjStartPos pj
p2 = fromMaybe p' $ fmap fst $ collidePointWalls p1 p' $ wallsNearPoint p' w
p4 = vNormal p5
p5 = errorNormalizeV 12 $ p2 -.- p1
p3 = p1 +.+ p4
g x | x > 5 = (10 - x) / 5
| x > 1 = 1
| x > -1 = x
| x > -5 = -1
| otherwise = (x - 10) / 5
d = errorNormalizeV 13 $ p' -.- p1
f x = g x / 50
cID = fromIntegral colID / 10
col = mixColors 0.5 0.5 white blue
px z = (fromIntegral time + 5) *.* z
pz z = fromIntegral time * 10 *.* z
pic = onLayer PtLayer $ color (withAlpha 0.05 col)
$ polygon [ p1 +.+ px p4
, p1 -.- 10 *.* p5
, p1 -.- px p4
, (p' -.- pz p5) -.- px p4
, (p' -.- pz p5) +.+ px p4]
thickLine :: [Point2] -> Picture thickLine :: [Point2] -> Picture
thickLine = lineOfThickness 2 thickLine = lineOfThickness 2
{- |
Current thickness: 3 -}
vThickLine :: [Point2] -> Picture vThickLine :: [Point2] -> Picture
vThickLine = lineOfThickness 3 vThickLine = lineOfThickness 3
{- |
Current thickness: 6 -}
vvThickLine :: [Point2] -> Picture vvThickLine :: [Point2] -> Picture
vvThickLine = lineOfThickness 6 vvThickLine = lineOfThickness 6
thinLine :: [Point2] -> Picture
thinLine = lineOfThickness 1
someJust (Just x) | x > 0 = True
| otherwise = False
{- | {- |
Sends out pulses that display walls. -} Sends out pulses that display walls. -}
radar = defaultGun radar = defaultGun
@@ -1632,7 +1489,6 @@ sonar = defaultGun
, _wpFireRate = 120 , _wpFireRate = 120
, _wpFireState = 0 , _wpFireState = 0
, _wpFire = shoot aSonarPulse , _wpFire = shoot aSonarPulse
, _wpSpread = autogunSpread
, _wpRange = 20 , _wpRange = 20
, _itHammer = HammerUp , _itHammer = HammerUp
, _itFloorPict = onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) , _itFloorPict = onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
@@ -1684,7 +1540,6 @@ spawnGun cr = defaultGun
, _wpFireRate = 100 , _wpFireRate = 100
, _wpFire = spawnCrNextTo cr , _wpFire = spawnCrNextTo cr
} }
spawnCrNextTo spawnCrNextTo
:: Creature -- ^ Creature to spawn :: Creature -- ^ Creature to spawn
-> Int -- ^ ID of existing creature that will be spawned next to -> Int -- ^ ID of existing creature that will be spawned next to
+7 -5
View File
@@ -17,11 +17,13 @@ import Control.Monad
Displays the item name, ammo if loaded, and any selected '_itCharMode'. Displays the item name, ammo if loaded, and any selected '_itCharMode'.
-} -}
basicWeaponDisplay :: Item -> String basicWeaponDisplay :: Item -> String
basicWeaponDisplay it = case it ^? itAttachment . _Just . itCharMode of basicWeaponDisplay it = case it ^? itAttachment . _Just of
Just (c :<| _) -> midPadL 10 ' ' (_itName it) (' ' : aIfLoaded) ++ [' ',c] Just ItCharMode {_itCharMode = (c :<| _)} -> midPadL 10 ' ' (_itName it) (' ' : aIfLoaded) ++ [' ',c]
Just ItMode {_itMode = i} -> midPadL 10 ' ' (_itName it) (' ' : aIfLoaded) ++ show i
_ -> midPadL 10 ' ' (_itName it) (' ' : aIfLoaded) _ -> midPadL 10 ' ' (_itName it) (' ' : aIfLoaded)
where where
availableAmmo = show $ _wpMaxAmmo it availableAmmo = show $ _wpMaxAmmo it
aIfLoaded = case _wpReloadState it of aIfLoaded = case it ^? wpReloadState of
0 -> show $ _wpLoadedAmmo it Just 0 -> show $ _wpLoadedAmmo it
x -> "R" ++ show x Just x -> "R" ++ show x
_ -> ""
+4 -6
View File
@@ -197,7 +197,6 @@ withMuzFlare f cid w = tempLightForAt 3 pos . muzzleFlashAt pos2 $ f cid w
dir = _crDir cr dir = _crDir cr
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr) pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr) pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr)
{- | {- |
Rotates the creature randomly, applies the effect, rotates the creature back. -} Rotates the creature randomly, applies the effect, rotates the creature back. -}
withRandomDir withRandomDir
@@ -213,8 +212,8 @@ withRandomDir acc f cid w = over (creatures . ix cid . crDir) (\d -> d - a)
$ set randGen g $ set randGen g
w w
where (a, g) = randomR (-acc,acc) $ _randGen w where (a, g) = randomR (-acc,acc) $ _randGen w
{- | Creates a bullet with a given velocity, width, and 'HitEffect' {- |
-} Creates a bullet with a given velocity, width, and 'HitEffect' -}
withVelWthHiteff withVelWthHiteff
:: Point2 -- ^ Velocity, x direction is forward with respect to the creature :: Point2 -- ^ Velocity, x direction is forward with respect to the creature
-> Float -- ^ Bullet width -> Float -- ^ Bullet width
@@ -231,7 +230,8 @@ withVelWthHiteff vel width hiteff cid w
dir = _crDir cr dir = _crDir cr
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr) pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr) pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr)
{- | Translate the creature sideways a random amount, apply the effect, translate back. -} {- |
Translate the creature sideways a random amount, apply the effect, translate back. -}
withRandomOffset withRandomOffset
:: Float -- ^ Max possible translate :: Float -- ^ Max possible translate
-> (Int -> World -> World) -> (Int -> World -> World)
@@ -249,7 +249,6 @@ withRandomOffset offsetAmount f cid w
(offsetVal , g) = randomR (-offsetAmount,offsetAmount) $ _randGen w (offsetVal , g) = randomR (-offsetAmount,offsetAmount) $ _randGen w
cr = _creatures w IM.! cid cr = _creatures w IM.! cid
offV = rotateV (_crDir cr) (0,offsetVal) offV = rotateV (_crDir cr) (0,offsetVal)
-- | Rotates a creature with minimum rotation at least 0.1. -- | Rotates a creature with minimum rotation at least 0.1.
-- Rotates the player creature before applying the effect, other creatures after. -- Rotates the player creature before applying the effect, other creatures after.
torqueBeforeForced torqueBeforeForced
@@ -269,7 +268,6 @@ torqueBeforeForced torque feff cid w
(rot, g) = randomR (-torque,torque) $ _randGen w (rot, g) = randomR (-torque,torque) $ _randGen w
rot' | rot < 0 = rot - 0.1 rot' | rot < 0 = rot - 0.1
| otherwise = rot + 0.1 | otherwise = rot + 0.1
-- | Rotates the player creature before applying an effect. -- | Rotates the player creature before applying an effect.
-- Note this currently (29/4/2021) rotates other creatures /after/ applying the effect. -- Note this currently (29/4/2021) rotates other creatures /after/ applying the effect.
torqueBefore torqueBefore
+91 -2
View File
@@ -6,6 +6,7 @@ module Dodge.Item.Weapon.UseEffect
import Dodge.Data import Dodge.Data
import Dodge.Base import Dodge.Base
import Dodge.Item.Weapon.Decoration import Dodge.Item.Weapon.Decoration
import Dodge.Item.Weapon.TriggerType
import Dodge.WorldEvent.Flash import Dodge.WorldEvent.Flash
import Dodge.WorldEvent.ThingsHit import Dodge.WorldEvent.ThingsHit
import Picture import Picture
@@ -102,9 +103,97 @@ mvRadar x p w pt = (putBlips w, Just $ pt {_ptDraw = const pic
++ (IM.elems $ wallsAlongCirc p r w) ++ (IM.elems $ wallsAlongCirc p r w)
r = fromIntegral (800 - x*16) r = fromIntegral (800 - x*16)
sweepPics = [--colHelper 0.1 $ uncurry translate p $ thickCircle r 15 sweepPics = [--colHelper 0.1 $ uncurry translate p $ thickCircle r 15
--,colHelper 0.06 $ uncurry translate p $ thickCircle (r-5) 5 --,colHelper 0.06 $ uncurry translate p $ thickCircle (r-5) 5
--,colHelper 0.03 $ uncurry translate p $ thickCircle (r-10) 5 --,colHelper 0.03 $ uncurry translate p $ thickCircle (r-10) 5
] ]
globalAlpha | x > 10 = 1 globalAlpha | x > 10 = 1
| otherwise = fromIntegral x / 10 | otherwise = fromIntegral x / 10
colHelper y = color (withAlpha (y * globalAlpha) red) colHelper y = color (withAlpha (y * globalAlpha) red)
aTractorBeam
:: Int -- ^ Color id
-> Int -- ^ Creature id
-> World
-> World
aTractorBeam col cid w
= set (creatures . ix cid . crInv . ix itRef . wpFire)
(shoot $ aTractorBeam ((col + 1) `mod` 10))
$ over projectiles (IM.insert i (tractorBeamAt col i pos dir)) w
where
i = newProjectileKey w
cr = (_creatures w IM.! cid)
pos = _crPos cr +.+ ((_crRad cr +10) *.* unitVectorAtAngle dir)
dir = _crDir cr
itRef = _crInvSel cr
tractorBeamAt :: Int -> Int -> Point2 -> Float -> Projectile
tractorBeamAt colID i pos dir = Projectile
{ _pjPos = pos
, _pjStartPos = p'
, _pjVel = d
, _pjPict = blank
, _pjID = i
, _pjUpdate = updateTractor colID 10 i
}
where
d = unitVectorAtAngle dir
p' = pos +.+ 400 *.* d
{- |
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
$ over creatures (IM.map tractCr)
$ over floorItems (IM.map tractFlIt)
w
| otherwise = over projectiles (IM.delete i) w
where
tractCr cr
| circOnSeg p1 p2 cP 10
= over crPos (\p ->
p -.- m *.* ((0.3/ x) *.* q +.+ (f y *.* p4))
) cr
| otherwise = cr
where
x = abs y + 1
y = errorClosestPointOnLineParam 1 p1 p3 cP
cP = _crPos cr
m | dist cP p1 < 350 = 1
| otherwise = (400 - dist cP p1) / 50
tractFlIt it | circOnSeg p1 p2 iP 10
= over flItPos (\p -> p -.- m *.*
( (0.3/ x) *.* q +.+ (f y *.* p4))
) it
| otherwise = it
where x = abs y + 1
y = errorClosestPointOnLineParam 2 p1 p3 iP
iP = _flItPos it
m | dist iP p1 < 350 = 1
| otherwise = (410 - dist iP p1) / 60
pj = _projectiles w IM.! i
q = _pjVel pj
p1 = _pjPos pj
p' = _pjStartPos pj
p2 = maybe p' fst $ collidePointWalls p1 p' $ wallsNearPoint p' w
p4 = vNormal p5
p5 = errorNormalizeV 12 $ p2 -.- p1
p3 = p1 +.+ p4
g x | x > 5 = (10 - x) / 5
| x > 1 = 1
| x > -1 = x
| x > -5 = -1
| otherwise = (x - 10) / 5
d = errorNormalizeV 13 $ p' -.- p1
f x = g x / 50
cID = fromIntegral colID / 10
col = mixColors 0.5 0.5 white blue
px z = (fromIntegral time + 5) *.* z
pz z = fromIntegral time * 10 *.* z
pic = setLayer 1 $ onLayer PtLayer $ color (withAlpha 0.05 col)
$ polygon [ p1 +.+ px p4
, p1 -.- 10 *.* p5
, p1 -.- px p4
, (p' -.- pz p5) -.- px p4
, (p' -.- pz p5) +.+ px p4]