Files
loop/src/Dodge/Item/Weapon/BatteryGuns.hs
T

220 lines
8.0 KiB
Haskell

module Dodge.Item.Weapon.BatteryGuns (
lasRayAt,
flameBeamCombine,
teslaBeamCombine,
splitBeamCombine,
-- shootTeslaArc,
shootLaser,
circleLaser,
shootDualLaser,
aTractorBeam,
) where
import Dodge.Base
import Dodge.Beam
import Dodge.Creature.HandPos
import Dodge.Data.World
import Dodge.Item.Weapon.LaserPath
import Geometry
import qualified IntMapHelp as IM
import LensHelp
import Picture
--import Control.Monad.State
--lasPulse :: Item
--lasPulse = lasGun
-- & itType . iyBase .~ LASPULSE
-- & itUse . useMods .~
-- [ ammoCheckI
-- , withItem $ \it -> withTempLight 1 (100 * frac it) (xyzV4 (_lasColor $ _itParams it))
-- , withItem $ \it -> withSoundForVol (frac it) tone440sawtoothquietS 2
-- , withItemUpdate itup
-- $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) (frac it * 0.8)
-- , useAmmoAmount 1
-- ]
-- where
-- itup it = it
-- & itParams . lasCycle %~ (\i -> (i+1) `mod` 20)
-- & itParams . lasDamage .~ ceiling ((22 :: Float) * frac it)
-- & itParams . lasColor .~ frac it * orange
-- frac it = 0.5 * (1 + sin (pi * fromIntegral (_lasCycle $ _itParams it) * 0.1))
--lasWidePulse :: Item
--lasWidePulse = lasGun
-- & itType . iyBase .~ LASGUNWIDEPULSE
-- & itParams . lasColor .~ orange
-- & itParams . lasDamage .~ 2
-- & itUse .~ ( ruseInstant shootLaser
-- [ ammoCheckI
-- , withItem $ \it -> withTempLight 1 (100 * frac it) (xyzV4 (_lasColor $ _itParams it))
-- , withItem $ \it -> withSoundForVol (frac it) tone440sawtoothquietS 2
-- , withItemUpdate itup
-- $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) (frac it * 0.8)
-- , useAmmoAmount 1
-- , withItemUpdate itup $ \it -> duplicateOffsets (xs it)
-- ]
-- & useAim . aimWeight .~ 6
-- & useAim . aimRange .~ 1
-- & useAim . aimStance .~ TwoHandTwist
-- )
-- where
-- itup it = it
-- & itParams . lasCycle %~ (\i -> (i+1) `mod` 40)
-- & itParams . lasDamage .~ ceiling ((22 :: Float) * frac it)
-- & itParams . lasColor .~ frac it * orange
-- frac it = 0.5 * (1 + sin (pi * fromIntegral (_lasCycle $ _itParams it) * 0.05))
-- xs it = [ 0.25 * (fromIntegral x - fromIntegral (n'-1) /2) | x <- [0..n'-1] ]
-- where
-- n' = (ceiling $ (150 :: Float) * frac it) :: Int
--lasSway :: Item
--lasSway = lasGun
-- & itType . iyBase .~ LASGUNSWAY
-- & itParams . lasColor .~ orange
-- & itParams . lasDamage .~ 11
-- & itUse .~ ( ruseInstant shootLaser
-- [ ammoCheckI
-- , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
-- , withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
-- , withSoundForI tone440sawtoothquietS 2
-- , useAmmoAmount 1
-- , withItemUpdate itup $ \it -> duplicateOffsets (x it)
-- ]
-- & useAim . aimWeight .~ 6
-- & useAim . aimRange .~ 1
-- & useAim . aimStance .~ TwoHandTwist
-- )
-- where
-- itup = itParams . lasCycle %~ (\i -> (i+1) `mod` 40)
-- x it = [ 15 * sin (pi * fromIntegral x' * 0.05) ]
-- where
-- x' = _lasCycle $ _itParams it
--lasFocus :: Int -> Item
--lasFocus n = lasGunWide n
-- & itType . iyBase .~ LASGUNFOCUS n
-- & itParams . lasColor .~ red
-- & itUse . useMods .~
-- [ ammoCheckI
-- , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
-- , withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
-- , withSoundForI tone440sawtoothquietS 2
-- , useAmmoAmount 1
-- , duplicateOffsetsFocus xs
-- ]
-- where
-- n' = 9 * n
-- xs = [ 0.25 * (fromIntegral x - fromIntegral (n'-1) /2) | x <- [0..n'-1] ]
--lasSwing :: Item
--lasSwing = lasGun
-- & itType . iyBase .~ LASGUNSWING
-- & itParams . lasColor .~ orange
-- & itUse . useMods .~
-- [ ammoCheckI
-- , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
-- , withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
-- , withSoundForI tone440sawtoothquietS 2
-- , useAmmoAmount 1
-- , withItemUpdate itup $ \it -> duplicateOffsetsFocus (x it)
-- ]
-- where
-- itup = itParams . lasCycle %~ (\i -> (i+1) `mod` 200)
-- x it = [-y,y]
-- where
-- y = 15 * sin (pi * fromIntegral x' * 0.01)
-- x' = _lasCycle $ _itParams it
shootLaser :: Item -> Creature -> World -> World
shootLaser it cr =
cWorld . lWorld . lasers
.:~ lasRayAt
(_lasColor $ _itParams it)
(_lasDamage $ _itParams it)
(_phaseV $ _itParams it)
(_crPos cr)
(_crDir cr)
-- this has the feel of a left click item
circleLaser :: Item -> Creature -> World -> World
circleLaser it cr w
| hasLOSIndirect cpos pos w =
w
& cWorld . lWorld . lasers .:~ lasRayAt (_lasColor $ _itParams it) dam phasev pos dir
| otherwise = w
where
cpos = _crPos cr
mwp = mouseWorldPos (w ^. input) (w ^. wCam)
pos = _crPos cr +.+ rotateV dir (V2 0 (max 70 $ dist cpos mwp))
dir = fromIntegral (_lasCycle (_itParams it)) * pi / 1000
phasev = _phaseV . _itParams $ _crInv cr IM.! itRef
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
dam = _lasDamage $ _itParams it
shootDualLaser :: Item -> Creature -> World -> World
shootDualLaser it cr w =
w
& cWorld . lWorld . newBeams . positronBeams .:~ dualRayAt (_lasBeam $ _itParams it) itid w (_lasColor $ _itParams it) dam phasev posl dirl
& cWorld . lWorld . newBeams . electronBeams .:~ basicBeamAt itid w (_lasColor2 $ _itParams it) dam phasev posr dirr
where
itid = _itID it
dir = _crDir cr
pos = _crPos cr +.+ aimlength *.* unitVectorAtAngle dir
aimlength = aimingMuzzleLength cr it
gap = _dbGap . _itParams $ it
posl = pos +.+ (- gap) *.* vNormal (unitVectorAtAngle dir)
posr = pos +.+ gap *.* vNormal (unitVectorAtAngle dir)
mwp = mouseWorldPos (w ^. input) (w ^. wCam)
mwp'
| dist mwp (_crPos cr) < aimlength + 5 = _crPos cr +.+ (aimlength + 5) *.* unitVectorAtAngle dir
| otherwise = mwp
dirl = argV $ mwp' -.- posl
dirr = argV $ mwp' -.- posr
phasev = _phaseV . _itParams $ _crInv cr IM.! itRef
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
dam = _lasDamage $ _itParams it
basicBeamAt :: Int -> World -> Color -> Int -> Float -> Point2 -> Float -> Beam
basicBeamAt itid w col dam phasev pos dir =
Beam
{ _bmDraw = BasicBeamDraw --drawBeam
, _bmPos = pos
, _bmDir = dir
, _bmDamage = dam
, _bmRange = 800
, _bmPhaseV = phasev
, _bmColor = col
, _bmPoints = pos : ps
, _bmFirstPoints = []
, _bmOrigin = Just itid
, _bmType = BeamCombine NoBeamCombine
}
where
(_, ps) = reflectLaserAlong phasev pos (pos +.+ 800 *.* unitVectorAtAngle dir) w
dualRayAt :: BeamType -> Int -> World -> Color -> Int -> Float -> Point2 -> Float -> Beam
dualRayAt bt itid w col dam phasev pos dir =
basicBeamAt itid w col dam phasev pos dir
& bmType .~ bt
aTractorBeam :: Item -> Creature -> World -> World
aTractorBeam _ cr w = w & cWorld . lWorld . tractorBeams .:~ tractorBeamAt spos outpos dir power
where
cpos = _crPos cr
spos = cpos +.+ (_crRad cr + 10) *.* unitVectorAtAngle dir
xpos = cpos +.+ 400 *.* unitVectorAtAngle dir
dir = _crDir cr
outpos = fst $ collidePointWallsFilter (const True) cpos xpos w
power = _attractionPower . _itParams $ _crInv cr IM.! itRef
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
tractorBeamAt :: Point2 -> Point2 -> Float -> Point2 -> TractorBeam
tractorBeamAt pos outpos dir power =
TractorBeam
{ _tbPos = pos
, _tbStartPos = outpos
, _tbVel = d
, _tbTime = 10
}
where
d = unitVectorAtAngle dir * power