Stop bullets when they hit walls

This commit is contained in:
2021-12-14 19:25:37 +00:00
parent 47391f3850
commit e3402bacf1
8 changed files with 64 additions and 21 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ wallNormal wl = normalizeV . vNormal $ a -.- b
wallsOnLine :: Point2 -> Point2 -> IM.IntMap Wall -> [Wall]
wallsOnLine p1 p2 ws = hitWalls
where
hitPoint w = uncurry (intersectSegSeg p1 p2) (_wlLine w)
hitPoint = uncurry (intersectSegSeg p1 p2) . _wlLine
hitWalls = filter (isJust . hitPoint) (IM.elems ws)
wallsOnLine3D :: Point3 -> Point3 -> IM.IntMap Wall -> [Wall]
+3 -3
View File
@@ -15,13 +15,13 @@ import Control.Lens
{- Update for a generic bullet. -}
mvBullet :: World -> Particle -> (World, Maybe Particle)
mvBullet w bt'
| t <= 0 || magV (_btVel' bt) < 1 = wAnd Nothing
| otherwise = second (fmap dodrag) $ hiteff bt (thingsHitExceptCr mcr p (p +.+ vel) w) w
| t <= 0 || magV (_btVel' bt) < 1 = (w,Nothing)
| otherwise = second (fmap dodrag) $
hiteff bt (thingsHitExceptCr mcr p (p +.+ vel) w) w
where
bt = foldr (\mg b -> _mgField mg mg b) bt' $ _magnets w
dodrag = btVel' %~ (drag *.*)
drag = _btDrag bt
wAnd = (w,)
mcr = _btPassThrough' bt
(p:_) = _btTrail' bt
vel = _btVel' bt
+1 -1
View File
@@ -36,8 +36,8 @@ putLasTurret rotSpeed = sps0 $ PutMachine blue (reverse $ square wdth) defaultMa
}
lasTurret :: MachineType
lasTurret = Turret
--{ _tuWeapon = lasGun
{ _tuWeapon = lasGun
--{ _tuWeapon = autoRifle
, _tuTurnSpeed = 0.1
, _tuFireTime = 0
, _tuMCrID = Nothing
+9
View File
@@ -51,9 +51,18 @@ mvPt pt = Just $ pt
destroyAt :: Point2 -> Particle -> Maybe Particle
destroyAt hitp pt = Just $ pt
& ptUpdate .~ killBulletUpdate
& btTrail' %~ (hitp :)
& btTimer' %~ (\t -> min 3 (t-1))
killBulletUpdate :: World -> Particle -> (World,Maybe Particle)
killBulletUpdate w pt
| _btTimer' pt <= 0 = (w,Nothing)
| otherwise = (w
,Just $ pt & btTimer' -~ 1
& btTrail' %~ (\(x:xs) -> (x:x:xs))
)
penWalls
:: HitCreatureEffect
-> HitWallEffect
+4 -3
View File
@@ -31,12 +31,13 @@ thingsHit sp ep w
where
hitCrs = IM.elems
$ IM.filter (\cr -> circOnSeg sp ep (_crPos cr) (_crRad cr))
$ _creatures w
-- $ creaturesAlongLine sp ep w
crPs = map (\cr -> ssaTriPoint ep (_crPos cr) sp (_crRad cr)) hitCrs
-- $ _creatures w
$ creaturesAlongLine sp ep w
crPs = map (\cr -> ssaTriPoint ep (_crPos cr) sp (_crRad cr)) hitCrs
crs = zip crPs (map Left hitCrs)
hitWls = wallsOnLine sp ep (IM.unions [f b $ f a $ _znObjects $ _wallsZone w | a<-[x-1,x,x+1]
, b<-[y-1,y,y+1]])
--hitWls = wallsOnLine sp ep $ _walls w
(x,y) = zoneOfPoint (0.5 *.* (sp +.+ ep))
f i m = case IM.lookup i m of
Just val -> val