Fix minigun
This commit is contained in:
+18
-59
@@ -23,21 +23,17 @@ import System.Random
|
|||||||
updateBullet :: World -> Bullet -> (World,Maybe Bullet)
|
updateBullet :: World -> Bullet -> (World,Maybe Bullet)
|
||||||
updateBullet w bu = case _buState bu of
|
updateBullet w bu = case _buState bu of
|
||||||
DyingBulletState -> (w,Nothing)
|
DyingBulletState -> (w,Nothing)
|
||||||
DelayedBullet x -> mvBulletSlow x w bu
|
DelayedBullet x -> mvBullet x w bu
|
||||||
_ -> mvBullet w bu
|
_ -> mvBullet 1 w bu
|
||||||
|
|
||||||
useAmmoParams :: Maybe Float -> Item -> Creature -> World -> World
|
useAmmoParams :: Item -> Creature -> World -> World
|
||||||
useAmmoParams vfact it cr w = w & instantBullets .:~ (_amBullet bultype
|
useAmmoParams it cr w = w & instantBullets .:~ (_amBullet bultype
|
||||||
& buPos .~ sp
|
& buPos .~ sp
|
||||||
& buTrajectory %~ settrajectory
|
& buTrajectory %~ settrajectory
|
||||||
& buVel %~ (rotateV dir . (muzvel *.*))
|
& buVel %~ (rotateV dir . (muzvel *.*))
|
||||||
& buDrag *~ _rifling (_itParams it)
|
& buDrag *~ _rifling (_itParams it)
|
||||||
& buState %~ setstate
|
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
setstate = case vfact of
|
|
||||||
Nothing -> id
|
|
||||||
Just x -> const $ DelayedBullet x
|
|
||||||
sp = _crPos cr +.+ (muzlength + 10) *.* unitVectorAtAngle dir
|
sp = _crPos cr +.+ (muzlength + 10) *.* unitVectorAtAngle dir
|
||||||
dir = _crDir cr
|
dir = _crDir cr
|
||||||
bultype = _laAmmoType $ _itConsumption it
|
bultype = _laAmmoType $ _itConsumption it
|
||||||
@@ -56,8 +52,8 @@ useAmmoParams vfact it cr w = w & instantBullets .:~ (_amBullet bultype
|
|||||||
return $ BezierTrajectory sp tpos (mouseWorldPos w)
|
return $ BezierTrajectory sp tpos (mouseWorldPos w)
|
||||||
|
|
||||||
{- Update for a generic bullet. -}
|
{- Update for a generic bullet. -}
|
||||||
mvBullet :: World -> Bullet -> (World, Maybe Bullet)
|
mvBullet :: Float -> World -> Bullet -> (World, Maybe Bullet)
|
||||||
mvBullet w bt'
|
mvBullet x w bt'
|
||||||
| t <= 0 || magV (_buVel bt) < 1 = (w,Nothing)
|
| t <= 0 || magV (_buVel bt) < 1 = (w,Nothing)
|
||||||
| otherwise = bimap (maybespawn . maybebounce) (fmap dodrag) $
|
| otherwise = bimap (maybespawn . maybebounce) (fmap dodrag) $
|
||||||
hiteff bt hitstream w
|
hiteff bt hitstream w
|
||||||
@@ -73,37 +69,14 @@ mvBullet w bt'
|
|||||||
(hp,crwl) <- runIdentity (S.head_ hitstream)
|
(hp,crwl) <- runIdentity (S.head_ hitstream)
|
||||||
dir <- bounceDir (hp,crwl)
|
dir <- bounceDir (hp,crwl)
|
||||||
return $ instantBullets .:~ (bt
|
return $ instantBullets .:~ (bt
|
||||||
& buPos .~ hp +.+ (normalizeV (_buPos bt' -.- hp))
|
& buPos .~ hp +.+ normalizeV (_buPos bt' -.- hp)
|
||||||
& buVel %~ reflectIn dir
|
& buVel %~ reflectIn dir
|
||||||
& buTrajectory .~ BasicBulletTrajectory
|
& buTrajectory .~ BasicBulletTrajectory
|
||||||
& buTimer -~ 1
|
& buTimer -~ 1
|
||||||
)
|
)
|
||||||
--maybebounce = case _buEffect bt' of
|
|
||||||
-- BounceBullet -> case runIdentity (S.head_ hitstream) of
|
|
||||||
-- Just (hp, Left cr) | crIsArmouredFrom hp cr -> instantBullets .:~ bouncer
|
|
||||||
-- where
|
|
||||||
-- bouncer = bt
|
|
||||||
-- & buPos .~ pOut
|
|
||||||
-- & buVel .~ reflectVel
|
|
||||||
-- & buTrajectory .~ BasicBulletTrajectory
|
|
||||||
-- & buTimer -~ 1
|
|
||||||
-- pOut = hp +.+ 2 *.* newDir
|
|
||||||
-- reflectVel = reflectIn newDir bulVel --magV bulVel *.* newDir
|
|
||||||
-- newDir = squashNormalizeV (hp -.- _crPos cr)
|
|
||||||
-- bulVel = _buVel bt
|
|
||||||
-- Just (hp, Right wl) -> instantBullets .:~ bouncer
|
|
||||||
-- where
|
|
||||||
-- reflectVel = reflVelWall wl (_buVel bt)
|
|
||||||
-- bouncer = bt
|
|
||||||
-- & buPos .~ pOut
|
|
||||||
-- & buVel .~ reflectVel
|
|
||||||
-- & buTrajectory .~ BasicBulletTrajectory
|
|
||||||
-- & buTimer -~ 1
|
|
||||||
-- pOut = hp +.+ squashNormalizeV (p -.- hp)
|
|
||||||
-- _ -> id
|
|
||||||
-- _ -> id
|
|
||||||
hitstream = thingsHit p (p +.+ vel) w
|
hitstream = thingsHit p (p +.+ vel) w
|
||||||
bt = foldr (\mg b -> _mgField mg mg b) bt' $ _magnets w
|
bt = (foldr (\mg b -> _mgField mg mg b) bt' $ _magnets w)
|
||||||
|
& buState .~ NormalBulletState
|
||||||
dodrag = case _buTrajectory bt of
|
dodrag = case _buTrajectory bt of
|
||||||
BasicBulletTrajectory -> buVel .*.*~ drag
|
BasicBulletTrajectory -> buVel .*.*~ drag
|
||||||
MagnetTrajectory tpos -> buVel .+.+~ 5 *.* normalizeV (tpos -.- _buPos bt)
|
MagnetTrajectory tpos -> buVel .+.+~ 5 *.* normalizeV (tpos -.- _buPos bt)
|
||||||
@@ -114,7 +87,7 @@ mvBullet w bt'
|
|||||||
drag = _buDrag bt
|
drag = _buDrag bt
|
||||||
p = _buPos bt
|
p = _buPos bt
|
||||||
vel = _buVel bt
|
vel = _buVel bt
|
||||||
hiteff = hitEffFromBul
|
hiteff = hitEffFromBul x
|
||||||
t = _buTimer bt
|
t = _buTimer bt
|
||||||
|
|
||||||
bounceDir :: (Point2, Either Creature Wall) -> Maybe Point2
|
bounceDir :: (Point2, Either Creature Wall) -> Maybe Point2
|
||||||
@@ -129,42 +102,28 @@ bulletSpawn bu = case _buSpawn bu of
|
|||||||
BulBall ConcBall -> Just concBall
|
BulBall ConcBall -> Just concBall
|
||||||
BulBall TeslaBall -> Just aStaticBall
|
BulBall TeslaBall -> Just aStaticBall
|
||||||
|
|
||||||
hitEffFromBul :: Bullet
|
hitEffFromBul :: Float -> Bullet
|
||||||
-> Stream (Of (Point2, Either Creature Wall)) Identity ()
|
-> Stream (Of (Point2, Either Creature Wall)) Identity ()
|
||||||
-> World
|
-> World
|
||||||
-> (World,Maybe Bullet)
|
-> (World,Maybe Bullet)
|
||||||
hitEffFromBul = expireAndDamage' setfromtodams
|
hitEffFromBul x = expireAndDamage' x setfromtodams
|
||||||
where
|
where
|
||||||
setfromtodams bu p = map f (_buDamages bu)
|
setfromtodams bu p = map f (_buDamages bu)
|
||||||
where
|
where
|
||||||
f = (dmFrom .~ _buPos bu) . (dmAt .~ p) . (dmTo .~ _buPos bu +.+ _buVel bu)
|
f = (dmFrom .~ _buPos bu) . (dmAt .~ p) . (dmTo .~ _buPos bu +.+ _buVel bu)
|
||||||
|
|
||||||
mvBulletSlow :: Float -> World -> Bullet -> (World, Maybe Bullet)
|
expireAndDamage' :: Float -> (Bullet -> Point2 -> [Damage])
|
||||||
mvBulletSlow x w bt'
|
|
||||||
| t <= 0 || magV (_buVel bt) < 1 = (w,Nothing)
|
|
||||||
| otherwise = second (fmap dodrag) $
|
|
||||||
hiteff bt (thingsHit p (p +.+ vel) w) w
|
|
||||||
where
|
|
||||||
bt = foldr (\mg b -> _mgField mg mg b) bt' $ _magnets w
|
|
||||||
dodrag = (buVel .*.*~ drag)
|
|
||||||
. (buState .~ NormalBulletState)
|
|
||||||
drag = _buDrag bt
|
|
||||||
p = _buPos bt
|
|
||||||
vel = x *.* _buVel bt
|
|
||||||
hiteff = hitEffFromBul
|
|
||||||
t = _buTimer bt
|
|
||||||
expireAndDamage' :: (Bullet -> Point2 -> [Damage])
|
|
||||||
-> Bullet
|
-> Bullet
|
||||||
-> Stream (Of (Point2, Either Creature Wall)) Identity ()
|
-> Stream (Of (Point2, Either Creature Wall)) Identity ()
|
||||||
-> World
|
-> World
|
||||||
-> (World, Maybe Bullet)
|
-> (World, Maybe Bullet)
|
||||||
expireAndDamage' fdm bt things w = case runIdentity $ S.head_ things of
|
expireAndDamage' y fdm bt things w = case runIdentity $ S.head_ things of
|
||||||
Nothing -> (w, moveBullet bt)
|
Nothing -> (w, moveBullet y bt)
|
||||||
Just x -> (doDamages' fdm x bt w, destroyAt' (fst x) bt)
|
Just x -> (doDamages' fdm x bt w, destroyAt' (fst x) bt)
|
||||||
|
|
||||||
moveBullet :: Bullet -> Maybe Bullet
|
moveBullet :: Float -> Bullet -> Maybe Bullet
|
||||||
moveBullet pt = Just $ pt
|
moveBullet x pt = Just $ pt
|
||||||
& buPos %~ (+.+ _buVel pt)
|
& buPos %~ (+.+ x *.* _buVel pt)
|
||||||
& buOldPos .~ _buPos pt
|
& buOldPos .~ _buPos pt
|
||||||
& buTimer -~ 1
|
& buTimer -~ 1
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ defaultWeapon = defaultItem
|
|||||||
defaultBulletWeapon :: Item
|
defaultBulletWeapon :: Item
|
||||||
defaultBulletWeapon = defaultWeapon
|
defaultBulletWeapon = defaultWeapon
|
||||||
& itConsumption .~ defaultBulletLoadable
|
& itConsumption .~ defaultBulletLoadable
|
||||||
& itUse . rUse .~ useAmmoParams Nothing
|
& itUse . rUse .~ useAmmoParams
|
||||||
|
|
||||||
defaultItemValue :: ItemValue
|
defaultItemValue :: ItemValue
|
||||||
defaultItemValue = ItemValue 10 MundaneItem
|
defaultItemValue = ItemValue 10 MundaneItem
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ burstRifle = repeater
|
|||||||
-- ]
|
-- ]
|
||||||
miniGunUse :: Int -> ItemUse
|
miniGunUse :: Int -> ItemUse
|
||||||
miniGunUse i = defaultrUse
|
miniGunUse i = defaultrUse
|
||||||
& rUse .~ useAmmoParams (Just 1)
|
& rUse .~ useAmmoParams
|
||||||
& useDelay .~ NoDelay
|
& useDelay .~ NoDelay
|
||||||
& useMods .~
|
& useMods .~
|
||||||
[ ammoCheckI
|
[ ammoCheckI
|
||||||
@@ -186,23 +186,18 @@ miniGunUse i = defaultrUse
|
|||||||
, withSmoke 1 black 20 200 5
|
, withSmoke 1 black 20 200 5
|
||||||
, withMuzFlareI
|
, withMuzFlareI
|
||||||
, useAmmoAmount i
|
, useAmmoAmount i
|
||||||
|
, withSidePushI (y * 50)
|
||||||
|
, torqueBefore (y * 0.05)
|
||||||
|
, afterRecoil (y * 5)
|
||||||
] <>
|
] <>
|
||||||
concat [
|
[ trigDoAlso' (moddelay x) (modcrpos x) useAmmoParams
|
||||||
[ withSidePushI 50
|
| x <- map ((/fromIntegral i) . fromIntegral) [1..i-1]
|
||||||
, torqueBefore 0.05
|
|
||||||
, afterRecoil recoilAmount
|
|
||||||
, withRandomOffset
|
|
||||||
, withOldDir x
|
|
||||||
, trigDoAlso (useAmmoParams $ Just x)
|
|
||||||
] | x <- map ((/fromIntegral i) . fromIntegral) [1..i-1]
|
|
||||||
]
|
|
||||||
<>
|
|
||||||
[ withSidePushI 50
|
|
||||||
, afterRecoil recoilAmount
|
|
||||||
, withRandomOffset
|
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
recoilAmount = 5
|
y = fromIntegral i
|
||||||
|
moddelay x = itConsumption . laAmmoType . amBullet . buState .~ DelayedBullet x
|
||||||
|
modcrpos x cr = cr & crDir %~ tweenAngles x (_crOldDir cr)
|
||||||
|
& crPos %~ tweenPoints x (_crOldPos cr)
|
||||||
|
|
||||||
miniGunX :: Int -> Item
|
miniGunX :: Int -> Item
|
||||||
miniGunX i = defaultAutoGun
|
miniGunX i = defaultAutoGun
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ module Dodge.Item.Weapon.TriggerType
|
|||||||
, crAtMuzPos
|
, crAtMuzPos
|
||||||
, withOldDir
|
, withOldDir
|
||||||
, trigDoAlso
|
, trigDoAlso
|
||||||
|
, trigDoAlso'
|
||||||
, withTempLight
|
, withTempLight
|
||||||
, withItem
|
, withItem
|
||||||
, withItemUpdate
|
, withItemUpdate
|
||||||
@@ -96,6 +97,13 @@ lockInvFor :: Int -> ChainEffect
|
|||||||
lockInvFor i f it cr = f it cr . (delayedEvents .:~ (i, unlockInv (_crID cr)))
|
lockInvFor i f it cr = f it cr . (delayedEvents .:~ (i, unlockInv (_crID cr)))
|
||||||
. lockInv (_crID cr)
|
. lockInv (_crID cr)
|
||||||
|
|
||||||
|
trigDoAlso'
|
||||||
|
:: (Item -> Item)
|
||||||
|
-> (Creature -> Creature)
|
||||||
|
-> (Item -> Creature -> World -> World)
|
||||||
|
-> ChainEffect
|
||||||
|
trigDoAlso' fit fcr f g itm cr = g itm cr . f (fit itm) (fcr cr)
|
||||||
|
|
||||||
-- Note that this uses the "base" creature and item values
|
-- Note that this uses the "base" creature and item values
|
||||||
trigDoAlso
|
trigDoAlso
|
||||||
:: (Item -> Creature -> World -> World)
|
:: (Item -> Creature -> World -> World)
|
||||||
|
|||||||
+3
-3
@@ -38,6 +38,9 @@ alongSegBy :: Float -> Point2 -> Point2 -> Point2
|
|||||||
alongSegBy !x !a !b = a +.+ y *.* normalizeV (b -.- a)
|
alongSegBy !x !a !b = a +.+ y *.* normalizeV (b -.- a)
|
||||||
where
|
where
|
||||||
y = min x $ dist a b
|
y = min x $ dist a b
|
||||||
|
|
||||||
|
tweenPoints :: Float -> Point2 -> Point2 -> Point2
|
||||||
|
tweenPoints = alongSegBy
|
||||||
-- | Debug version of 'pointInPolygon'.
|
-- | Debug version of 'pointInPolygon'.
|
||||||
errorPointInPolygon :: Int -> Point2 -> [Point2] -> Bool
|
errorPointInPolygon :: Int -> Point2 -> [Point2] -> Bool
|
||||||
errorPointInPolygon !i !p xs
|
errorPointInPolygon !i !p xs
|
||||||
@@ -115,9 +118,6 @@ difference x y
|
|||||||
reflectIn :: Point2 -> Point2 -> Point2
|
reflectIn :: Point2 -> Point2 -> Point2
|
||||||
reflectIn line vec = rotateV (2 * angleBetween line vec) vec
|
reflectIn line vec = rotateV (2 * angleBetween line vec) vec
|
||||||
|
|
||||||
reflectIn' :: Point2 -> Point2 -> Point2
|
|
||||||
reflectIn' line vec = rotateV (2 * angleBetween vec line) vec
|
|
||||||
|
|
||||||
-- | Find angle between two points.
|
-- | Find angle between two points.
|
||||||
-- Not normalised, ranges from -2*pi to 2*pi.
|
-- Not normalised, ranges from -2*pi to 2*pi.
|
||||||
angleBetween :: Point2 -> Point2 -> Float
|
angleBetween :: Point2 -> Point2 -> Float
|
||||||
|
|||||||
Reference in New Issue
Block a user