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