Improve static bullets

This commit is contained in:
2022-07-19 13:15:13 +01:00
parent 54ba0fbedc
commit 0a7922ec5e
19 changed files with 287 additions and 134 deletions
+20 -11
View File
@@ -2,11 +2,12 @@ module Dodge.Bullet
( updateBullet
, useAmmoParams
) where
import Dodge.WorldEvent.SpawnParticle
import Dodge.EnergyBall
import Dodge.Creature.Test
import Dodge.Data
import Dodge.Creature.HandPos
import Dodge.Base.Coordinate
import Dodge.WorldEvent.SpawnParticle
import Geometry
import LensHelp
import StreamingHelp
@@ -17,8 +18,6 @@ import Data.Maybe
import Dodge.Movement.Turn
import Dodge.WorldEvent.ThingsHit
import Control.Monad.State
import System.Random
--import Data.Bifunctor
updateBullet :: World -> Bullet -> (World,Maybe Bullet)
updateBullet w bu = case _buState bu of
@@ -54,16 +53,17 @@ useAmmoParams it cr w = w & instantBullets .:~ (_amBullet bultype
{- Update for a generic bullet. -}
mvBullet :: Float -> World -> Bullet -> (World, Maybe Bullet)
mvBullet x w bt'
| t <= 0 || magV (_buVel bt) < 1 = (w,Nothing)
| t <= 0 || magV (_buVel bt) < 1 = (endspawn w,Nothing)
| otherwise = bimap (maybespawn . maybebounce) (fmap dodrag) $
hiteff bt hitstream w
where
endspawn w' = fromMaybe w' $ do
partspawn <- bulletSpawn bt'
return $ partspawn p w'
maybespawn w' = fromMaybe w' $ do
(hp,_) <- runIdentity (S.head_ hitstream)
partspawn <- bulletSpawn bt'
let (thepart,g) = runState (partspawn hp) $ _randGen w'
return $ w' & instantParticles .:~ thepart
& randGen .~ g
return $ partspawn (hp +.+ normalizeV (_buPos bt' -.- hp)) w'
maybebounce = fromMaybe id $ do
guard (_buEffect bt' == BounceBullet)
(hp,crwl) <- runIdentity (S.head_ hitstream)
@@ -95,12 +95,21 @@ bounceDir (_,Right wl) = Just $ uncurry (-.-) (_wlLine wl)
bounceDir (p,Left cr) | crIsArmouredFrom p cr = Just $ vNormal $ p -.- _crPos cr
bounceDir _ = Nothing
bulletSpawn :: Bullet -> Maybe (Point2 -> State StdGen Particle)
bulletSpawn :: Bullet -> Maybe (Point2 -> World -> World)
bulletSpawn bu = case _buSpawn bu of
BulSpark -> Nothing
BulBall IncBall -> Just incBall
BulBall ConcBall -> Just concBall
BulBall TeslaBall -> Just aStaticBall
BulBall IncBall -> Just incBallAt
BulBall ConcBall -> Just $ randParticleAt concBall
BulBall TeslaBall -> Just makeStaticBall
-- where
-- dosatate st p w = w'
-- &
-- where
-- (pt,g) = runState do
-- partspawn <- bulletSpawn bt'
-- let (thepart,g) = runState (partspawn hp) $ _randGen w'
-- return $ w' & instantParticles .:~ thepart
-- & randGen .~ g
hitEffFromBul :: Float -> Bullet
-> Stream (Of (Point2, Either Creature Wall)) Identity ()