Linting, refactor random angle walk for flamer
This commit is contained in:
+36
-201
@@ -1,4 +1,4 @@
|
||||
{-
|
||||
{- |
|
||||
Definitions of weapons.
|
||||
In progress: move out effects into other modules.
|
||||
-}
|
||||
@@ -16,9 +16,11 @@ import Dodge.WorldEvent
|
||||
import Dodge.Default
|
||||
import Dodge.Item.Draw
|
||||
import Dodge.Item.Weapon.Bullet
|
||||
import Dodge.Item.Weapon.Decoration
|
||||
import Dodge.Item.Weapon.InventoryDisplay
|
||||
import Dodge.Item.Weapon.TriggerType
|
||||
import Dodge.Item.Weapon.Recock
|
||||
import Dodge.Item.Weapon.ExtraEffect
|
||||
import Dodge.Item.Weapon.UseEffect
|
||||
import Dodge.Item.Attachment.Data
|
||||
import Dodge.Item.Attachment
|
||||
import Geometry
|
||||
@@ -410,7 +412,7 @@ ltAutoGun = defaultAutoGun
|
||||
, _wpFireRate = 4
|
||||
, _wpFireState = 0
|
||||
, _wpFire = shootWithSound 0 . withRandomDir 0.3 . withSidePush 50
|
||||
. withMuzFlare $ withVelWthHiteff (30,0) 2 bulletEffect'
|
||||
. withMuzFlare $ withVelWthHiteff (30,0) 2 basicBulletEffect
|
||||
, _wpSpread = 0.5
|
||||
, _wpRange = 20
|
||||
, _itFloorPict = onLayer FlItLayer $ color green $ pictures [polygon $ rectNSWE 4 (-4) (-4) 0
|
||||
@@ -461,7 +463,7 @@ spreadGun = defaultGun
|
||||
, _wpFire = shootWithSound (fromIntegral shotgunSound)
|
||||
. withRecoil 100
|
||||
. withMuzFlare
|
||||
$ spreadNumVelWthHiteff spreadGunSpread 9 (30,0) 2 bulletEffect'
|
||||
$ spreadNumVelWthHiteff spreadGunSpread 9 (30,0) 2 basicBulletEffect
|
||||
, _wpSpread = spreadGunSpread
|
||||
, _wpRange = 20
|
||||
, _itFloorPict = onLayer FlItLayer $ color green $ pictures [ polygon [(-3,0),(3,6),(3,-6)]
|
||||
@@ -504,7 +506,7 @@ multGun = defaultGun
|
||||
, _wpFire = shootWithSound (fromIntegral shotgunSound)
|
||||
. withRecoil 200
|
||||
. withMuzFlare
|
||||
$ numVelWthHitEff 5 (50,0) 5 bulletEffect'
|
||||
$ numVelWthHitEff 5 (50,0) 5 basicBulletEffect
|
||||
, _wpSpread = spreadGunSpread
|
||||
, _wpRange = 20
|
||||
, _itFloorPict = onLayer FlItLayer $ multGunPic
|
||||
@@ -571,7 +573,7 @@ poisonSprayer = defaultAutoGun
|
||||
, _wpFireRate = 0
|
||||
, _wpFireState = 0
|
||||
, _wpFire = shoot $ aGasCloud
|
||||
, _wpSpread = flamerAngle
|
||||
, _wpSpread = 0.3
|
||||
, _wpRange = 8
|
||||
, _itFloorPict = onLayer FlItLayer $ color yellow $ polygon $ rectNESW 4 4 (-4) (-4)
|
||||
, _itAmount = 1
|
||||
@@ -591,8 +593,8 @@ flamer = defaultAutoGun
|
||||
, _wpReloadState = 0
|
||||
, _wpFireRate = 0
|
||||
, _wpFireState = 0
|
||||
, _wpFire = shoot $ aFlame 0
|
||||
, _wpSpread = flamerAngle
|
||||
, _wpFire = shoot $ withSidePushAfter 10 $ randWalkAngle 0.5 0.05 aFlame
|
||||
, _wpSpread = 0
|
||||
, _wpRange = 8
|
||||
, _itFloorPict = onLayer FlItLayer $ color yellow $ polygon $ rectNESW 4 4 (-4) (-4)
|
||||
, _itAmount = 1
|
||||
@@ -804,30 +806,16 @@ aGasCloud cid w
|
||||
vel = (_crPos cr -.- _crOldPos cr) +.+ 10 *.* unitVectorAtAngle dir
|
||||
insertCloud = makeGasCloud pos vel -- . makeFlame pos2 vel (Just cid)
|
||||
|
||||
|
||||
aFlame :: Float -> Int -> World -> World
|
||||
aFlame a cid w
|
||||
= shakeCr cid 2
|
||||
$ insertFlame $ resetAngle $ set randGen g $
|
||||
w
|
||||
where
|
||||
(a2,g) = randomR (-0.1,0.1) (_randGen w)
|
||||
(t,_) = randomR (99,101) (_randGen w)
|
||||
angle = min flamerAngle $ max (-flamerAngle) (a + a2)
|
||||
cr = (_creatures w IM.! cid)
|
||||
dir = _crDir cr + angle
|
||||
pos = _crPos cr +.+ ((_crRad cr + 2.9) *.* unitVectorAtAngle (_crDir cr))
|
||||
w1 = set randGen g w
|
||||
vel = (_crPos cr -.- _crOldPos cr) +.+ 4 *.* unitVectorAtAngle dir
|
||||
insertFlame = makeFlame t pos vel (Just cid) -- . makeFlame pos2 vel (Just cid)
|
||||
resetAngle = set (creatures . ix cid . crInv . ix (_crInvSel cr) . wpFire)
|
||||
(shoot $ aFlame angle)
|
||||
|
||||
|
||||
|
||||
aFlame :: Int -> World -> World
|
||||
aFlame cid w = insertFlame w
|
||||
where
|
||||
(t,_) = randomR (99,101) (_randGen w)
|
||||
cr = (_creatures w IM.! cid)
|
||||
dir = _crDir cr
|
||||
pos = _crPos cr +.+ ((_crRad cr + 2.9) *.* unitVectorAtAngle (_crDir cr))
|
||||
vel = (_crPos cr -.- _crOldPos cr) +.+ 4 *.* unitVectorAtAngle dir
|
||||
insertFlame = makeFlame t pos vel (Just cid) -- . makeFlame pos2 vel (Just cid)
|
||||
|
||||
flamerAngle = 0.3
|
||||
|
||||
aSelf :: Int -> World -> World
|
||||
aSelf = blinkAction
|
||||
|
||||
@@ -1610,14 +1598,8 @@ thinLine = lineOfThickness 1
|
||||
|
||||
someJust (Just x) | x > 0 = True
|
||||
| otherwise = False
|
||||
|
||||
shakeCr :: Int -> Float -> World -> World
|
||||
shakeCr cID amount w =
|
||||
let vec = vNormal $ unitVectorAtAngle $ _crDir $ _creatures w IM.! cID
|
||||
(x,g) = randomR (-amount,amount) $ _randGen w
|
||||
in set randGen g . over (creatures . ix cID . crPos) (+.+ (x *.* vec)) $ w
|
||||
|
||||
|
||||
{- |
|
||||
Sends out pulses that display walls. -}
|
||||
radar = defaultGun
|
||||
{ _itName = "RADAR"
|
||||
, _itIdentity = Generic
|
||||
@@ -1627,7 +1609,7 @@ radar = defaultGun
|
||||
, _wpReloadState = 0
|
||||
, _wpFireRate = 120
|
||||
, _wpFireState = 0
|
||||
, _wpFire = shoot $ aRadarPulse
|
||||
, _wpFire = shoot aRadarPulse
|
||||
, _wpSpread = autogunSpread
|
||||
, _wpRange = 20
|
||||
, _itHammer = HammerUp
|
||||
@@ -1638,7 +1620,8 @@ radar = defaultGun
|
||||
, _itZoom = defaultItZoom {_itAimZoomMax = 1, _itZoomMax = 1}
|
||||
, _itEquipPict = drawWeapon $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
|
||||
}
|
||||
|
||||
{- |
|
||||
Sends out pulses that display creatures. -}
|
||||
sonar = defaultGun
|
||||
{ _itName = "SONAR"
|
||||
, _itIdentity = Generic
|
||||
@@ -1648,7 +1631,7 @@ sonar = defaultGun
|
||||
, _wpReloadState = 0
|
||||
, _wpFireRate = 120
|
||||
, _wpFireState = 0
|
||||
, _wpFire = shoot $ aSonarPulse
|
||||
, _wpFire = shoot aSonarPulse
|
||||
, _wpSpread = autogunSpread
|
||||
, _wpRange = 20
|
||||
, _itHammer = HammerUp
|
||||
@@ -1659,96 +1642,8 @@ sonar = defaultGun
|
||||
, _itZoom = defaultItZoom {_itAimZoomMax = 1, _itZoomMax = 1}
|
||||
, _itEquipPict = drawWeapon $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
|
||||
}
|
||||
|
||||
aSonarPulse :: Int -> World -> World
|
||||
aSonarPulse cid w = over particles ((:) $ sonarPulseAt (_crPos (_creatures w IM.! cid))) w
|
||||
|
||||
aRadarPulse :: Int -> World -> World
|
||||
aRadarPulse cid w = over particles ((:) $ radarPulseAt (_crPos (_creatures w IM.! cid))) w
|
||||
|
||||
{-
|
||||
Radar blip at a point.
|
||||
-}
|
||||
blipAt :: Point2 -> Color -> Int -> Particle
|
||||
blipAt p col i = Particle
|
||||
{_ptDraw = const blank
|
||||
,_ptUpdate' = mvBlip p col i i
|
||||
}
|
||||
|
||||
mvBlip :: Point2 -> Color -> Int -> Int -> World -> Particle -> (World, Maybe Particle)
|
||||
mvBlip p col maxt 0 w pt = (w, Nothing)
|
||||
mvBlip p col maxt t w pt
|
||||
= (w, Just $ pt & ptUpdate' .~ mvBlip p col maxt (t-1)
|
||||
& ptDraw .~ (const . setDepth (-0.5)
|
||||
. setLayer 1
|
||||
$ uncurry translate p
|
||||
$ color (withAlpha (fromIntegral t / fromIntegral maxt) col)
|
||||
$ circleSolid 2)
|
||||
)
|
||||
|
||||
sonarPulseAt :: Point2 -> Particle
|
||||
sonarPulseAt p = Particle
|
||||
{ _ptDraw = const blank
|
||||
, _ptUpdate' = mvSonar 100 p
|
||||
}
|
||||
|
||||
mvSonar :: Int -> Point2 -> World -> Particle -> (World, Maybe Particle)
|
||||
mvSonar 0 _ w _ = (w, Nothing)
|
||||
mvSonar x p w pt = (w, Just $ pt {_ptDraw = const pic
|
||||
,_ptUpdate' = mvSonar (x-1) p
|
||||
}
|
||||
)
|
||||
where
|
||||
pic = setDepth (-0.5) . setLayer 1 $ pictures
|
||||
-- $ sweepPics ++
|
||||
crBlips -- ++ wallBlips
|
||||
crBlips = mapMaybe crBlip $ IM.elems $ _creatures w
|
||||
crBlip cr | dist cpos p < r + crad && dist cpos p > r - (crad + 100)
|
||||
= Just $ colHelper (0.5 * (1 - (r - dist cpos p) /100))
|
||||
$ uncurry translate cpos $ circleSolid crad
|
||||
| otherwise = Nothing
|
||||
where crad = _crRad cr
|
||||
cpos = _crPos cr
|
||||
r = fromIntegral (500 - x*5)
|
||||
sweepPics = [colHelper 0.05 $ uncurry translate p $ thickCircle r 5
|
||||
-- ,colHelper 0.3 $ uncurry translate p $ thickCircle (r-5) 5
|
||||
-- ,colHelper 0.1 $ uncurry translate p $ thickCircle (r-10) 5
|
||||
]
|
||||
globalAlpha | x > 10 = 1
|
||||
| otherwise = fromIntegral x / 10
|
||||
colHelper y = color (withAlpha (y * globalAlpha) green)
|
||||
-- wallBlips
|
||||
|
||||
|
||||
radarPulseAt :: Point2 -> Particle
|
||||
radarPulseAt p = Particle
|
||||
{ _ptDraw = const blank
|
||||
, _ptUpdate' = mvRadar 50 p
|
||||
}
|
||||
|
||||
mvRadar :: Int -> Point2 -> World -> Particle -> (World, Maybe Particle)
|
||||
mvRadar 0 _ w _ = (w, Nothing)
|
||||
mvRadar x p w pt = (putBlips w, Just $ pt {_ptDraw = const pic
|
||||
,_ptUpdate' = mvRadar (x-1) p
|
||||
}
|
||||
)
|
||||
where
|
||||
pic = onLayerL [levLayer ShadowLayer, 1] $ pictures $ sweepPics
|
||||
putBlips = over worldEvents ((.) $ over particles ((++) blips))
|
||||
blips = map (\p -> blipAt p (withAlpha (0.5*globalAlpha) red) 50)
|
||||
$ circPoints
|
||||
circPoints = mapMaybe (\wl -> collidePointCircCorrect (_wlLine wl !! 0) (_wlLine wl !! 1) r p)
|
||||
$ (map (over wlLine reverse) $ IM.elems $ wallsAlongCirc p r w)
|
||||
++ (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
|
||||
]
|
||||
globalAlpha | x > 10 = 1
|
||||
| otherwise = fromIntegral x / 10
|
||||
colHelper y = color (withAlpha (y * globalAlpha) red)
|
||||
|
||||
{- |
|
||||
Automatically sends out pulses that display creatures. -}
|
||||
autoSonar = defaultEquipment
|
||||
{ _itIdentity = Generic
|
||||
, _itName = "AUTOSONAR"
|
||||
@@ -1762,6 +1657,8 @@ autoSonar = defaultEquipment
|
||||
, _itAimingRange = 0
|
||||
, _itZoom = defaultItZoom {_itAimZoomMax = 1, _itZoomMax = 1}
|
||||
}
|
||||
{- |
|
||||
Automatically sends out pulses that display walls. -}
|
||||
autoRadar = defaultEquipment
|
||||
{ _itIdentity = Generic
|
||||
, _itName = "AUTORADAR"
|
||||
@@ -1775,74 +1672,8 @@ autoRadar = defaultEquipment
|
||||
, _itAimingRange = 0
|
||||
, _itZoom = defaultItZoom {_itAimZoomMax = 1, _itZoomMax = 1}
|
||||
}
|
||||
|
||||
autoRadarEffect :: ItEffect
|
||||
autoRadarEffect = ItInvEffect {_itInvEffect = f 50
|
||||
,_itEffectCounter = 0
|
||||
}
|
||||
where f 0 cr i w = aRadarPulse (_crID cr)
|
||||
w & creatures . ix (_crID cr) . crInv . ix i
|
||||
. itEffect . itInvEffect .~ f 100
|
||||
f t cr i w = w & creatures . ix (_crID cr) . crInv . ix i
|
||||
. itEffect . itInvEffect .~ f (t-1)
|
||||
|
||||
autoSonarEffect :: ItEffect
|
||||
autoSonarEffect = ItInvEffect {_itInvEffect = f 50
|
||||
,_itEffectCounter = 0
|
||||
}
|
||||
where f 0 cr i w = aSonarPulse (_crID cr)
|
||||
w & creatures . ix (_crID cr) . crInv . ix i
|
||||
. itEffect . itInvEffect .~ f 140
|
||||
f t cr i w = w & creatures . ix (_crID cr) . crInv . ix i
|
||||
. itEffect . itInvEffect .~ f (t-1)
|
||||
|
||||
itemLaserScopeEffect :: ItEffect
|
||||
itemLaserScopeEffect
|
||||
= ItInvEffect {_itInvEffect = f
|
||||
,_itEffectCounter = 0
|
||||
}
|
||||
where f cr invid w
|
||||
| invid == _crInvSel cr
|
||||
= w & particles %~ (:) (makeLaserScope sp ep d reloadFrac)
|
||||
& creatures . ix (_crID cr) . crInv . ix invid . itHammer %~ moveHammerUp
|
||||
& laserScopeTargetGlow col glowPoint
|
||||
-- this flare MAY be buggy... something to do with the creature glare
|
||||
| otherwise = w
|
||||
where
|
||||
p = _crPos cr
|
||||
d = _crDir cr
|
||||
r = _crRad cr
|
||||
sp = (p +.+ (r + 3) *.* unitVectorAtAngle d)
|
||||
xp = sp +.+ 3000 *.* unitVectorAtAngle d
|
||||
ep = case listToMaybe $ thingsHitLongLine sp xp w of
|
||||
Just (p,_) -> p
|
||||
Nothing -> xp
|
||||
glowPoint = case listToMaybe $ thingsHitLongLine sp xp w of
|
||||
Just (p,E3x2 wl) -> p +.+ 2 *.* wallNormal wl
|
||||
_ -> (ep -.- 2 *.* unitVectorAtAngle d)
|
||||
it = (cr ^. crInv) IM.! invid
|
||||
reloadFrac
|
||||
| _wpLoadedAmmo it == 0 = 1
|
||||
| otherwise = fromIntegral (_wpReloadState it) / fromIntegral (_wpReloadTime it)
|
||||
col = mixColors reloadFrac (1-reloadFrac) red green
|
||||
moveHammerUp !HammerDown = HammerReleased
|
||||
moveHammerUp !_ = HammerUp
|
||||
|
||||
makeLaserScope :: Point2 -> Point2 -> Float -> Float -> Particle
|
||||
makeLaserScope p ep d relFrac = Particle
|
||||
{_ptDraw = const $ onLayer PtLayer $ pictures
|
||||
[color (withAlpha 0.5 $ mixColors relFrac (1-relFrac) red green)
|
||||
$ lineOfThickness 0.5 [p,ep]
|
||||
,color (withAlpha 0.2 $ mixColors relFrac (1-relFrac) red green)
|
||||
$ lineOfThickness 1.5 [p,ep]
|
||||
,color (withAlpha 0.1 $ mixColors relFrac (1-relFrac) red green)
|
||||
$ lineOfThickness 2 [p,ep]
|
||||
]
|
||||
,_ptUpdate' = \w pt -> (w, Just $ pt & ptUpdate' .~ \w' _ -> (w',Nothing))
|
||||
}
|
||||
|
||||
|
||||
|
||||
{- |
|
||||
Creates a creature next to the creature using the item. -}
|
||||
spawnGun :: Creature -> Item
|
||||
spawnGun cr = defaultGun
|
||||
{ _itName = "SPAWNER"
|
||||
@@ -1854,7 +1685,11 @@ spawnGun cr = defaultGun
|
||||
, _wpFire = spawnCrNextTo cr
|
||||
}
|
||||
|
||||
spawnCrNextTo :: Creature -> Int -> World -> World
|
||||
spawnCrNextTo
|
||||
:: Creature -- ^ Creature to spawn
|
||||
-> Int -- ^ ID of existing creature that will be spawned next to
|
||||
-> World
|
||||
-> World
|
||||
spawnCrNextTo cr i w = w & creatures %~ IM.insert k newCr
|
||||
where
|
||||
k = newKey $ _creatures w
|
||||
|
||||
Reference in New Issue
Block a user