Add intersecting beams

This commit is contained in:
2022-04-06 11:40:22 +01:00
parent bca1236a85
commit de8da05bdf
9 changed files with 224 additions and 14 deletions
+105 -10
View File
@@ -1,6 +1,8 @@
module Dodge.Item.Weapon.BatteryGuns
( lasGun
, lasGunDual
, lasGunWide
, lasGunWidePulse
, lasGunSway
, lasGunSwing
, lasGunFocus
@@ -14,6 +16,7 @@ import Dodge.Data
import Dodge.Item.Weapon.LaserPath
import Dodge.Creature.HandPos
import Dodge.Particle.TeslaArc
import Dodge.Particle.Flame
import Dodge.SoundLogic.LoadSound
import Dodge.WorldEvent.Flash
import Dodge.WorldEvent.Damage
@@ -137,27 +140,34 @@ lasGunWide n = lasGun
where
n' = 9 * n
xs = [ 0.25 * (fromIntegral x - fromIntegral (n'-1) /2) | x <- [0..n'-1] ]
lasGunWidePulse :: Int -> Item
lasGunWidePulse n = lasGun
& itName .~ "PARALELLASPULSE"++show n
& itType .~ LASGUNWIDE n
lasGunWidePulse :: Item
lasGunWidePulse = lasGun
& itName .~ "LASWIDEPULSE"
& itType .~ LASGUNWIDEPULSE
& itParams . lasColor .~ orange
& itParams . lasDamage .~ 2
& itUse .~ ( ruseInstant shootLaser NoHammer
[ ammoCheckI
, withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
, withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
, withSoundForI tone440sawtoothquietS 2
, 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
, duplicateOffsets xs
, withItemUpdate itup $ \it -> duplicateOffsets (xs it)
]
& useAim . aimSpeed .~ 0.4
& useAim . aimRange .~ 1
& useAim . aimStance .~ TwoHandTwist
)
where
n' = 9 * n
xs = [ 0.25 * (fromIntegral x - fromIntegral (n'-1) /2) | x <- [0..n'-1] ]
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
lasGunSway :: Item
lasGunSway = lasGun
& itName .~ "SWAYLAS"
@@ -197,6 +207,24 @@ lasGunFocus n = lasGunWide n
where
n' = 9 * n
xs = [ 0.25 * (fromIntegral x - fromIntegral (n'-1) /2) | x <- [0..n'-1] ]
lasGunDual :: Item
lasGunDual = lasGun
& itName .~ "DUALAS"
& itType .~ LASGUNDUAL
& itParams . lasColor .~ red
& itUse .~ (ruseInstant shootDualLaser NoHammer
[ ammoCheckI
, withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
, withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
, withSoundForI tone440sawtoothquietS 2
, useAmmoAmount 1
]
& useAim . aimSpeed .~ 0.4
& useAim . aimRange .~ 1
& useAim . aimStance .~ TwoHandTwist
)
lasGunSwing :: Item
lasGunSwing = lasGun
& itName .~ "SWINGLAS"
@@ -404,6 +432,73 @@ shootLaser it cr = instantParticles .:~ lasRayAt (_lasColor $ _itParams it) dam
phasev = _phaseV . _itParams $ _crInv cr IM.! _crInvSel cr
dam = _lasDamage $ _itParams it
shootDualLaser :: Item -> Creature -> World -> World
shootDualLaser it cr w = w
& newBeams . positronBeams .:~ dualRayAt w orange dam phasev posl dirl
& newBeams . electronBeams .:~ dualRayAtNoFlame w blue dam phasev posr dirr
where
dir = _crDir cr
pos = _crPos cr +.+ aimlength *.* unitVectorAtAngle dir
aimlength = aimingMuzzlePos cr it
posl = pos +.+ (-10) * vNormal (unitVectorAtAngle dir)
posr = pos +.+ 10 * vNormal (unitVectorAtAngle dir)
mwp = mouseWorldPos w
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.! _crInvSel cr
dam = _lasDamage $ _itParams it
drawBeam :: Beam -> Picture
drawBeam bm = setLayer 1 $ pictures
[ setDepth 19 . color (brightX 0 0.5 col) $ thickLine 20 ps
, setDepth 19.5 . color (brightX 10 1 col) $ thickLine 3 ps
]
where
col = _bmColor bm
ps = _bmFirstPoints bm
dualRayAt :: World -> Color -> Int -> Float -> Point2 -> Float -> Beam
dualRayAt w col dam phasev pos dir = Beam
{ _bmDraw = drawBeam
, _bmPos = pos
, _bmDir = dir
, _bmDamage = dam
-- , _ptUpdate = mvLaser phasev pos dir
, _bmRange = 800
-- , _ptDamage = dam
, _bmPhaseV = phasev
, _bmColor = col
, _bmPoints = pos:ps
, _bmFirstPoints = []
, _bmType = BeamCombine
$ \(p,(a,b,_),(x,y,_)) -> makeFlame p (2 *.* normalizeV (normalizeV (b-.-a)+.+normalizeV (y-.-x)))
-- $ \(p,(a,b,_),(x,y,_)) -> makeFlame p (V2 5 0)
}
where
(_,ps) = reflectLaserAlong phasev [] pos (pos +.+ 800 *.* unitVectorAtAngle dir) w
-- ps = [pos,pos +.+ 800 *.* unitVectorAtAngle dir]
dualRayAtNoFlame :: World -> Color -> Int -> Float -> Point2 -> Float -> Beam
dualRayAtNoFlame w col dam phasev pos dir = Beam
{ _bmDraw = drawBeam
, _bmPos = pos
, _bmDir = dir
, _bmDamage = dam
-- , _ptUpdate = mvLaser phasev pos dir
, _bmRange = 800
-- , _ptDamage = dam
, _bmPhaseV = phasev
, _bmColor = col
, _bmPoints = pos:ps
, _bmFirstPoints = []
, _bmType = BeamCombine
$ \_ -> id
-- $ \(p,(a,b,_),(x,y,_)) -> makeFlame p (V2 5 0)
}
where
(_,ps) = reflectLaserAlong phasev [] pos (pos +.+ 800 *.* unitVectorAtAngle dir) w
lasRayAt :: Color -> Int -> Float -> Point2 -> Float -> Particle
lasRayAt col dam phasev pos dir = LaserParticle
{ _ptDraw = const blank
+4 -2
View File
@@ -7,6 +7,7 @@ module Dodge.Item.Weapon.SprayGuns
, flameWall
) where
import Dodge.Data
import Dodge.Particle.Flame
--import Dodge.Data.SoundOrigin
--import Dodge.Base
--import Dodge.Zone
@@ -204,7 +205,8 @@ useGasParams nz it cr = _amCreateGas (_aoType (_itConsumption it)) (_nzPressure
pos = _crPos cr +.+ (_nzLength nz *.* unitVectorAtAngle (_crDir cr))
aFlame :: Float -> Point2 -> Float -> Creature -> World -> World
aFlame pressure pos dir cr w = w & instantParticles .:~ aFlameParticle t pos vel (Just $ _crID cr)
aFlame pressure pos dir cr = makeFlame pos vel
--w & instantParticles .:~ aFlameParticle t pos vel Nothing -- (Just $ _crID cr)
where
(t,_) = randomR (99,101) (_randGen w)
-- (t,_) = randomR (99,101) (_randGen w)
vel = (_crPos cr -.- _crOldPos cr) +.+ pressure *.* unitVectorAtAngle dir