Fix error in circle wall collision detection
The wall zoning did not take into account the radius of the circle
This commit is contained in:
@@ -96,6 +96,8 @@ firstWorldLoad theConfig = do
|
|||||||
, _uvFrameTicks = 0
|
, _uvFrameTicks = 0
|
||||||
, _uvRAMSave = Nothing
|
, _uvRAMSave = Nothing
|
||||||
, _uvDebug = mempty
|
, _uvDebug = mempty
|
||||||
|
, _uvDebugFloat1 = 10
|
||||||
|
, _uvDebugFloat2 = 0
|
||||||
, _uvDebugMessageOffset = 0
|
, _uvDebugMessageOffset = 0
|
||||||
}
|
}
|
||||||
return $ u & uvScreenLayers .~ [splashMenu u]
|
return $ u & uvScreenLayers .~ [splashMenu u]
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
"_debug_booleans": [
|
"_debug_booleans": [
|
||||||
"Show_ms_frame",
|
"Show_ms_frame",
|
||||||
"Enable_debug",
|
"Enable_debug",
|
||||||
"Collision_test"
|
"Circ_collision_test",
|
||||||
|
"Show_walls_near_segment"
|
||||||
],
|
],
|
||||||
"_debug_view_clip_bounds": "NoRoomClipBoundaries",
|
"_debug_view_clip_bounds": "NoRoomClipBoundaries",
|
||||||
"_gameplay_rotate_to_wall": true,
|
"_gameplay_rotate_to_wall": true,
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ module Dodge.Base.Collide (
|
|||||||
anythingHitCirc,
|
anythingHitCirc,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
--import qualified Data.IntMap.Strict as IM
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import qualified Data.IntSet as IS
|
import qualified Data.IntSet as IS
|
||||||
import Data.List (sortOn)
|
import Data.List (sortOn)
|
||||||
@@ -152,13 +153,12 @@ collideCircWalls sp ep rad = foldl' findPoint (ep, Nothing)
|
|||||||
where
|
where
|
||||||
findPoint (p, mwl) wl =
|
findPoint (p, mwl) wl =
|
||||||
maybe (p, mwl) (,Just wl) . uncurry (intersectSegSeg sp p)
|
maybe (p, mwl) (,Just wl) . uncurry (intersectSegSeg sp p)
|
||||||
. shiftbyrad
|
. shiftbyrad . _wlLine $ wl
|
||||||
. _wlLine
|
-- shiftbyrad (a, b) =
|
||||||
$ wl
|
-- ( a +.+ rad *.* normalizeV (a -.- b)
|
||||||
shiftbyrad (a, b) =
|
-- , b +.+ rad *.* normalizeV (b -.- a)
|
||||||
bimap
|
-- )
|
||||||
f
|
shiftbyrad (a, b) = bimap f f
|
||||||
f
|
|
||||||
( a +.+ rad *.* normalizeV (a -.- b)
|
( a +.+ rad *.* normalizeV (a -.- b)
|
||||||
, b +.+ rad *.* normalizeV (b -.- a)
|
, b +.+ rad *.* normalizeV (b -.- a)
|
||||||
)
|
)
|
||||||
@@ -243,13 +243,16 @@ canSeeIndirect i j w = hasLOSIndirect ipos jpos w
|
|||||||
anythingHitCirc :: Float -> Point2 -> Point2 -> World -> Bool
|
anythingHitCirc :: Float -> Point2 -> Point2 -> World -> Bool
|
||||||
anythingHitCirc rad sp ep w = hitCr || isJust (sequence hitWl)
|
anythingHitCirc rad sp ep w = hitCr || isJust (sequence hitWl)
|
||||||
where
|
where
|
||||||
hitCr = IS.foldr f False $ crixsNearSeg sp ep w
|
x = rad *.* normalizeV (ep - sp)
|
||||||
|
xsp = sp - x
|
||||||
|
xep = ep + x
|
||||||
|
hitCr = IS.foldr f False $ crixsNearSeg xsp xep w
|
||||||
f cid bl =
|
f cid bl =
|
||||||
maybe
|
maybe
|
||||||
False
|
False
|
||||||
(\cr -> null $ intersectCircSeg (_crPos cr) (rad + _crRad cr) sp ep)
|
(\cr -> null $ intersectCircSeg (_crPos cr) (rad + _crRad cr) sp ep)
|
||||||
(w ^? cWorld . lWorld . creatures . ix cid)
|
(w ^? cWorld . lWorld . creatures . ix cid)
|
||||||
|| bl
|
|| bl
|
||||||
hitWl = collideCircWalls sp ep rad $ wlsNearSeg sp ep w
|
hitWl = collideCircWalls sp ep rad $ wlsNearSeg xsp xep w
|
||||||
|
|
||||||
-- this should probably be wallsOnLine or something
|
-- this should probably be wallsOnLine or something
|
||||||
|
|||||||
@@ -82,9 +82,11 @@ data DebugBool
|
|||||||
| Show_wall_search_rays
|
| Show_wall_search_rays
|
||||||
| Show_dda_test
|
| Show_dda_test
|
||||||
| Collision_test
|
| Collision_test
|
||||||
|
| Circ_collision_test
|
||||||
| Show_far_wall_detect
|
| Show_far_wall_detect
|
||||||
| Show_walls_near_point_cursor
|
| Show_walls_near_point_cursor
|
||||||
| Show_walls_near_point_you
|
| Show_walls_near_point_you
|
||||||
|
| Show_walls_near_segment
|
||||||
| Show_zone_near_point_cursor
|
| Show_zone_near_point_cursor
|
||||||
| Inspect_wall
|
| Inspect_wall
|
||||||
| Show_nodes_near_select
|
| Show_nodes_near_select
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ data Universe = Universe
|
|||||||
, _uvFrameTicks :: Word32
|
, _uvFrameTicks :: Word32
|
||||||
, _uvRAMSave :: Maybe World
|
, _uvRAMSave :: Maybe World
|
||||||
, _uvDebug :: M.Map DebugBool DebugItem
|
, _uvDebug :: M.Map DebugBool DebugItem
|
||||||
|
, _uvDebugFloat1 :: Float
|
||||||
|
, _uvDebugFloat2 :: Float
|
||||||
, _uvDebugMessageOffset :: Int
|
, _uvDebugMessageOffset :: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+28
-4
@@ -1,3 +1,4 @@
|
|||||||
|
{-# LANGUAGE LambdaCase #-}
|
||||||
module Dodge.Debug where
|
module Dodge.Debug where
|
||||||
|
|
||||||
import Data.Aeson.Types
|
import Data.Aeson.Types
|
||||||
@@ -23,10 +24,25 @@ debugEvents u = case dbools ^. at Enable_debug of
|
|||||||
dbools = u ^. uvConfig . debug_booleans
|
dbools = u ^. uvConfig . debug_booleans
|
||||||
|
|
||||||
debugEvent :: DebugBool -> Universe -> Universe
|
debugEvent :: DebugBool -> Universe -> Universe
|
||||||
debugEvent db u = case db of
|
debugEvent db u = u & uvDebug . at db .~ debugEvent' u db
|
||||||
Collision_test -> u & uvDebug . at Collision_test ?~ collisionDebugItem u
|
-- case db of
|
||||||
Select_creature -> u & uvDebug . at Select_creature ?~ selectCreatureDebugItem u
|
-- Collision_test -> u & uvDebug . at Collision_test ?~ collisionDebugItem u
|
||||||
_ -> u
|
-- Circ_collision_test -> u & uvDebug . at Circ_collision_test ?~ circCollisionDebugItem u
|
||||||
|
-- Select_creature -> u & uvDebug . at Select_creature ?~ selectCreatureDebugItem u
|
||||||
|
-- _ -> u
|
||||||
|
|
||||||
|
debugEvent' :: Universe -> DebugBool -> Maybe DebugItem
|
||||||
|
debugEvent' u = \case
|
||||||
|
Collision_test -> Just $ collisionDebugItem u
|
||||||
|
Circ_collision_test -> Just $ circCollisionDebugItem u
|
||||||
|
Select_creature -> Just $ selectCreatureDebugItem u
|
||||||
|
Show_walls_near_point_cursor -> Just
|
||||||
|
(DebugItem (const $ drawWallsNearCursor w) (const mempty) NoDebugInfo)
|
||||||
|
Show_walls_near_segment -> Just
|
||||||
|
(DebugItem (const $ drawWallsNearSegment w) (const mempty) NoDebugInfo)
|
||||||
|
_ -> Nothing
|
||||||
|
where
|
||||||
|
w = u ^. uvWorld
|
||||||
|
|
||||||
collisionDebugItem :: Universe -> DebugItem
|
collisionDebugItem :: Universe -> DebugItem
|
||||||
collisionDebugItem u =
|
collisionDebugItem u =
|
||||||
@@ -44,6 +60,14 @@ selectCreatureDebugItem u =
|
|||||||
, _debugInfo = scrollDebugInfoInt (length $ debugSelectCreatureList 0 u) u $ clickGetCreature u
|
, _debugInfo = scrollDebugInfoInt (length $ debugSelectCreatureList 0 u) u $ clickGetCreature u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
circCollisionDebugItem :: Universe -> DebugItem
|
||||||
|
circCollisionDebugItem _ =
|
||||||
|
DebugItem
|
||||||
|
{ _debugPic = drawCircCollisionTest . (^. uvWorld)
|
||||||
|
, _debugMessage = const []
|
||||||
|
, _debugInfo = NoDebugInfo
|
||||||
|
}
|
||||||
|
|
||||||
scrollDebugInfoInt :: Int -> Universe -> DebugInfo -> DebugInfo
|
scrollDebugInfoInt :: Int -> Universe -> DebugInfo -> DebugInfo
|
||||||
scrollDebugInfoInt i u
|
scrollDebugInfoInt i u
|
||||||
| SDL.ScancodeRShift `M.member` (u ^. uvWorld . input . pressedKeys) =
|
| SDL.ScancodeRShift `M.member` (u ^. uvWorld . input . pressedKeys) =
|
||||||
|
|||||||
@@ -108,6 +108,27 @@ drawCollisionTest w = concat $ do
|
|||||||
setLayer DebugLayer (color orange $ line [a, b])
|
setLayer DebugLayer (color orange $ line [a, b])
|
||||||
<> foldMap (drawCrossCol red . fst) (thingHit a b w)
|
<> foldMap (drawCrossCol red . fst) (thingHit a b w)
|
||||||
|
|
||||||
|
drawCircCollisionTest :: World -> Picture
|
||||||
|
drawCircCollisionTest w = concat $ do
|
||||||
|
a <- w ^. input . heldWorldPos . at ButtonLeft
|
||||||
|
b <- w ^. input . heldWorldPos . at ButtonRight
|
||||||
|
let col | (anythingHitCirc 2 a b w) = red
|
||||||
|
| otherwise = green
|
||||||
|
return $
|
||||||
|
setLayer DebugLayer (color col $ line [a, b])
|
||||||
|
<> drawCoord a w <> drawCoord b w
|
||||||
|
|
||||||
|
drawWallsNearSegment :: World -> Picture
|
||||||
|
drawWallsNearSegment w = concat $ do
|
||||||
|
a <- w ^. input . heldWorldPos . at ButtonLeft
|
||||||
|
b <- w ^. input . heldWorldPos . at ButtonRight
|
||||||
|
return . foldMap f $ wlsNearSeg a b w
|
||||||
|
where
|
||||||
|
f wl = setLayer DebugLayer (color rose $ thickLine 3 [a, b])
|
||||||
|
<> drawCoord a w <> drawCoord b w
|
||||||
|
where
|
||||||
|
(a, b) = _wlLine wl
|
||||||
|
|
||||||
-- <> foldMap (drawCross . _crPos) (crsNearSeg a b w)
|
-- <> foldMap (drawCross . _crPos) (crsNearSeg a b w)
|
||||||
-- <> foldMap (drawZoneCol green crZoneSize . zoneOfPoint crZoneSize) (xIntercepts crZoneSize a b)
|
-- <> foldMap (drawZoneCol green crZoneSize . zoneOfPoint crZoneSize) (xIntercepts crZoneSize a b)
|
||||||
-- <> foldMap (drawZoneCol yellow crZoneSize . zoneOfPoint crZoneSize) (yIntercepts' crZoneSize a b)
|
-- <> foldMap (drawZoneCol yellow crZoneSize . zoneOfPoint crZoneSize) (yIntercepts' crZoneSize a b)
|
||||||
@@ -147,7 +168,8 @@ debugDraw' cfig w bl = case bl of
|
|||||||
Show_wall_search_rays -> drawWallSearchRays w
|
Show_wall_search_rays -> drawWallSearchRays w
|
||||||
Show_dda_test -> drawDDATest w
|
Show_dda_test -> drawDDATest w
|
||||||
Show_far_wall_detect -> drawFarWallDetect w
|
Show_far_wall_detect -> drawFarWallDetect w
|
||||||
Show_walls_near_point_cursor -> drawWallsNearCursor w
|
Show_walls_near_point_cursor -> mempty
|
||||||
|
Show_walls_near_segment -> mempty
|
||||||
Show_walls_near_point_you -> drawWallsNearYou w
|
Show_walls_near_point_you -> drawWallsNearYou w
|
||||||
Show_zone_near_point_cursor -> drawZoneNearPointCursor w
|
Show_zone_near_point_cursor -> drawZoneNearPointCursor w
|
||||||
Inspect_wall -> drawInspectWalls w
|
Inspect_wall -> drawInspectWalls w
|
||||||
@@ -160,6 +182,7 @@ debugDraw' cfig w bl = case bl of
|
|||||||
Show_nodes_near_select -> undefined --drawNodesNearSelect w
|
Show_nodes_near_select -> undefined --drawNodesNearSelect w
|
||||||
Show_path_between -> drawPathBetween w
|
Show_path_between -> drawPathBetween w
|
||||||
Collision_test -> mempty
|
Collision_test -> mempty
|
||||||
|
Circ_collision_test -> mempty
|
||||||
Select_creature -> mempty
|
Select_creature -> mempty
|
||||||
|
|
||||||
drawCreatureDisplayTexts :: World -> Picture
|
drawCreatureDisplayTexts :: World -> Picture
|
||||||
@@ -188,9 +211,10 @@ drawWallsNearYou w = concat $ do
|
|||||||
|
|
||||||
drawWallsNearCursor :: World -> Picture
|
drawWallsNearCursor :: World -> Picture
|
||||||
drawWallsNearCursor w =
|
drawWallsNearCursor w =
|
||||||
setLayer DebugLayer $ foldMap f $ wlsNearPoint (mouseWorldPos (_input w) (_wCam w)) w
|
foldMap f $ wlsNearPoint (mouseWorldPos (_input w) (_wCam w)) w
|
||||||
where
|
where
|
||||||
f wl = color rose $ thickLine 3 [a, b]
|
f wl = setLayer DebugLayer (color rose $ thickLine 3 [a, b])
|
||||||
|
<> drawCoord a w <> drawCoord b w
|
||||||
where
|
where
|
||||||
(a, b) = _wlLine wl
|
(a, b) = _wlLine wl
|
||||||
|
|
||||||
@@ -326,6 +350,14 @@ drawMousePosition w =
|
|||||||
where
|
where
|
||||||
mwp = mouseWorldPos (w ^. input) (w ^. wCam)
|
mwp = mouseWorldPos (w ^. input) (w ^. wCam)
|
||||||
|
|
||||||
|
drawCoord :: Point2 -> World -> Picture
|
||||||
|
drawCoord p w =
|
||||||
|
setLayer FixedCoordLayer
|
||||||
|
. uncurryV translate (worldPosToScreen (w ^. wCam) p)
|
||||||
|
. scale 0.1 0.1
|
||||||
|
. text
|
||||||
|
$ shortPoint2 p
|
||||||
|
|
||||||
drawWlIDs :: World -> Picture
|
drawWlIDs :: World -> Picture
|
||||||
drawWlIDs w = setLayer FixedCoordLayer $ foldMap f (w ^. cWorld . lWorld . walls)
|
drawWlIDs w = setLayer FixedCoordLayer $ foldMap f (w ^. cWorld . lWorld . walls)
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ import qualified IntMapHelp as IM
|
|||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
|
|
||||||
testStringInit :: Universe -> [String]
|
testStringInit :: Universe -> [String]
|
||||||
testStringInit u = foldMap prettyShort $ u ^. uvWorld . cWorld . lWorld . projectiles
|
testStringInit u = [show $ u ^. uvDebugFloat1
|
||||||
|
, show $ u ^. uvWorld . input . heldWorldPos . at SDL.ButtonRight]
|
||||||
|
--testStringInit u = foldMap prettyShort $ u ^. uvWorld . cWorld . lWorld . projectiles
|
||||||
-- (map (show . _ebPos) $ u ^. uvWorld . cWorld . lWorld . energyBalls)
|
-- (map (show . _ebPos) $ u ^. uvWorld . cWorld . lWorld . energyBalls)
|
||||||
-- <>
|
-- <>
|
||||||
-- (foldMap prettyShort $ u ^. uvWorld . cWorld . lWorld . bullets)
|
-- (foldMap prettyShort $ u ^. uvWorld . cWorld . lWorld . bullets)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ module Dodge.Update.Input.InGame (
|
|||||||
updateMouseInGame,
|
updateMouseInGame,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Dodge.Update.Input.DebugTest
|
||||||
import Dodge.Item.InvSize
|
import Dodge.Item.InvSize
|
||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
import NewInt
|
import NewInt
|
||||||
@@ -351,6 +352,8 @@ updateFunctionKey uv sc InitialPress = case sc of
|
|||||||
ScancodeF9 -> doQuickload uv
|
ScancodeF9 -> doQuickload uv
|
||||||
ScancodeEscape -> pauseGame uv
|
ScancodeEscape -> pauseGame uv
|
||||||
_ -> uv
|
_ -> uv
|
||||||
|
updateFunctionKey uv ScancodeF3 _ = doDebugTest uv
|
||||||
|
updateFunctionKey uv ScancodeF4 _ = doDebugTest2 uv
|
||||||
updateFunctionKey uv _ _ = uv
|
updateFunctionKey uv _ _ = uv
|
||||||
|
|
||||||
updatePressedButtonsCarte :: World -> World
|
updatePressedButtonsCarte :: World -> World
|
||||||
@@ -585,3 +588,4 @@ maybeExitCombine w
|
|||||||
| ButtonRight `M.member` (w ^. input . mouseButtons) = w
|
| ButtonRight `M.member` (w ^. input . mouseButtons) = w
|
||||||
| otherwise =
|
| otherwise =
|
||||||
w & hud . hudElement . subInventory .~ NoSubInventory
|
w & hud . hudElement . subInventory .~ NoSubInventory
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user