Remove bullet delay

This commit is contained in:
2024-11-29 21:15:12 +00:00
parent d09e715653
commit 234b10df40
4 changed files with 23 additions and 31 deletions
+19 -24
View File
@@ -21,16 +21,14 @@ import qualified ListHelp as List
import Data.Bifunctor
updateBullet :: World -> Bullet -> (World, Maybe Bullet)
updateBullet w bu = case _buDelayFraction bu of
1 -> mvBullet 1 w bu
x -> mvBullet x w (bu & buDelayFraction .~ 1)
updateBullet w bu = mvBullet w bu
mvBullet :: Float -> World -> Bullet -> (World, Maybe Bullet)
mvBullet x w bu
mvBullet :: World -> Bullet -> (World, Maybe Bullet)
mvBullet w bu
| magV (_buVel bu) < 1 || _buTimer bu <= 0 = (endspawn w, Nothing)
| otherwise =
second (fmap updateBulVel)
. hitEffFromBul x w
. hitEffFromBul w
$ applyMagnetsToBul bu w
where
endspawn = fromMaybe id $ do
@@ -139,15 +137,14 @@ makeFlak bu _ w = w & cWorld . lWorld . instantBullets .++~ [f x | x <- xs]
g x v = v +.+ x *.* normalizeV (vNormal v)
hitEffFromBul ::
Float ->
World ->
Bullet ->
(World, Maybe Bullet)
hitEffFromBul x w bu = case _buEffect bu of
PenetrateBullet -> movePenBullet x bu hitstream w
hitEffFromBul w bu = case _buEffect bu of
PenetrateBullet -> movePenBullet bu hitstream w
BounceBullet -> case List.safeHead hitstream of
Nothing -> (w, moveBullet x bu)
Just (hp, crwl) -> fromMaybe (expireAndDamage x bu hitstream w) $ do
Nothing -> (w, moveBullet bu)
Just (hp, crwl) -> fromMaybe (expireAndDamage bu hitstream w) $ do
dir <- bounceDir (hp, crwl)
return
( w
@@ -158,9 +155,9 @@ hitEffFromBul x w bu = case _buEffect bu of
& buTrajectory .~ BasicBulletTrajectory
& buTimer -~ 1
)
DestroyBullet -> expireAndDamage x bu hitstream w
DestroyBullet -> expireAndDamage bu hitstream w
where
ep = sp +.+ x *.* _buVel bu
ep = sp +.+ _buVel bu
sp = _buPos bu
hitstream = thingsHit sp ep w
@@ -177,20 +174,19 @@ damageThingHit bu (p, crwl) = case crwl of
dams = setFromToDams bu p
expireAndDamage ::
Float ->
Bullet ->
[(Point2, Either Creature Wall)] ->
World ->
(World, Maybe Bullet)
expireAndDamage y bt things w = case List.safeHead things of
Nothing -> (w, moveBullet y bt)
expireAndDamage bt things w = case List.safeHead things of
Nothing -> (w, moveBullet bt)
Just x -> (damageThingHit bt x w, destroyAt (fst x) bt)
moveBullet :: Float -> Bullet -> Maybe Bullet
moveBullet x pt =
moveBullet :: Bullet -> Maybe Bullet
moveBullet pt =
Just $
pt
& buPos %~ (+.+ x *.* _buVel pt)
& buPos %~ (+.+ _buVel pt)
& buOldPos .~ _buPos pt
& buTimer -~ 1
@@ -205,17 +201,16 @@ destroyAt hitp pt =
p = _buPos pt
movePenBullet ::
Float ->
Bullet ->
[(Point2, Either Creature Wall)] ->
World ->
(World, Maybe Bullet)
movePenBullet x bu hitstream w = case hitstream of
[] -> (w, moveBullet x bu)
movePenBullet bu hitstream w = case hitstream of
[] -> (w, moveBullet bu)
((p, crwl) : strm) ->
if penThing crwl
then first (damageThingHit bu (p, crwl)) $ movePenBullet x bu strm w
else expireAndDamage x bu hitstream w
then first (damageThingHit bu (p, crwl)) $ movePenBullet bu strm w
else expireAndDamage bu hitstream w
penThing :: Either Creature Wall -> Bool
penThing (Left _) = True
+2 -3
View File
@@ -253,10 +253,9 @@ chainLinkOrientation ::
ItemLink ->
ComposedItem ->
(Point3, Q.Quaternion Float)
chainLinkOrientation (p,q) (par, _, _) (ILink lt f) (child, _, _) =
(p + Q.rotate q p1, q * q1)
chainLinkOrientation (p,q) par (ILink lt f) child = (p + Q.rotate q p1, q * q1)
where
(p1, q1) = f par lt child
(p1, q1) = f (par ^. _1) lt (child ^. _1)
updateItemWithOrientation ::
Creature ->
+1 -2
View File
@@ -15,8 +15,7 @@ import Dodge.Data.Damage
import Geometry.Data
data Bullet = Bullet
{ _buDelayFraction :: Float
, _buEffect :: BulletEffect
{ _buEffect :: BulletEffect
, _buPayload :: BulletPayload
, _buTrajectory :: BulletTrajectory
, _buVel :: Point2
+1 -2
View File
@@ -10,8 +10,7 @@ import Geometry.Data
defaultBullet :: Bullet
defaultBullet =
Bullet
{ _buDelayFraction = 1
, _buEffect = DestroyBullet
{ _buEffect = DestroyBullet
, _buPayload = BulSpark
, _buTrajectory = BasicBulletTrajectory
, _buVel = V2 50 0