subtile collision for walls
Before Width: | Height: | Size: 623 B After Width: | Height: | Size: 454 B |
Before Width: | Height: | Size: 667 B After Width: | Height: | Size: 451 B |
Before Width: | Height: | Size: 656 B After Width: | Height: | Size: 469 B |
Before Width: | Height: | Size: 592 B After Width: | Height: | Size: 486 B |
Before Width: | Height: | Size: 677 B After Width: | Height: | Size: 444 B |
Before Width: | Height: | Size: 652 B After Width: | Height: | Size: 513 B |
Before Width: | Height: | Size: 588 B After Width: | Height: | Size: 471 B |
Before Width: | Height: | Size: 664 B After Width: | Height: | Size: 512 B |
Before Width: | Height: | Size: 652 B After Width: | Height: | Size: 487 B |
Before Width: | Height: | Size: 623 B After Width: | Height: | Size: 481 B |
Before Width: | Height: | Size: 617 B After Width: | Height: | Size: 479 B |
|
@ -40,7 +40,7 @@ placeInteriorIO imat imgmat graph =
|
||||||
let applicable =
|
let applicable =
|
||||||
reverse (L.sortBy (\a b -> size a `compare` size b) (
|
reverse (L.sortBy (\a b -> size a `compare` size b) (
|
||||||
L.filter
|
L.filter
|
||||||
(\a -> clusterRoom a == roomType && size a < size bnds)
|
(\a -> clusterRoom a == roomType && size a <= size bnds)
|
||||||
[minBound .. maxBound] :: [Cluster])
|
[minBound .. maxBound] :: [Cluster])
|
||||||
)
|
)
|
||||||
roomType = fst (head $ reverse $ L.sortBy
|
roomType = fst (head $ reverse $ L.sortBy
|
||||||
|
@ -71,7 +71,7 @@ placeInteriorIO imat imgmat graph =
|
||||||
)
|
)
|
||||||
cmat = clusterMat appl
|
cmat = clusterMat appl
|
||||||
in
|
in
|
||||||
if try > 100 || fromIntegral freeRoom < size appl
|
if try > 10 || fromIntegral freeRoom < size appl
|
||||||
then (g2, mat)
|
then (g2, mat)
|
||||||
else
|
else
|
||||||
if pr + nrows cmat - 1 > fst (matmax bnds) ||
|
if pr + nrows cmat - 1 > fst (matmax bnds) ||
|
||||||
|
|
116
src/Test.hs
|
@ -149,65 +149,11 @@ updateMap dt = do
|
||||||
pos'@(V2 or oc) <- E.get pos
|
pos'@(V2 or oc) <- E.get pos
|
||||||
vel' <- E.get vel
|
vel' <- E.get vel
|
||||||
let npos@(V2 nr nc) = pos' + fmap (* (4 * dt)) vel'
|
let npos@(V2 nr nc) = pos' + fmap (* (4 * dt)) vel'
|
||||||
let ent =
|
let ent = defEntity'
|
||||||
case imgObstacle (imgMat (stateData ud) M.! (floor nr, floor nc)) of
|
{ pos = Set $ Prelude.foldl (checkBoundsCollision pos')
|
||||||
Just (Boundaries (minr, minc) (maxr, maxc))
|
npos
|
||||||
| (nr - fromIntegral (floor nr) >= minr &&
|
(imgObstacle (imgMat (stateData ud) M.! (floor nr, floor nc)))
|
||||||
nr - fromIntegral (floor nr) <= maxr) &&
|
|
||||||
(nc - fromIntegral (floor nc) >= minc &&
|
|
||||||
nc - fromIntegral (floor nc) <= maxc) &&
|
|
||||||
(or - fromIntegral (floor or) < minr ||
|
|
||||||
or - fromIntegral (floor or) > maxr) ->
|
|
||||||
defEntity'
|
|
||||||
{ pos = Set (V2 or nc)
|
|
||||||
}
|
}
|
||||||
| (nr - fromIntegral (floor nr) >= minr &&
|
|
||||||
nr - fromIntegral (floor nr) <= maxr) &&
|
|
||||||
(nc - fromIntegral (floor nc) >= minc &&
|
|
||||||
nc - fromIntegral (floor nc) <= maxc) &&
|
|
||||||
(oc - fromIntegral (floor oc) < minc ||
|
|
||||||
oc - fromIntegral (floor oc) > maxc) ->
|
|
||||||
defEntity'
|
|
||||||
{ pos = Set (V2 nr oc)
|
|
||||||
}
|
|
||||||
| (nr - fromIntegral (floor nr) < minr ||
|
|
||||||
nr - fromIntegral (floor nr) > maxr) &&
|
|
||||||
(nc - fromIntegral (floor nc) < minc ||
|
|
||||||
nc - fromIntegral (floor nc) > maxc) ->
|
|
||||||
defEntity'
|
|
||||||
{ pos = Set npos
|
|
||||||
}
|
|
||||||
| (nr - fromIntegral (floor nr) < minr ||
|
|
||||||
nr - fromIntegral (floor nr) > maxr) &&
|
|
||||||
(nc - fromIntegral (floor nc) >= minc &&
|
|
||||||
nc - fromIntegral (floor nc) <= maxc) ->
|
|
||||||
defEntity'
|
|
||||||
{ pos = Set npos
|
|
||||||
}
|
|
||||||
| (nr - fromIntegral (floor nr) >= minr &&
|
|
||||||
nr - fromIntegral (floor nr) <= maxr) &&
|
|
||||||
(nc - fromIntegral (floor nc) < minc ||
|
|
||||||
nc - fromIntegral (floor nc) > maxc) ->
|
|
||||||
defEntity'
|
|
||||||
{ pos = Set npos
|
|
||||||
}
|
|
||||||
| otherwise ->
|
|
||||||
defEntity'
|
|
||||||
Nothing
|
|
||||||
| Wall /= matrix M.! (floor nr, floor nc) ->
|
|
||||||
defEntity'
|
|
||||||
{ pos = Set npos
|
|
||||||
}
|
|
||||||
| Wall /= matrix M.! (floor nr, floor oc) ->
|
|
||||||
defEntity'
|
|
||||||
{ pos = Set (V2 nr oc)
|
|
||||||
}
|
|
||||||
| Wall /= matrix M.! (floor or, floor nc) ->
|
|
||||||
defEntity'
|
|
||||||
{ pos = Set (V2 or nc)
|
|
||||||
}
|
|
||||||
| otherwise ->
|
|
||||||
defEntity'
|
|
||||||
return ent
|
return ent
|
||||||
putAffection ud
|
putAffection ud
|
||||||
{ worldState = nws
|
{ worldState = nws
|
||||||
|
@ -228,25 +174,27 @@ drawTile ai ctx pr pc row col img =
|
||||||
if (isNothing img)
|
if (isNothing img)
|
||||||
then drawPlayer
|
then drawPlayer
|
||||||
else do
|
else do
|
||||||
if (isNothing mb)
|
if (Prelude.null mb)
|
||||||
then do
|
then do
|
||||||
drawImage
|
drawImage
|
||||||
drawPlayer
|
drawPlayer
|
||||||
else do
|
else do
|
||||||
let (Boundaries (minr, minc) (maxr, maxc)) = fromJust mb
|
if any (\minr -> pr <= fromIntegral (floor pr) + minr) minrs &&
|
||||||
if (pr <= fromIntegral (floor pr) + minr &&
|
any (\minc -> pc >= fromIntegral (floor pc) + minc) mincs
|
||||||
pc >= fromIntegral (floor pc) + minc)
|
|
||||||
then do
|
then do
|
||||||
drawPlayer
|
drawPlayer
|
||||||
drawImage
|
drawImage
|
||||||
else do
|
else do
|
||||||
drawImage
|
drawImage
|
||||||
drawPlayer
|
drawPlayer
|
||||||
-- when (isNothing img) drawPlayer
|
|
||||||
restore ctx
|
restore ctx
|
||||||
where
|
where
|
||||||
tileWidth = 64 :: Double
|
tileWidth = 64 :: Double
|
||||||
tileHeight = 32 :: Double
|
tileHeight = 32 :: Double
|
||||||
|
minrs = Prelude.map (fst . matmin) mb
|
||||||
|
maxrs = Prelude.map (fst . matmax) mb
|
||||||
|
mincs = Prelude.map (snd . matmin) mb
|
||||||
|
maxcs = Prelude.map (snd . matmax) mb
|
||||||
x = realToFrac $ 640 + ((fromIntegral col - pc) +
|
x = realToFrac $ 640 + ((fromIntegral col - pc) +
|
||||||
(fromIntegral row - pr)) * (tileWidth / 2)
|
(fromIntegral row - pr)) * (tileWidth / 2)
|
||||||
y = realToFrac $ 360 - (tileHeight / 2) + ((fromIntegral row - pr) -
|
y = realToFrac $ 360 - (tileHeight / 2) + ((fromIntegral row - pr) -
|
||||||
|
@ -254,7 +202,8 @@ drawTile ai ctx pr pc row col img =
|
||||||
dist = distance (V2 (fromIntegral row) (fromIntegral col))
|
dist = distance (V2 (fromIntegral row) (fromIntegral col))
|
||||||
(V2 (realToFrac pr - 1) (realToFrac pc)) / 4
|
(V2 (realToFrac pr - 1) (realToFrac pc)) / 4
|
||||||
fact =
|
fact =
|
||||||
if (floor pr <= row && floor pc >= col) &&
|
if (pr <= fromIntegral row + maximum minrs &&
|
||||||
|
pc >= fromIntegral col + minimum mincs) &&
|
||||||
isWall (fromJust img)
|
isWall (fromJust img)
|
||||||
then min 1 dist
|
then min 1 dist
|
||||||
else 1
|
else 1
|
||||||
|
@ -288,3 +237,42 @@ drawTile ai ctx pr pc row col img =
|
||||||
closePath ctx
|
closePath ctx
|
||||||
fillColor ctx (rgba 0 255 255 255)
|
fillColor ctx (rgba 0 255 255 255)
|
||||||
fill ctx
|
fill ctx
|
||||||
|
|
||||||
|
checkBoundsCollision
|
||||||
|
:: V2 Double
|
||||||
|
-> V2 Double
|
||||||
|
-> Boundaries Double
|
||||||
|
-> V2 Double
|
||||||
|
checkBoundsCollision
|
||||||
|
pos'@(V2 or oc) acc@(V2 fr fc) (Boundaries (minr, minc) (maxr, maxc))
|
||||||
|
| (fr - fromIntegral (floor fr) >= minr &&
|
||||||
|
fr - fromIntegral (floor fr) <= maxr) &&
|
||||||
|
(fc - fromIntegral (floor fc) >= minc &&
|
||||||
|
fc - fromIntegral (floor fc) <= maxc) &&
|
||||||
|
(or - fromIntegral (floor or) < minr ||
|
||||||
|
or - fromIntegral (floor or) > maxr) =
|
||||||
|
(V2 or fc)
|
||||||
|
| (fr - fromIntegral (floor fr) >= minr &&
|
||||||
|
fr - fromIntegral (floor fr) <= maxr) &&
|
||||||
|
(fc - fromIntegral (floor fc) >= minc &&
|
||||||
|
fc - fromIntegral (floor fc) <= maxc) &&
|
||||||
|
(oc - fromIntegral (floor oc) < minc ||
|
||||||
|
oc - fromIntegral (floor oc) > maxc) =
|
||||||
|
(V2 fr oc)
|
||||||
|
| (fr - fromIntegral (floor fr) < minr ||
|
||||||
|
fr - fromIntegral (floor fr) > maxr) &&
|
||||||
|
(fc - fromIntegral (floor fc) < minc ||
|
||||||
|
fc - fromIntegral (floor fc) > maxc) =
|
||||||
|
acc
|
||||||
|
| (fr - fromIntegral (floor fr) < minr ||
|
||||||
|
fr - fromIntegral (floor fr) > maxr) &&
|
||||||
|
(fc - fromIntegral (floor fc) >= minc &&
|
||||||
|
fc - fromIntegral (floor fc) <= maxc) =
|
||||||
|
acc
|
||||||
|
| (fr - fromIntegral (floor fr) >= minr &&
|
||||||
|
fr - fromIntegral (floor fr) <= maxr) &&
|
||||||
|
(fc - fromIntegral (floor fc) < minc ||
|
||||||
|
fc - fromIntegral (floor fc) > maxc) =
|
||||||
|
acc
|
||||||
|
| otherwise =
|
||||||
|
pos'
|
||||||
|
|
|
@ -14,9 +14,9 @@ data Cluster
|
||||||
clusterMat :: Cluster -> Matrix (Maybe ImgId)
|
clusterMat :: Cluster -> Matrix (Maybe ImgId)
|
||||||
clusterMat ClusterBox1 =
|
clusterMat ClusterBox1 =
|
||||||
M.fromLists
|
M.fromLists
|
||||||
[ [Nothing, Nothing, Nothing]
|
-- [ [ Nothing]
|
||||||
, [Nothing, Just ImgMiscBox1, Nothing]
|
[ [Just ImgMiscBox1]
|
||||||
, [Nothing, Nothing, Nothing]
|
-- , [Nothing, Nothing, Nothing]
|
||||||
]
|
]
|
||||||
|
|
||||||
clusterRoom :: Cluster -> TileState
|
clusterRoom :: Cluster -> TileState
|
||||||
|
|
|
@ -58,9 +58,47 @@ isWall :: ImgId -> Bool
|
||||||
isWall ImgMiscBox1 = False
|
isWall ImgMiscBox1 = False
|
||||||
isWall _ = True
|
isWall _ = True
|
||||||
|
|
||||||
imgObstacle :: Maybe ImgId -> Maybe (Boundaries Double)
|
imgObstacle :: Maybe ImgId -> [(Boundaries Double)]
|
||||||
imgObstacle (Just ImgMiscBox1) = Just (Boundaries (0.2, 0.34) (0.8, 1))
|
imgObstacle (Just ImgMiscBox1) = [Boundaries (0.2, 0.34) (0.8, 1)]
|
||||||
imgObstacle _ = Nothing
|
imgObstacle (Just ImgWallAsc) = [Boundaries (0.37, 0) (0.63, 1)]
|
||||||
|
imgObstacle (Just ImgWallDesc) = [Boundaries (0, 0.37) (1, 0.63)]
|
||||||
|
imgObstacle (Just ImgWallCornerN) =
|
||||||
|
[ Boundaries (0, 0.37) (0.63, 0.63)
|
||||||
|
, Boundaries (0.37, 0.37) (0.63, 1)
|
||||||
|
]
|
||||||
|
imgObstacle (Just ImgWallCornerE) =
|
||||||
|
[ Boundaries (0.37, 0.37) (1, 0.63)
|
||||||
|
, Boundaries (0.37, 0.37) (0.63, 1)
|
||||||
|
]
|
||||||
|
imgObstacle (Just ImgWallCornerS) =
|
||||||
|
[ Boundaries (0.37, 0.37) (1, 0.63)
|
||||||
|
, Boundaries (0.37, 0) (0.63, 0.63)
|
||||||
|
]
|
||||||
|
imgObstacle (Just ImgWallCornerW) =
|
||||||
|
[ Boundaries (0, 0.37) (0.63, 0.63)
|
||||||
|
, Boundaries (0.37, 0) (0.63, 0.63)
|
||||||
|
]
|
||||||
|
imgObstacle (Just ImgWallTNE) =
|
||||||
|
[ Boundaries (0, 0.37) (1, 0.63)
|
||||||
|
, Boundaries (0.37, 0.37) (0.63, 1)
|
||||||
|
]
|
||||||
|
imgObstacle (Just ImgWallTSW) =
|
||||||
|
[ Boundaries (0, 0.37) (1, 0.63)
|
||||||
|
, Boundaries (0.37, 0) (0.63, 0.63)
|
||||||
|
]
|
||||||
|
imgObstacle (Just ImgWallTSE) =
|
||||||
|
[ Boundaries (0.37, 0) (0.63, 1)
|
||||||
|
, Boundaries (0.37, 0.37) (1, 0.63)
|
||||||
|
]
|
||||||
|
imgObstacle (Just ImgWallTNW) =
|
||||||
|
[ Boundaries (0.37, 0) (0.63, 1)
|
||||||
|
, Boundaries (0, 0.37) (0.63, 0.63)
|
||||||
|
]
|
||||||
|
imgObstacle (Just ImgWallCross) =
|
||||||
|
[ Boundaries (0.37, 0) (0.63, 1)
|
||||||
|
, Boundaries (0, 0.37) (1, 0.63)
|
||||||
|
]
|
||||||
|
imgObstacle _ = []
|
||||||
|
|
||||||
data FontId
|
data FontId
|
||||||
= FontBedstead
|
= FontBedstead
|
||||||
|
|