Allow turrets to fire bullets, only good for testing for now

This commit is contained in:
2024-12-24 12:24:27 +00:00
parent fb1553bf3c
commit d739a95197
6 changed files with 130 additions and 96 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ applyMagnetsToBul bu =
doMagnetBuBu :: Magnet -> Bullet -> Bullet
doMagnetBuBu mg bu = case _mgField mg of
MagnetAlign | isclose -> bu
MagnetDeflect | isclose -> bu & buVel %~ vecTurnTo (50 * pi / d) bpos mgdeflectpos
MagnetDeflect | isclose -> bu & buVel %~ vecTurnTo (4 * pi / (d+16)) bpos mgdeflectpos
_ -> bu
where
bvel = bu ^. buVel
+33 -18
View File
@@ -7,6 +7,7 @@ module Dodge.HeldUse (
mcUseHeld,
) where
import Dodge.Item.Weapon.Bullet
import Color
import Control.Monad
import Data.Maybe
@@ -458,36 +459,39 @@ shootBullet ::
World
shootBullet itmtree cr (mz, x, magtree) w = fromMaybe w $ do
thebullet <- getBulletType itmtree magtree mz cr w
return $ foldl' (&) w (replicate x (makeBullet thebullet (itmtree ^. ldtValue) cr mz))
return $ foldl' (&) w (replicate x (makeBullet' thebullet (itmtree ^. ldtValue) cr mz))
makeBullet' :: Bullet -> Item -> Creature -> Muzzle -> World -> World
makeBullet' bu itm cr mz w = makeBullet bu itm bulpos dir . (randGen .~ g) $ w
where
bulpos = _crPos cr + rotateV (_crDir cr) moff
(moff, mrot) = heldItemOrient2D itm cr (_mzPos mz + V2 0 offset) (_mzRot mz)
(a, g) = randomR (- inacc, inacc) $ _randGen w
dir = _crDir cr + mrot + a
inacc = _mzInaccuracy mz
offset = case itm ^? itUse . heldParams . randomOffset of
Just x | x /= 0 -> fst . randomR (- x, x) $ _randGen w
_ -> 0
-- & makeMuzzleSmoke mz itm cr
-- the random generator is not updated here, not sure if that is a problem
makeBullet :: Bullet -> Item -> Creature -> Muzzle -> World -> World
makeBullet thebullet itm cr mz w =
w & randGen .~ g
makeBullet :: Bullet -> Item -> Point2 -> Float -> World -> World
makeBullet thebullet itm bulpos dir w =
w & randGen .~ g''
& cWorld . lWorld . instantBullets
.:~ ( thebullet
& buPos .~ bulpos
-- & buTrajectory .~ BasicBulletTrajectory
& buVel %~ (rotateV dir . (muzvel *.*))
& buDrag *~ drag
)
where
(moff, mrot) = heldItemOrient2D itm cr (_mzPos mz + V2 0 offset) (_mzRot mz)
bulpos = _crPos cr + rotateV (_crDir cr) moff
(a, g'') = randomR (- inacc, inacc) $ _randGen w
inacc = _mzInaccuracy mz
g = _randGen w
(drag, g') = case _rifling (_heldParams $ _itUse itm) of
ConstFloat x -> (x, g'')
UniRandFloat x y -> randomR (x, y) g''
(muzvel, g) = case _muzVel $ _heldParams $ _itUse itm of
ConstFloat x -> (x, g)
UniRandFloat x y -> randomR (x, y) g
(muzvel, g'') = case _muzVel $ _heldParams $ _itUse itm of
ConstFloat x -> (x, g')
UniRandFloat x y -> randomR (x, y) g'
dir = _crDir cr + mrot + a
offset = case itm ^? itUse . heldParams . randomOffset of
Just x | x /= 0 -> fst . randomR (- x, x) $ _randGen w
_ -> 0
mcUseHeld :: HeldItemType -> Item -> Machine -> World -> World
mcUseHeld hit = case hit of
@@ -555,7 +559,18 @@ mcShootLaser _ mc = cWorld . lWorld . lasers .:~ lasRayAt yellow dam phasev pos
dam = 11
mcShootAuto :: Item -> Machine -> World -> World
mcShootAuto _ _ = id
mcShootAuto itm mc w
| Just (FixedRate x 0) <- mc ^? mcType . mctTurret . tuWeapon . itUse . heldDelay
= w & cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon
. itUse . heldDelay . rateTime .~ x
& makeBullet defaultBullet itm pos dir
| otherwise
= w & cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon
. itUse . heldDelay . rateTime -~ 1
where
pos = _mcPos mc +.+ 20 *.* unitVectorAtAngle dir
dir = mc ^?! mcType . _McTurret . tuDir
-- | assumes that the item is held
shootTeslaArc :: Item -> Creature -> Muzzle -> World -> World
+12
View File
@@ -8,6 +8,18 @@ import Dodge.LevelGen.PlacementHelper
import Geometry
import LensHelp
putTurret :: Item -> Float -> Placement
putTurret itm rotSpeed =
sps0 $
PutMachine
(reverse $ square 10)
( defaultMachine
& mcColor .~ blue
& mcType .~ (turret itm & _McTurret . tuTurnSpeed .~ rotSpeed)
& mcHP .~ 50000
)
defaultMachineWall
putLasTurret :: Float -> Placement
putLasTurret rotSpeed =
sps0 $
+3 -1
View File
@@ -1,5 +1,6 @@
module Dodge.Room.LasTurret where
import Dodge.Item.Held.Cane
import qualified Data.Set as S
import Dodge.Cleat
import Dodge.Data.GenWorld
@@ -23,7 +24,8 @@ import RandomHelp
cenLasTur :: Room
cenLasTur =
roomNgon 8 200 & rmPmnts
.~ [ putLasTurret 0.02
-- .~ [ putLasTurret 0.02
.~ [ putTurret autoRifle 0.02
, heightWallPS (resetPLUse $ rprBoolShift (const . isInLnk) (shiftInBy 100)) 30 covershape
, mntLightLnkCond $ rprBool $ const . isInLnk
]