Tweak weapons

This commit is contained in:
2021-09-06 21:58:36 +01:00
parent 60dc2d9342
commit 6ecd739d6f
6 changed files with 65 additions and 58 deletions
+23 -29
View File
@@ -1,4 +1,9 @@
module Dodge.Item.Attachment module Dodge.Item.Attachment
( charFiringStratI
, scrollCharMode
, decreaseFuse
, increaseFuse
)
where where
import Dodge.Data import Dodge.Data
import Dodge.Item.Attachment.Data import Dodge.Item.Attachment.Data
@@ -6,19 +11,9 @@ import Dodge.Default
import Control.Lens hiding ((|>),(<|)) import Control.Lens hiding ((|>),(<|))
import Data.Sequence import Data.Sequence
import Data.Maybe (fromJust) import Data.Maybe
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
incCharMode' :: ItAttachment -> ItAttachment
incCharMode' = itCharMode %~ cycleL
where
cycleL (x :<| xs) = xs |> x
cycleL xs = xs
decCharMode' :: ItAttachment -> ItAttachment
decCharMode' = itCharMode %~ cycleR
where
cycleR (xs :|> x) = x <| xs
cycleR xs = xs
scrollCharMode scrollCharMode
:: Float -- ^ Amount scrolled :: Float -- ^ Amount scrolled
@@ -34,34 +29,32 @@ incCharMode
:: Int -- ^ Inventory selection :: Int -- ^ Inventory selection
-> World -> World
-> World -> World
incCharMode i = creatures . ix 0 . crInv . ix i . itAttachment %~ incCharMode' incCharMode i = creatures . ix 0 . crInv . ix i . itAttachment . itCharMode %~ cycleL
where
cycleL (x :<| xs) = xs |> x
cycleL xs = xs
decCharMode decCharMode
:: Int -- ^ Inventory selection :: Int -- ^ Inventory selection
-> World -> World
-> World -> World
decCharMode i = creatures . ix 0 . crInv . ix i . itAttachment %~ decCharMode' decCharMode i = creatures . ix 0 . crInv . ix i . itAttachment . itCharMode %~ cycleR
charFiringStrat
:: [(Char, Creature -> World -> World)] -- ^ Different firing effects for different characters
-> Creature -- ^ Creature id
-> World
-> World
charFiringStrat strats cr w = case w ^? creatures . ix cid . crInv
. ix (_crInvSel $ _creatures w IM.! cid) . itAttachment . itCharMode of
Just (c :<| _) -> fromJust (Prelude.lookup c strats) cr w
_ -> w
where where
cid = _crID cr cycleR (xs :|> x) = x <| xs
charFiringStratI cycleR xs = xs
:: [(Char, (Item -> Creature -> World -> World) -> Item -> Creature -> World -> World)] -- ^ Different firing effects for different characters
-> (Item -> Creature -> World -> World) type ChainEffect =
(Item -> Creature -> World -> World)
-> Item -> Item
-> Creature -> Creature
-> World -> World
-> World -> World
charFiringStratI
:: [(Char, ChainEffect)] -- ^ Different firing effects for different characters
-> ChainEffect
charFiringStratI strats eff item cr w = case w ^? creatures . ix cid . crInv charFiringStratI strats eff item cr w = case w ^? creatures . ix cid . crInv
. ix (_crInvSel $ _creatures w IM.! cid) . itAttachment . itCharMode of . ix (_crInvSel $ _creatures w IM.! cid) . itAttachment . itCharMode of
Just (c :<| _) -> fromJust (Prelude.lookup c strats) eff item cr w Just (c :<| _) -> fromMaybe id (Prelude.lookup c strats) eff item cr w
_ -> w _ -> w
where where
cid = _crID cr cid = _crID cr
@@ -84,7 +77,8 @@ increaseFuse fuse itid w = w
decreaseFuse decreaseFuse
:: Int -- ^ Old fuse time :: Int -- ^ Old fuse time
-> Int -- ^ Inventory item reference (I believe) -> Int -- ^ Inventory item reference (I believe)
-> World -> World -> World
-> World
decreaseFuse fuse itid w = w decreaseFuse fuse itid w = w
& creatures . ix 0 . crInv . ix itid %~ & creatures . ix 0 . crInv . ix itid %~
( itScrollUp .~ decreaseFuse newTime ) ( itScrollUp .~ decreaseFuse newTime )
+1 -1
View File
@@ -67,7 +67,7 @@ pistol = defaultGun
, useTimeCheckI , useTimeCheckI
, withSoundI 0 , withSoundI 0
, useAmmo 1 , useAmmo 1
-- , withRandomDirI 0.1 , randSpreadDir
, withMuzFlareI , withMuzFlareI
] ]
, _itLeftClickUse = Nothing , _itLeftClickUse = Nothing
+5 -2
View File
@@ -32,10 +32,13 @@ autoGun = defaultAutoGun
, _itUse = useAmmoParams , _itUse = useAmmoParams
, _itUseModifiers = , _itUseModifiers =
[ ammoCheckI [ ammoCheckI
, charFiringStratI
[('S', hammerCheckI)
]
, useTimeCheckI , useTimeCheckI
, charFiringStratI , charFiringStratI
[('M', torqueBefore 0.05) [('M', torqueBefore 0.08)
,('S', hammerCheckI) ,('S', torqueBefore 0.05)
] ]
, withSoundI autoGunSound , withSoundI autoGunSound
, useAmmo 1 , useAmmo 1
+9
View File
@@ -31,6 +31,7 @@ module Dodge.Item.Weapon.TriggerType
, shootL , shootL
, useTimeCheckI , useTimeCheckI
, ammoCheckI , ammoCheckI
, randSpreadDir
) )
where where
import Dodge.Data import Dodge.Data
@@ -282,6 +283,14 @@ withMuzFlareI f it cr w = tempLightForAt 3 pos2 -- . muzzleFlashAt pos2
where where
--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)
{- | Applies the effect to a randomly rotated creature,
- rotation amount given by wpSpread -}
randSpreadDir :: ChainEffect
randSpreadDir f it cr w = f it (cr & crDir +~ a) $ set randGen g w
where
acc = _wpSpread it
(a, g) = randomR (-acc,acc) $ _randGen w
{- | Applies the effect to a randomly rotated creature. -} {- | Applies the effect to a randomly rotated creature. -}
withRandomDirI withRandomDirI
:: Float -- ^ Max possible rotation :: Float -- ^ Max possible rotation
+3 -2
View File
@@ -9,7 +9,7 @@ import Dodge.Picture
import Dodge.Picture.Layer import Dodge.Picture.Layer
import Dodge.Render.HUD import Dodge.Render.HUD
import Dodge.Render.MenuScreen import Dodge.Render.MenuScreen
import Dodge.Graph --import Dodge.Graph
import Geometry import Geometry
import Picture import Picture
import Polyhedra.Data import Polyhedra.Data
@@ -59,7 +59,8 @@ customMouseCursor w =
$ pictures [ line [V2 (-5) 0,V2 5 0] , line [V2 0 (-5),V2 0 5] ] $ pictures [ line [V2 (-5) 0,V2 5 0] , line [V2 0 (-5),V2 0 5] ]
testPic :: World -> Picture testPic :: World -> Picture
testPic w = color green . pictures . map (flip thickLine 5 . tflat2) . graphToEdges $ _pathGraph w testPic _ = blank
--testPic w = color green . pictures . map (flip thickLine 5 . tflat2) . graphToEdges $ _pathGraph w
crDraw :: World -> Creature -> Picture crDraw :: World -> Creature -> Picture
crDraw w c = _crPict c c w crDraw w c = _crPict c c w