Rotate camera on chasm edges

This commit is contained in:
2026-02-08 14:32:30 +00:00
parent db24b0ffa6
commit 1d85ee6330
4 changed files with 56 additions and 27 deletions
+10
View File
@@ -1,5 +1,7 @@
module Dodge.Creature.Update (updateCreature) where
import Dodge.Update.Camera.Rotate
import SDL (MouseButton (..))
import Dodge.Creature.Vocalization
import RandomHelp
import Data.Maybe
@@ -128,6 +130,7 @@ chasmTest cr w
| Just (x, y) <- List.find g (w ^. cWorld . cliffs) = w
& soundContinue (CrChasm (_crID cr)) (cr ^. crPos . _xy) debrisS (Just 100)
& tocr . crPos . _xy -~ normalizeV (vNormal (x - y))
& chasmRotate cr (x - y)
| any f (w ^. cWorld . chasms) = w & tocr . crZVel -~ 0.5
| otherwise = w
where
@@ -135,6 +138,13 @@ chasmTest cr w
g = uncurry $ circOnSeg (cr ^. crPos . _xy) (crRad $ cr ^. crType)
f = circInPolygon (cr ^. crPos . _xy) (crRad $ cr ^. crType)
chasmRotate :: Creature -> Point2 -> World -> World
chasmRotate cr v w
| t = rotateTo8 (argV v) w
| otherwise = w
where
t = cr ^. crID == 0 && isNothing (w ^? input . mouseButtons . ix SDL.ButtonRight)
updatePulse :: Pulse -> Pulse
updatePulse p
| p ^. pulseProgress >= p ^. pulseRate = p & pulseProgress .~ 0
+10 -8
View File
@@ -6,6 +6,7 @@ module Dodge.Update.Camera (
updateCamera,
) where
import Dodge.Update.Camera.Rotate
import Linear.V3
import Dodge.Creature.Radius
import Bound
@@ -226,14 +227,15 @@ rotateToOverlappingWall w =
p = you w ^. crPos . _xy
doWallRotate :: Wall -> World -> World
doWallRotate wl w
| b - b' > 0.01 = w & wCam . camRot +~ 0.01
| b - b' < negate 0.01 = w & wCam . camRot -~ 0.01
| otherwise = w
where
a = argV (uncurry (-.-) $ _wlLine wl) - w ^. wCam . camRot
b = a * (4 / pi) -- for 8 way cardinal orientation wrt wall
b' = fromIntegral (round b :: Int)
doWallRotate = rotateTo8 . argV . uncurry (-) . _wlLine
--doWallRotate wl w = rotateTo8
-- | b - b' > 0.01 = w & wCam . camRot +~ 0.01
-- | b - b' < negate 0.01 = w & wCam . camRot -~ 0.01
-- | otherwise = w
-- where
-- a = argV (uncurry (-.-) $ _wlLine wl) - w ^. wCam . camRot
-- b = a * (4 / pi) -- for 8 way cardinal orientation wrt wall
-- b' = fromIntegral (round b :: Int)
clipZoom ::
-- | Furthest viewable distance
+15
View File
@@ -0,0 +1,15 @@
module Dodge.Update.Camera.Rotate (rotateTo8) where
import Dodge.Data.World
import Control.Lens
rotateTo8 :: Float -> World -> World
rotateTo8 a' w
| b - b' > 0.01 = w & wCam . camRot +~ 0.01
| b - b' < negate 0.01 = w & wCam . camRot -~ 0.01
| otherwise = w
where
a = a' - w ^. wCam . camRot
b = a * (4 / pi) -- for 8 way cardinal orientation wrt wall
b' = fromIntegral (round b :: Int)