Refactoring, linting
This commit is contained in:
@@ -17,11 +17,13 @@ import Control.Monad
|
||||
Displays the item name, ammo if loaded, and any selected '_itCharMode'.
|
||||
-}
|
||||
basicWeaponDisplay :: Item -> String
|
||||
basicWeaponDisplay it = case it ^? itAttachment . _Just . itCharMode of
|
||||
Just (c :<| _) -> midPadL 10 ' ' (_itName it) (' ' : aIfLoaded) ++ [' ',c]
|
||||
basicWeaponDisplay it = case it ^? itAttachment . _Just of
|
||||
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)
|
||||
where
|
||||
availableAmmo = show $ _wpMaxAmmo it
|
||||
aIfLoaded = case _wpReloadState it of
|
||||
0 -> show $ _wpLoadedAmmo it
|
||||
x -> "R" ++ show x
|
||||
aIfLoaded = case it ^? wpReloadState of
|
||||
Just 0 -> show $ _wpLoadedAmmo it
|
||||
Just x -> "R" ++ show x
|
||||
_ -> ""
|
||||
|
||||
@@ -197,7 +197,6 @@ withMuzFlare f cid w = tempLightForAt 3 pos . muzzleFlashAt pos2 $ f cid w
|
||||
dir = _crDir cr
|
||||
pos = _crPos cr +.+ _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. -}
|
||||
withRandomDir
|
||||
@@ -213,8 +212,8 @@ withRandomDir acc f cid w = over (creatures . ix cid . crDir) (\d -> d - a)
|
||||
$ set randGen g
|
||||
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
|
||||
:: Point2 -- ^ Velocity, x direction is forward with respect to the creature
|
||||
-> Float -- ^ Bullet width
|
||||
@@ -231,7 +230,8 @@ withVelWthHiteff vel width hiteff cid w
|
||||
dir = _crDir cr
|
||||
pos = _crPos cr +.+ _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
|
||||
:: Float -- ^ Max possible translate
|
||||
-> (Int -> World -> World)
|
||||
@@ -249,7 +249,6 @@ withRandomOffset offsetAmount f cid w
|
||||
(offsetVal , g) = randomR (-offsetAmount,offsetAmount) $ _randGen w
|
||||
cr = _creatures w IM.! cid
|
||||
offV = rotateV (_crDir cr) (0,offsetVal)
|
||||
|
||||
-- | Rotates a creature with minimum rotation at least 0.1.
|
||||
-- Rotates the player creature before applying the effect, other creatures after.
|
||||
torqueBeforeForced
|
||||
@@ -269,7 +268,6 @@ torqueBeforeForced torque feff cid w
|
||||
(rot, g) = randomR (-torque,torque) $ _randGen w
|
||||
rot' | rot < 0 = rot - 0.1
|
||||
| otherwise = rot + 0.1
|
||||
|
||||
-- | Rotates the player creature before applying an effect.
|
||||
-- Note this currently (29/4/2021) rotates other creatures /after/ applying the effect.
|
||||
torqueBefore
|
||||
|
||||
@@ -6,6 +6,7 @@ module Dodge.Item.Weapon.UseEffect
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Item.Weapon.Decoration
|
||||
import Dodge.Item.Weapon.TriggerType
|
||||
import Dodge.WorldEvent.Flash
|
||||
import Dodge.WorldEvent.ThingsHit
|
||||
import Picture
|
||||
@@ -102,9 +103,97 @@ mvRadar x p w pt = (putBlips w, Just $ pt {_ptDraw = const pic
|
||||
++ (IM.elems $ wallsAlongCirc p r w)
|
||||
r = fromIntegral (800 - x*16)
|
||||
sweepPics = [--colHelper 0.1 $ uncurry translate p $ thickCircle r 15
|
||||
--,colHelper 0.06 $ uncurry translate p $ thickCircle (r-5) 5
|
||||
--,colHelper 0.03 $ uncurry translate p $ thickCircle (r-10) 5
|
||||
--,colHelper 0.06 $ uncurry translate p $ thickCircle (r-5) 5
|
||||
--,colHelper 0.03 $ uncurry translate p $ thickCircle (r-10) 5
|
||||
]
|
||||
globalAlpha | x > 10 = 1
|
||||
| otherwise = fromIntegral x / 10
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user