Use grid when creating block debris
This commit is contained in:
@@ -12,6 +12,7 @@ import Geometry
|
||||
import Color
|
||||
import LensHelp
|
||||
import RandomHelp
|
||||
import Grid
|
||||
import qualified Quaternion as Q
|
||||
|
||||
import qualified Data.IntSet as IS
|
||||
@@ -29,16 +30,46 @@ makeDoorDebris dr w = w & makeDebris mt col p
|
||||
return (_wlMaterial wl,_wlColor wl)
|
||||
|
||||
makeBlockDebris :: Block -> World -> World
|
||||
makeBlockDebris bl w = w & makeDebris mt col (_blPos bl)
|
||||
--makeBlockDebris bl w = w & makeDebris mt col (_blPos bl)
|
||||
makeBlockDebris bl w = foldr (makeDebris mt col) w ps
|
||||
where
|
||||
dsize = debrisSize mt
|
||||
ps = gridInPolygon dsize $ shrinkPolyOnEdges dsize $ reverse (_blFootprint bl)
|
||||
(mt,col) = fromMaybe (Stone,greyN 0.5) $ do
|
||||
wlids <- w ^? blocks . ix (_blID bl) . blWallIDs
|
||||
(wlid,_) <- IS.minView wlids
|
||||
wl <- w ^? walls . ix wlid
|
||||
return (_wlMaterial wl,_wlColor wl)
|
||||
|
||||
makeDebrisToHeight :: Float -> Material -> Color -> Point2 -> World -> World
|
||||
makeDebrisToHeight = makeDebrisDirectedHeight 1 2 (2*pi) 0
|
||||
|
||||
makeDebris :: Material -> Color -> Point2 -> World -> World
|
||||
makeDebris = makeDebrisDirected 1 2 (2*pi) 0
|
||||
|
||||
makeDebrisDirectedHeight :: Float -> Float -> Float -> Float -> Float -> Material
|
||||
-> Color -> Point2 -> World -> World
|
||||
makeDebrisDirectedHeight mindist maxdist arcrad dir maxh bm col p w = w
|
||||
& flip (foldl' (flip $ plNew props pjID)) thedebris
|
||||
& randGen .~ newg
|
||||
& originsIDsAt [MaterialSound bm i | i <- [0,1,2]] (destroyMatS bm) p
|
||||
where
|
||||
dsize = debrisSize bm
|
||||
(thedebris,newg) = mapM f [10,10 + dsize ..maxh+5] & runState $ _randGen w
|
||||
f h = do
|
||||
v <- rotateV (dir - arcrad/2) <$> randInArcStrip mindist maxdist arcrad
|
||||
q <- Q.vToQuat (V3 0 0 1) <$> randOnUnitSphere
|
||||
spinspeed <- randomR (-0.2,-0.1) & state
|
||||
basedebris <- baseDebris bm
|
||||
return $ basedebris
|
||||
& pjColor .~ col
|
||||
& prPos .~ p
|
||||
& pjVel .~ v
|
||||
& pjQuatSpin .~ Q.axisAngle (vNormal v `v2z` 0) spinspeed
|
||||
& pjQuat .~ q
|
||||
& pjVelZ .~ 0
|
||||
& pjPosZ .~ h
|
||||
|
||||
makeDebrisDirected :: Float
|
||||
-> Float
|
||||
-> Float
|
||||
@@ -67,6 +98,15 @@ makeDebrisDirected mindist maxdist arcrad dir bm col p w = w
|
||||
& pjVelZ .~ 0
|
||||
& pjPosZ .~ h
|
||||
|
||||
debrisSize :: Material -> Float
|
||||
debrisSize mt = case mt of
|
||||
Stone -> 20
|
||||
Glass -> 10
|
||||
Crystal -> 10
|
||||
Dirt -> 20
|
||||
Wood -> 10
|
||||
Metal -> 10
|
||||
|
||||
baseDebris :: Material -> State StdGen Prop
|
||||
baseDebris mt = case mt of
|
||||
Stone -> return stoneDebris
|
||||
|
||||
Reference in New Issue
Block a user