Refactoring and linting

This commit is contained in:
2021-04-30 17:50:28 +02:00
parent 83c2220813
commit 9c0e4425da
18 changed files with 531 additions and 523 deletions
+9 -9
View File
@@ -467,7 +467,7 @@ miniAI w (f,g) cr =
addAction newActions addAction newActions
= Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = Just -- autoFireTweak p | _wpIsAuto wp = Just
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
in --if _crHP cr <= 0 then killCr w f cr else in --if _crHP cr <= 0 then killCr w f cr else
case head $ _goals $ _crState cr of case head $ _goals $ _crState cr of
[] | canSeeFire cpos ypos w -> ( ( f , g1 ) [] | canSeeFire cpos ypos w -> ( ( f , g1 )
@@ -586,7 +586,7 @@ strafeOrChargeAI inRange outRange w (f,g) cr =
addAction newActions addAction newActions
= Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = Just -- autoFireTweak p | _wpIsAuto wp = Just
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
in --if _crHP cr <= 0 then killCr w f cr else in --if _crHP cr <= 0 then killCr w f cr else
case head $ _goals $ _crState cr of case head $ _goals $ _crState cr of
[] | canSeeFire cpos ypos w -> ( ( f , g1 ) [] | canSeeFire cpos ypos w -> ( ( f , g1 )
@@ -1101,7 +1101,7 @@ circleClockwiseAI inRange outRange w (f,g) cr =
addAction newActions addAction newActions
= Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = Just -- autoFireTweak p | _wpIsAuto wp = Just
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
in --if _crHP cr <= 0 then killCr w f cr else in --if _crHP cr <= 0 then killCr w f cr else
case head $ _goals $ _crState cr of case head $ _goals $ _crState cr of
[] | canSeeFire cpos ypos w -> ( ( f , g1 ) [] | canSeeFire cpos ypos w -> ( ( f , g1 )
@@ -1198,7 +1198,7 @@ twitchMissAI inRange outRange w (f,g) cr =
cid = _crID cr cid = _crID cr
ypos = _crPos $ you w ypos = _crPos $ you w
wp = _crInv cr IM.! _crInvSel cr wp = _crInv cr IM.! _crInvSel cr
fireRate = fromMaybe 0 $ wp ^? wpFireRate fireRate = fromMaybe 0 $ wp ^? itUseRate
noAmmo = 0 == _wpLoadedAmmo wp noAmmo = 0 == _wpLoadedAmmo wp
strafeCloseSlow p | errorAngleVV 22 (p -.- cpos) strafeCloseSlow p | errorAngleVV 22 (p -.- cpos)
(unitVectorAtAngle (_crDir cr)) < 0.1 (unitVectorAtAngle (_crDir cr)) < 0.1
@@ -1297,7 +1297,7 @@ closeToRangeAI inRange outRange w (f,g) cr =
cid = _crID cr cid = _crID cr
ypos = _crPos $ you w ypos = _crPos $ you w
wp = _crInv cr IM.! _crInvSel cr wp = _crInv cr IM.! _crInvSel cr
fireRate = fromMaybe 0 $ wp ^? wpFireRate fireRate = fromMaybe 0 $ wp ^? itUseRate
(aimtime,g1) = randomR (80,120) g (aimtime,g1) = randomR (80,120) g
noAmmo = 0 == _wpLoadedAmmo wp noAmmo = 0 == _wpLoadedAmmo wp
strafeCloseSlow p | errorAngleVV 22 (p -.- cpos) strafeCloseSlow p | errorAngleVV 22 (p -.- cpos)
@@ -1424,7 +1424,7 @@ suppressShooterAI w (f,g) cr =
addAction newActions addAction newActions
= Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = Just -- autoFireTweak p | _wpIsAuto wp = Just
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
in --if _crHP cr <= 0 then killCr w f cr else in --if _crHP cr <= 0 then killCr w f cr else
case head $ _goals $ _crState cr of case head $ _goals $ _crState cr of
[] | canSeeFire cpos ypos w -> ( ( f , g1 ) [] | canSeeFire cpos ypos w -> ( ( f , g1 )
@@ -1528,7 +1528,7 @@ basicShooterAI w (f,g) cr =
addAction newActions addAction newActions
= Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = Just -- autoFireTweak p | _wpIsAuto wp = Just
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
in --if _crHP cr <= 0 then killCr w f cr else in --if _crHP cr <= 0 then killCr w f cr else
case head $ _goals $ _crState cr of case head $ _goals $ _crState cr of
[] | canSeeFire cpos ypos w -> ( ( f , g1 ) [] | canSeeFire cpos ypos w -> ( ( f , g1 )
@@ -1631,7 +1631,7 @@ sniperAI w (f,g) cr =
addAction newActions addAction newActions
= Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = Just -- autoFireTweak p | _wpIsAuto wp = Just
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
in --if _crHP cr <= 0 then killCr w f cr else in --if _crHP cr <= 0 then killCr w f cr else
case head $ _goals $ _crState cr of case head $ _goals $ _crState cr of
[] | canSeeFire cpos ypos w -> ( ( f , g1 ) [] | canSeeFire cpos ypos w -> ( ( f , g1 )
@@ -1733,7 +1733,7 @@ sniperAI w (f,g) cr =
-- addAction newActions = over (creatures . ix cid . crState . goals) -- addAction newActions = over (creatures . ix cid . crState . goals)
-- (\(as:ass) -> (newActions++as):ass) -- (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = id -- autoFireTweak p | _wpIsAuto wp = id
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
-- in if _crHP cr <= 0 then killCr cid w else -- in if _crHP cr <= 0 then killCr cid w else
-- case head $ _goals $ _crState cr of -- case head $ _goals $ _crState cr of
-- [] | canSeeAny cid (_yourID w) w -- [] | canSeeAny cid (_yourID w) w
+9 -9
View File
@@ -469,7 +469,7 @@ miniAI w (f,g) cr =
addAction newActions addAction newActions
= Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = Just -- autoFireTweak p | _wpIsAuto wp = Just
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
in --if _crHP cr <= 0 then killCr w f cr else in --if _crHP cr <= 0 then killCr w f cr else
case head $ _goals $ _crState cr of case head $ _goals $ _crState cr of
[] | canSeeFire cpos ypos w -> ( ( f , g1 ) [] | canSeeFire cpos ypos w -> ( ( f , g1 )
@@ -588,7 +588,7 @@ strafeOrChargeAI inRange outRange w (f,g) cr =
addAction newActions addAction newActions
= Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = Just -- autoFireTweak p | _wpIsAuto wp = Just
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
in --if _crHP cr <= 0 then killCr w f cr else in --if _crHP cr <= 0 then killCr w f cr else
case head $ _goals $ _crState cr of case head $ _goals $ _crState cr of
[] | canSeeFire cpos ypos w -> ( ( f , g1 ) [] | canSeeFire cpos ypos w -> ( ( f , g1 )
@@ -1103,7 +1103,7 @@ circleClockwiseAI inRange outRange w (f,g) cr =
addAction newActions addAction newActions
= Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = Just -- autoFireTweak p | _wpIsAuto wp = Just
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
in --if _crHP cr <= 0 then killCr w f cr else in --if _crHP cr <= 0 then killCr w f cr else
case head $ _goals $ _crState cr of case head $ _goals $ _crState cr of
[] | canSeeFire cpos ypos w -> ( ( f , g1 ) [] | canSeeFire cpos ypos w -> ( ( f , g1 )
@@ -1200,7 +1200,7 @@ twitchMissAI inRange outRange w (f,g) cr =
cid = _crID cr cid = _crID cr
ypos = _crPos $ you w ypos = _crPos $ you w
wp = _crInv cr IM.! _crInvSel cr wp = _crInv cr IM.! _crInvSel cr
fireRate = fromMaybe 0 $ wp ^? wpFireRate fireRate = fromMaybe 0 $ wp ^? itUseRate
noAmmo = 0 == _wpLoadedAmmo wp noAmmo = 0 == _wpLoadedAmmo wp
strafeCloseSlow p | errorAngleVV 22 (p -.- cpos) strafeCloseSlow p | errorAngleVV 22 (p -.- cpos)
(unitVectorAtAngle (_crDir cr)) < 0.1 (unitVectorAtAngle (_crDir cr)) < 0.1
@@ -1299,7 +1299,7 @@ closeToRangeAI inRange outRange w (f,g) cr =
cid = _crID cr cid = _crID cr
ypos = _crPos $ you w ypos = _crPos $ you w
wp = _crInv cr IM.! _crInvSel cr wp = _crInv cr IM.! _crInvSel cr
fireRate = fromMaybe 0 $ wp ^? wpFireRate fireRate = fromMaybe 0 $ wp ^? itUseRate
(aimtime,g1) = randomR (80,120) g (aimtime,g1) = randomR (80,120) g
noAmmo = 0 == _wpLoadedAmmo wp noAmmo = 0 == _wpLoadedAmmo wp
strafeCloseSlow p | errorAngleVV 22 (p -.- cpos) strafeCloseSlow p | errorAngleVV 22 (p -.- cpos)
@@ -1426,7 +1426,7 @@ suppressShooterAI w (f,g) cr =
addAction newActions addAction newActions
= Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = Just -- autoFireTweak p | _wpIsAuto wp = Just
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
in --if _crHP cr <= 0 then killCr w f cr else in --if _crHP cr <= 0 then killCr w f cr else
case head $ _goals $ _crState cr of case head $ _goals $ _crState cr of
[] | canSeeFire cpos ypos w -> ( ( f , g1 ) [] | canSeeFire cpos ypos w -> ( ( f , g1 )
@@ -1530,7 +1530,7 @@ basicShooterAI w (f,g) cr =
addAction newActions addAction newActions
= Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = Just -- autoFireTweak p | _wpIsAuto wp = Just
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
in --if _crHP cr <= 0 then killCr w f cr else in --if _crHP cr <= 0 then killCr w f cr else
case head $ _goals $ _crState cr of case head $ _goals $ _crState cr of
[] | canSeeFire cpos ypos w -> ( ( f , g1 ) [] | canSeeFire cpos ypos w -> ( ( f , g1 )
@@ -1633,7 +1633,7 @@ sniperAI w (f,g) cr =
addAction newActions addAction newActions
= Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass) = Just . over (crState . goals) (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = Just -- autoFireTweak p | _wpIsAuto wp = Just
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
in --if _crHP cr <= 0 then killCr w f cr else in --if _crHP cr <= 0 then killCr w f cr else
case head $ _goals $ _crState cr of case head $ _goals $ _crState cr of
[] | canSeeFire cpos ypos w -> ( ( f , g1 ) [] | canSeeFire cpos ypos w -> ( ( f , g1 )
@@ -1735,7 +1735,7 @@ sniperAI w (f,g) cr =
-- addAction newActions = over (creatures . ix cid . crState . goals) -- addAction newActions = over (creatures . ix cid . crState . goals)
-- (\(as:ass) -> (newActions++as):ass) -- (\(as:ass) -> (newActions++as):ass)
-- autoFireTweak p | _wpIsAuto wp = id -- autoFireTweak p | _wpIsAuto wp = id
-- | otherwise = replaceGoal [[AimAt p (_wpFireRate wp * 2)]] -- | otherwise = replaceGoal [[AimAt p (_itUseRate wp * 2)]]
-- in if _crHP cr <= 0 then killCr cid w else -- in if _crHP cr <= 0 then killCr cid w else
-- case head $ _goals $ _crState cr of -- case head $ _goals $ _crState cr of
-- [] | canSeeAny cid (_yourID w) w -- [] | canSeeAny cid (_yourID w) w
-9
View File
@@ -425,15 +425,6 @@ collidePointFireVision p1 p2 ws = any ( isJust
Just _ -> not $ _wlIsSeeThrough wl Just _ -> not $ _wlIsSeeThrough wl
Nothing -> True Nothing -> True
-- shit this is ugly
lineOfThickness :: Float -> [Point2] -> Picture
lineOfThickness t = pictures . f
where f (x:y:ys)
| x == y = f (x:ys)
| otherwise
= polygon [x +.+ n x y, x -.- n x y, y -.- n x y, y +.+ n x y] : f (y:ys)
f _ = []
n a b = (t*0.5) *.* errorNormalizeV 42 (vNormal (a -.- b))
lineGeom :: Float -> Point2 -> Point2 -> [Point2] lineGeom :: Float -> Point2 -> Point2 -> [Point2]
lineGeom t x y lineGeom t x y
+1 -1
View File
@@ -264,7 +264,7 @@ Items you start with.
-} -}
startInventory = IM.fromList (zip [0..20] startInventory = IM.fromList (zip [0..20]
( (
[lasGun [bezierGun
,remoteLauncher ,remoteLauncher
,grenade ,grenade
--,spawnGun lamp --,spawnGun lamp
+1 -1
View File
@@ -178,7 +178,7 @@ isFrictionless cr = case cr ^? crState . stance . carriage of
_ -> False _ -> False
updateReloadCounter :: Creature -> Creature updateReloadCounter :: Creature -> Creature
updateReloadCounter cr = over (crInv . ix iSel . wpFireState) decreaseToZero updateReloadCounter cr = over (crInv . ix iSel . itUseTime) decreaseToZero
. over (crInv . ix iSel . wpReloadState) decreaseToZero . over (crInv . ix iSel . wpReloadState) decreaseToZero
$ cr $ cr
where iSel = _crInvSel cr where iSel = _crInvSel cr
+4 -2
View File
@@ -215,8 +215,8 @@ data Item
, _wpLoadedAmmo :: Int , _wpLoadedAmmo :: Int
, _wpReloadTime :: Int , _wpReloadTime :: Int
, _wpReloadState :: Int , _wpReloadState :: Int
, _wpFireRate :: Int , _itUseRate :: Int
, _wpFireState :: Int , _itUseTime :: Int
, _wpFire :: Int -> World -> World , _wpFire :: Int -> World -> World
, _wpSpread :: Float , _wpSpread :: Float
, _wpRange :: Float , _wpRange :: Float
@@ -286,6 +286,8 @@ data Item
, _twMaxRange :: Float , _twMaxRange :: Float
, _twAccuracy :: Float , _twAccuracy :: Float
, _twFire :: Int -> World -> World , _twFire :: Int -> World -> World
, _itUseRate :: Int
, _itUseTime :: Int
, _itAimingSpeed :: Float , _itAimingSpeed :: Float
, _itAimingRange :: Float , _itAimingRange :: Float
, _itZoom :: ItZoom , _itZoom :: ItZoom
+2 -2
View File
@@ -276,8 +276,8 @@ data Item
, _wpLoadedAmmo :: Int , _wpLoadedAmmo :: Int
, _wpReloadTime :: Int , _wpReloadTime :: Int
, _wpReloadState :: Int , _wpReloadState :: Int
, _wpFireRate :: Int , _itUseRate :: Int
, _wpFireState :: Int , _itUseTime :: Int
, _wpFire :: Int -> World -> World , _wpFire :: Int -> World -> World
, _wpSpread :: Float , _wpSpread :: Float
, _wpRange :: Float , _wpRange :: Float
+1
View File
@@ -2,6 +2,7 @@ module Dodge.Debug where
import Dodge.Data import Dodge.Data
import Dodge.Base import Dodge.Base
import Dodge.Picture
import Geometry.Data import Geometry.Data
import Picture import Picture
+1
View File
@@ -4,6 +4,7 @@ module Dodge.Item
import Dodge.Data import Dodge.Data
import Dodge.Base import Dodge.Base
import Dodge.Default import Dodge.Default
import Dodge.Picture
import Picture import Picture
keyToken :: Int -> Item keyToken :: Int -> Item
+277 -470
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -5,6 +5,7 @@ module Dodge.Item.Weapon.Decoration
where where
import Dodge.Data import Dodge.Data
import Dodge.Base import Dodge.Base
import Dodge.Picture
import Geometry.Data import Geometry.Data
import Picture import Picture
+123
View File
@@ -0,0 +1,123 @@
module Dodge.Item.Weapon.Laser
where
import Dodge.Data
import Dodge.Picture
import Dodge.Item.Attachment.Data
import Dodge.Base
import Dodge.SoundLogic
import Dodge.WorldEvent.SpawnParticle
import Dodge.WorldEvent.ThingsHit
import Dodge.WorldEvent.HelperParticle
import Dodge.WorldEvent.Flash
import Geometry
import Picture
import Control.Lens
import System.Random
import Data.List (find)
import Data.Maybe (fromMaybe)
import qualified Data.Sequence as Seq
import qualified Data.IntMap.Strict as IM
aLaser :: Int -> World -> World
aLaser cid w = over particles (makeLaserAt phaseV pos dir (Just cid) : )
$ soundFrom LasSound 24 1 0
$ laserGunFlashAt (pos +.+ 5 *.* unitVectorAtAngle dir)
w
where
cr = _creatures w IM.! cid
i = newProjectileKey w
pos = _crPos cr +.+ ((_crRad cr +3) *.* unitVectorAtAngle dir)
dir = _crDir cr
phaseV = charToPhaseV
$ fromMaybe '/' $ Seq.lookup 0 =<< cr ^? crInv . ix j . itAttachment . _Just . itCharMode
j = _crInvSel cr
charToPhaseV 'V' = 0.2
charToPhaseV '/' = 1
charToPhaseV 'Z' = 5
makeLaserAt :: Float -> Point2 -> Float -> Maybe Int -> Particle
makeLaserAt phaseV pos dir mcid = Particle
{ _ptDraw = const blank
, _ptUpdate' = moveLaser phaseV pos dir mcid
}
moveLaser
:: Float -- ^ Phase velocity, controls deflection in windows
-> Point2
-> Float
-> Maybe Int
-> World
-> Particle
-> (World, Maybe Particle)
moveLaser phaseV pos dir mcid w pt
= ( set randGen g $ hitEffect w
, Just pt {_ptDraw = const $ onLayer PtLayer $ pic ,_ptUpdate' = ptTimer' 0 }
)
where
xp = pos +.+ 800 *.* unitVectorAtAngle dir
(a,g) = randomR (-0.7,0.7) $ _randGen w
reflectDir wall = a +
(argV $ reflectIn (_wlLine wall !! 1 -.- _wlLine wall !! 0) (xp -.- pos) )
(colID,_) = randomR (0,11) $ _randGen w
f :: [Wall] -> Point2 -> Point2 -> (Maybe (Point2,Either3 Creature Wall ForceField),[Point2])
f seenWs x y = case find (h' seenWs) $ thingsHitExceptCrLongLine Nothing x y w of
Just (p,E3x2 wl)
| _wlIsSeeThrough wl -> f' p $ f (wl:seenWs)
p
(h x y wl p)
| otherwise -> (Just (p,E3x2 wl), [p])
Just (p,obj) -> (Just (p,obj), [p])
Nothing -> (Nothing, [y])
f' p (x,ps') = (x,p:ps')
h x y wl p | isEntering = p +.+ rotateV angleRef normalDist
| otherwise = p +.+ rotateV angleRef' normalDist'
where
wlNormal = vNormal $ (_wlLine wl !! 1) -.- (_wlLine wl !! 0)
normalDist = magV (p -.- y) *.* normalizeV wlNormal
angleInc = piRange $ argV wlNormal - argV (x -.- y)
angleRef | reflectExternal = angleInc
| otherwise = asin $ sin angleInc / phaseV
piRange a | a > pi = a - 2 * pi
| a > negate pi = a
| otherwise = a + 2 * pi
isEntering = isLeftOf (x -.- y) ((_wlLine wl !! 1) -.- (_wlLine wl !! 0))
wlNormal' = vNormal $ (_wlLine wl !! 0) -.- (_wlLine wl !! 1)
normalDist' = magV (p -.- y) *.* normalizeV wlNormal'
angleInc' = piRange $ argV wlNormal' - argV (x -.- y)
angleRef' | reflectInternal = angleInc'
| otherwise = asin $ phaseV * sin angleInc'
reflectInternal = 1 < abs (phaseV * sin angleInc')
reflectExternal = 1 < abs (sin angleInc / phaseV)
h' ws (_,E3x2 wl) = not $ any (\w -> _wlID w == _wlID wl) ws
h' _ _ = True
(thHit, ps) = f [] pos xp
hitEffect
= case thHit of
Just (p,E3x1 cr)
-> over (creatures . ix (_crID cr) . crState . crDamage) ((:) $ Lasering 19 pos p xp)
-- . over worldEvents ((.) $ flareAt yellow (flarePos p))
Just (p,E3x2 wl) -> createSpark 8 colID (p +.+ safeNormalizeV (pos -.- p))
(reflectDir wl) Nothing
_ -> id
pic = pictures [ fadeLine pos (head ps) 0.2 40 yellow
, setLayer 1 $ color (withAlpha 0.9 white) $ vThickLine (pos:ps)
, setLayer 1 $ color (withAlpha 0.5 yellow) $ vvThickLine (pos:ps)
]
fadeLine :: Point2 -> Point2 -> Float -> Float -> Color -> Picture
fadeLine sp ep alph width col = setLayer 1 $ polygonCol
[(sp , ca)
,(sp +.+ n , cb)
,(ep +.+ n , cb)
,(ep , ca)
,(ep -.- n , cb)
,(sp -.- n , cb)
]
where
n = width *.* normalizeV (vNormal $ ep -.- sp)
ca = withAlpha alph col
cb = withAlpha 0 col
+63 -10
View File
@@ -42,6 +42,44 @@ withThickSmoke eff cid w = eff cid $ foldr (makeThickSmokeAt . (+.+ pos)) w ps
pos = _crPos cr +.+ (_crRad cr + 15) *.* unitVectorAtAngle dir pos = _crPos cr +.+ (_crRad cr + 15) *.* unitVectorAtAngle dir
ps = (replicateM 20 . randInCirc) 8 & evalState $ _randGen w ps = (replicateM 20 . randInCirc) 8 & evalState $ _randGen w
{- | {- |
Fires at an increasing rate.
Has different effect after first fire.
Applies ammo check and use cooldown check. -}
rateIncAB
:: Int -- ^ Start rate
-> Int -- ^ End rate
-> (Int -> World -> World) -- ^ Effect on first fire
-> (Int -> World -> World) -- ^ Effect on continued fire
-> Int -- ^ Creature id
-> World
-> World
rateIncAB startRate fastRate shooteff1 shooteff2 cid w
| repeatFire = set (pointItem . itUseRate) (max fastRate (currentRate - 1))
$ over (pointItem . wpLoadedAmmo) (\ammo -> ammo-1)
$ set (pointItem . itUseTime) currentRate
$ shooteff2 cid
w
| firstFire = set (pointItem . itUseRate) (startRate - 1)
$ over (pointItem . wpLoadedAmmo) (\ammo -> ammo-1)
$ set (pointItem . itUseTime) startRate
$ shooteff1 cid
w
| reloadCondition = fromMaybe w $ reloadWeapon cid w
| otherwise = w
where
cr = _creatures w IM.! cid
itRef = _crInvSel cr
item = _crInv cr IM.! itRef
pointItem = creatures . ix cid . crInv . ix itRef
currentRate = _itUseRate item
repeatFire = _wpReloadState item == 0
&& _itUseTime item == 1
&& _wpLoadedAmmo item > 0
firstFire = _wpReloadState item == 0
&& _itUseTime item == 0
&& _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0
{- |
Shoot a weapon rapidly after a warm up. Shoot a weapon rapidly after a warm up.
Applies ammo check as well. -} Applies ammo check as well. -}
withWarmUp withWarmUp
@@ -55,18 +93,18 @@ withWarmUp t f cid w
| reloadCondition = fromMaybe w $ reloadWeapon cid w | reloadCondition = fromMaybe w $ reloadWeapon cid w
| _wpReloadState item /= 0 = w | _wpReloadState item /= 0 = w
| fState == 0 = set (pointerToItem . wpFire) (withWarmUp 100 f) | fState == 0 = set (pointerToItem . wpFire) (withWarmUp 100 f)
$ set (pointerToItem . wpFireState) 2 $ set (pointerToItem . itUseTime) 2
w w
| t > 2 = set (pointerToItem . wpFire) (withWarmUp (t-1) f) | t > 2 = set (pointerToItem . wpFire) (withWarmUp (t-1) f)
$ set (pointerToItem . wpFireState) 2 $ set (pointerToItem . itUseTime) 2
$ soundFrom (CrWeaponSound cid) 26 2 0 $ soundFrom (CrWeaponSound cid) 26 2 0
w w
| t > 0 = set (pointerToItem . wpFire) (withWarmUp (t-1) f) | t > 0 = set (pointerToItem . wpFire) (withWarmUp (t-1) f)
$ set (pointerToItem . wpFireState) 2 $ set (pointerToItem . itUseTime) 2
w w
| otherwise = set (pointerToItem . wpFire) (withWarmUp 1 f) | otherwise = set (pointerToItem . wpFire) (withWarmUp 1 f)
$ over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1) $ over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1)
$ set (pointerToItem . wpFireState) 2 $ set (pointerToItem . itUseTime) 2
$ f cid $ f cid
$ soundFrom (CrWeaponSound cid) 28 2 0 $ soundFrom (CrWeaponSound cid) 28 2 0
w w
@@ -75,8 +113,8 @@ withWarmUp t f cid w
itRef = _crInvSel cr itRef = _crInvSel cr
item = _crInv cr IM.! itRef item = _crInv cr IM.! itRef
pointerToItem = creatures . ix cid . crInv . ix itRef pointerToItem = creatures . ix cid . crInv . ix itRef
fState = _wpFireState item fState = _itUseTime item
fRate = _wpFireRate item fRate = _itUseRate item
reloadCondition = _wpLoadedAmmo item == 0 reloadCondition = _wpLoadedAmmo item == 0
{- | {- |
Adds a sound to a creature based world effect. Adds a sound to a creature based world effect.
@@ -136,7 +174,7 @@ shootWithSound
shootWithSound soundid f cid w shootWithSound soundid f cid w
| fireCondition = over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1) | fireCondition = over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1)
$ soundOncePos soundid (_crPos cr) $ soundOncePos soundid (_crPos cr)
$ set (pointerToItem . wpFireState) (_wpFireRate item) $ set (pointerToItem . itUseTime) (_itUseRate item)
$ f cid w $ f cid w
| reloadCondition = fromMaybe w $ reloadWeapon cid w | reloadCondition = fromMaybe w $ reloadWeapon cid w
| otherwise = w | otherwise = w
@@ -146,10 +184,25 @@ shootWithSound soundid f cid w
item = _crInv cr IM.! itRef item = _crInv cr IM.! itRef
pointerToItem = creatures . ix cid . crInv . ix itRef pointerToItem = creatures . ix cid . crInv . ix itRef
fireCondition = _wpReloadState item == 0 fireCondition = _wpReloadState item == 0
&& _wpFireState item == 0 && _itUseTime item == 0
&& _wpLoadedAmmo item > 0 && _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0 reloadCondition = _wpLoadedAmmo item == 0
{- | {- |
Applies a world effect after an item use cooldown check. -}
useTimeCheck
:: (Int -> World -> World) -- ^ Underlying effect
-> Int -- ^ Creature id
-> World
-> World
useTimeCheck f cid w = case theItem ^? itUseTime of
Just 0 -> f cid $ setUseTime w
_ -> w
where
cr = _creatures w IM.! cid
setUseTime = creatures . ix cid . crInv . ix (_crInvSel cr) . itUseTime +~ useRate
theItem = _crInv cr IM.! _crInvSel cr
useRate = fromMaybe 0 $ theItem ^? itUseRate
{- |
Applies a world effect after a hammer position check. -} Applies a world effect after a hammer position check. -}
hammerCheck hammerCheck
:: (Int -> World -> World) -- ^ Underlying effect :: (Int -> World -> World) -- ^ Underlying effect
@@ -172,7 +225,7 @@ shoot
-> World -> World
shoot f cid w shoot f cid w
| fireCondition = over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1) | fireCondition = over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1)
$ set (pointerToItem . wpFireState) (_wpFireRate item) $ set (pointerToItem . itUseTime) (_itUseRate item)
$ f cid w $ f cid w
| reloadCondition = fromMaybe w $ reloadWeapon cid w | reloadCondition = fromMaybe w $ reloadWeapon cid w
| otherwise = w | otherwise = w
@@ -182,7 +235,7 @@ shoot f cid w
item = _crInv cr IM.! itRef item = _crInv cr IM.! itRef
pointerToItem = creatures . ix cid . crInv . ix itRef pointerToItem = creatures . ix cid . crInv . ix itRef
fireCondition = _wpReloadState item == 0 fireCondition = _wpReloadState item == 0
&& _wpFireState item == 0 && _itUseTime item == 0
&& _wpLoadedAmmo item > 0 && _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0 reloadCondition = _wpLoadedAmmo item == 0
+31
View File
@@ -0,0 +1,31 @@
{- |
Compound, universal pictures.
Creates uniform sizes and commands for the Dodge modules. -}
module Dodge.Picture
where
import Geometry
import Picture
-- {- |
-- Current thickness: 2 -}
-- thickLine :: [Point2] -> Picture
-- thickLine = lineOfThickness 2
{- |
Current thickness: 3 -}
vThickLine :: [Point2] -> Picture
vThickLine = lineOfThickness 3
{- |
Current thickness: 6 -}
vvThickLine :: [Point2] -> Picture
vvThickLine = lineOfThickness 6
-- shit this is ugly
lineOfThickness :: Float -> [Point2] -> Picture
lineOfThickness t = pictures . f
where f (x:y:ys)
| x == y = f (x:ys)
| otherwise
= polygon [x +.+ n x y, x -.- n x y, y -.- n x y, y +.+ n x y] : f (y:ys)
f _ = []
n a b = (t*0.5) *.* errorNormalizeV 42 (vNormal (a -.- b))
+4 -7
View File
@@ -20,9 +20,10 @@ hudDrawings w = setLayer 1 . setDepth (-0.5) . pictures $
] ]
++ selectionText ++ selectionText
where where
selectionText = if _carteDisplay w selectionText =
then drawLocations w if _carteDisplay w
else drawInventory w then drawLocations w
else drawInventory w
scaler = scale (2 / getWindowX w) (2 / getWindowY w) scaler = scale (2 / getWindowX w) (2 / getWindowY w)
drawInventory :: World -> [Picture] drawInventory :: World -> [Picture]
@@ -53,10 +54,6 @@ itemStringCol :: Item -> (String,Color)
itemStringCol NoItem = ("----", greyN 0.5) itemStringCol NoItem = ("----", greyN 0.5)
itemStringCol itm = (_itInvDisplay itm itm, _itInvColor itm) itemStringCol itm = (_itInvDisplay itm itm, _itInvColor itm)
dItem' NoItem = scale 0.1 0.1 $ dShadCol (greyN 0.5) $ text "----"
dItem' i = scale 0.1 0.1 $ dShadCol (_itInvColor i) t
where t = text $ _itInvDisplay i i
drawLocations :: World -> [Picture] drawLocations :: World -> [Picture]
drawLocations w = displayListTopLeft locs w drawLocations w = displayListTopLeft locs w
++ zipWith bFunc (displayListEndCoords w locTexts) locPoss ++ zipWith bFunc (displayListEndCoords w locTexts) locPoss
+1 -2
View File
@@ -2,10 +2,9 @@ module Dodge.Render.Picture
where where
import Dodge.Data import Dodge.Data
import Dodge.Base import Dodge.Base
import Dodge.Picture
import Dodge.Render.HUD import Dodge.Render.HUD
import Dodge.Render.MenuScreen import Dodge.Render.MenuScreen
import Geometry import Geometry
import Picture import Picture
+1
View File
@@ -12,6 +12,7 @@ module Dodge.WorldEvent.Flash
where where
import Dodge.Data import Dodge.Data
import Dodge.Base import Dodge.Base
import Dodge.Picture
import Dodge.LightSources import Dodge.LightSources
import Dodge.WorldEvent.ThingsHit import Dodge.WorldEvent.ThingsHit
+1
View File
@@ -5,6 +5,7 @@ module Dodge.WorldEvent.SpawnParticle
where where
import Dodge.Data import Dodge.Data
import Dodge.Base import Dodge.Base
import Dodge.Picture
import Dodge.WorldEvent.HitEffect import Dodge.WorldEvent.HitEffect
import Dodge.WorldEvent.ThingsHit import Dodge.WorldEvent.ThingsHit
import Dodge.WorldEvent.Cloud import Dodge.WorldEvent.Cloud