Add distance indicator for forcefield gun
This commit is contained in:
@@ -11,6 +11,7 @@ module Dodge.Item.Weapon.ExtraEffect
|
||||
, targetRBCreature
|
||||
, targetCursor
|
||||
, targetLaser
|
||||
, targetDistanceDraw
|
||||
-- , rbSetTarget
|
||||
) where
|
||||
import Dodge.Data
|
||||
@@ -28,6 +29,7 @@ import Geometry.Data
|
||||
import LensHelp
|
||||
import qualified FoldlHelp as L
|
||||
import Sound.Data
|
||||
import ShortShow
|
||||
|
||||
--import Data.Bifunctor
|
||||
import Data.Maybe
|
||||
@@ -75,16 +77,35 @@ targetCursor = defaultTargeting
|
||||
& tgUpdate .~ targetUpdateWith targetCursorUpdate
|
||||
& tgDraw .~ targetSimpleDraw
|
||||
|
||||
targetDraw :: (Item -> Picture) -> Int -> Item -> Creature -> Configuration -> World -> Picture
|
||||
targetDraw f _ it _ cfig w = fromMaybe mempty $ do
|
||||
targetDraw :: (Item -> Picture) -> Item -> Creature -> Configuration -> World -> Picture
|
||||
targetDraw f it _ cfig w = fromMaybe mempty $ do
|
||||
p <- it ^? itTargeting . tgPos . _Just
|
||||
return $ winScale cfig
|
||||
$ setLayer FixedCoordLayer
|
||||
$ color white
|
||||
$ uncurryV translate (worldPosToScreen w p)
|
||||
$ f it
|
||||
targetSimpleDraw :: Int -> Item -> Creature -> Configuration -> World -> Picture
|
||||
targetSimpleDraw :: Item -> Creature -> Configuration -> World -> Picture
|
||||
targetSimpleDraw = targetDraw $ const activeTargetCursorPic
|
||||
|
||||
targetDistanceDraw :: Item -> Creature -> Configuration -> World -> Picture
|
||||
targetDistanceDraw itm _ cfig w = fromMaybe mempty $ do
|
||||
p <- itm ^? itTargeting . tgPos . _Just
|
||||
let p1 = worldPosToScreen w p
|
||||
mwp = mouseWorldPos w
|
||||
p2 = worldPosToScreen w mwp
|
||||
return $ winScale cfig
|
||||
$ setLayer FixedCoordLayer
|
||||
$ color white
|
||||
$ line [p1, p2]
|
||||
<> translate (20) (f p1 p2) (uncurryV translate (0.5 *.* (p1 +.+ p2)) . scale 0.1 0.1 $ text $ shortShow $ dist p mwp)
|
||||
where
|
||||
f (V2 x y) (V2 x' y')
|
||||
| y > y' && x > x' = max (-10) (x'-x)
|
||||
| y > y' && x < x' = min 10 (x'-x)
|
||||
| x > x' = min 10 (x-x')
|
||||
| otherwise = max (-10) (x-x')
|
||||
|
||||
targetRBCreatureUp :: Item -> Creature -> World -> Targeting -> (World, Targeting)
|
||||
targetRBCreatureUp it cr w t
|
||||
| not $ _itIsHeld it = (w, t
|
||||
@@ -114,7 +135,7 @@ targetRBCreatureUp it cr w t
|
||||
cpos <- w ^? creatures . ix cid . crPos
|
||||
Just $ hasLOS cpos (_crPos cr) w
|
||||
|
||||
targetRBCreatureDraw :: Int -> Item -> Creature -> Configuration -> World -> Picture
|
||||
targetRBCreatureDraw :: Item -> Creature -> Configuration -> World -> Picture
|
||||
targetRBCreatureDraw = targetDraw thepic
|
||||
where
|
||||
thepic it | _tgActive $ _itTargeting it = activeTargetCursorPic
|
||||
|
||||
@@ -147,19 +147,22 @@ forceFieldGun = defaultGun
|
||||
, _itUse = ruseInstant useForceFieldGun (HasHammer HammerUp)
|
||||
[ hammerCheckI , ammoCheckI , useAmmoAmount 1]
|
||||
-- , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-4,-4),(-4,4),(4,4),(4,0),(0,0),(0,-4)]
|
||||
, _itTargeting = targetRBPress
|
||||
, _itTargeting = targetRBPress & tgDraw .~ targetDistanceDraw
|
||||
, _itParams = ParamMID Nothing
|
||||
}
|
||||
|
||||
-- I believe because the targeting returns to nothing straight after you release
|
||||
-- the rmb, it is possible for this to do nothing
|
||||
-- TODO investigate more and fix
|
||||
useForceFieldGun :: Item -> Creature -> World -> World
|
||||
useForceFieldGun itm cr w = w
|
||||
& walls %~ IM.insertWith (\_ x -> x) i forceField {_wlID = i}
|
||||
& creatures . ix (_crID cr) . crInv . ix (fromJust (_itInvPos itm)) . itParams . paramMID ?~ i
|
||||
& moveWallIDUnsafe i wlline
|
||||
useForceFieldGun itm cr w = fromMaybe w $ do
|
||||
a <- _tgPos $ _itTargeting itm
|
||||
let wlline = (a,mouseWorldPos w)
|
||||
return $ w
|
||||
& walls %~ IM.insertWith (\_ x -> x) i forceField {_wlID = i}
|
||||
& creatures . ix (_crID cr) . crInv . ix (fromJust (_itInvPos itm)) . itParams . paramMID ?~ i
|
||||
& moveWallIDUnsafe i wlline
|
||||
where
|
||||
i = fromMaybe (IM.newKey (_walls w)) $ itm ^? itParams . paramMID . _Just
|
||||
a = fromJust . _tgPos $ _itTargeting itm
|
||||
wlline = (a,mouseWorldPos w)
|
||||
|
||||
-- grapGun = defaultGun
|
||||
-- { _itName = "grapGun"
|
||||
|
||||
Reference in New Issue
Block a user