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)
+21 -19
View File
@@ -2800,14 +2800,15 @@ chaseCritInternal src/Dodge/Humanoid.hs 8;" f
chaseCritMv src/Dodge/Creature/ReaderUpdate.hs 121;" f
chaseCritPerceptionUpdate src/Dodge/Creature/Perception.hs 32;" f
chaseCritVocalization src/Dodge/Creature/ChaseCrit.hs 36;" f
chasmRotate src/Dodge/Creature/Update.hs 140;" f
chasmSimpleMaze src/Dodge/Room/Tutorial.hs 294;" f
chasmSpitTerminal src/Dodge/Room/Tutorial.hs 265;" f
chasmTest src/Dodge/Creature/Update.hs 123;" f
chasmTest src/Dodge/Creature/Update.hs 124;" f
chasmWallToSurface src/Dodge/Base/Collide.hs 118;" f
checkCombineSelectionExists src/Dodge/DisplayInventory.hs 100;" f
checkConnection src/Dodge/Inventory/Swap.hs 66;" f
checkDeath src/Dodge/Creature/Update.hs 73;" f
checkDeath' src/Dodge/Creature/Update.hs 76;" f
checkDeath src/Dodge/Creature/Update.hs 74;" f
checkDeath' src/Dodge/Creature/Update.hs 77;" f
checkEndGame src/Dodge/Update.hs 807;" f
checkErrorGL src/Shader/Compile.hs 86;" f
checkFBO src/Framebuffer/Check.hs 6;" f
@@ -2853,7 +2854,7 @@ cleatSide src/Dodge/Cleat.hs 27;" f
click1S src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 783;" f
clicker src/Dodge/Item/Scope.hs 88;" f
clipV src/Geometry/Vector.hs 48;" f
clipZoom src/Dodge/Update/Camera.hs 237;" f
clipZoom src/Dodge/Update/Camera.hs 239;" f
clockCycle src/Dodge/Clock.hs 7;" f
closeButtonToSelectionItem src/Dodge/Inventory/SelectionList.hs 221;" f
closeItemToSelectionItem src/Dodge/Inventory/SelectionList.hs 205;" f
@@ -2926,7 +2927,7 @@ copierItemUpdate src/Dodge/Creature/State.hs 131;" f
copyItemToFloor src/Dodge/FloorItem.hs 14;" f
corDoor src/Dodge/Room/Room.hs 398;" f
cornerList src/Preload/Render.hs 236;" f
corpseOrGib src/Dodge/Creature/Update.hs 91;" f
corpseOrGib src/Dodge/Creature/Update.hs 92;" f
corridor src/Dodge/Room/Corridor.hs 17;" f
corridorBoss src/Dodge/LockAndKey.hs 133;" f
corridorN src/Dodge/Room/Corridor.hs 57;" f
@@ -2936,7 +2937,7 @@ crAwayFromPost src/Dodge/Creature/Test.hs 85;" f
crBlips src/Dodge/RadarSweep.hs 88;" f
crCamouflage src/Dodge/Creature/Picture.hs 33;" f
crCanSeeCr src/Dodge/Creature/Test.hs 52;" f
crCrSpring src/Dodge/Update.hs 917;" f
crCrSpring src/Dodge/Update.hs 919;" f
crCurrentEquipment src/Dodge/Creature/Statistics.hs 62;" f
crDeathSounds src/Dodge/Creature/Vocalization.hs 44;" f
crDexterity src/Dodge/Creature/Statistics.hs 19;" f
@@ -2971,7 +2972,7 @@ crShape src/Dodge/Creature/Shape.hs 8;" f
crSpring src/Dodge/Update.hs 914;" f
crStratConMatches src/Dodge/Creature/Test.hs 80;" f
crStrength src/Dodge/Creature/Statistics.hs 29;" f
crUpdate src/Dodge/Creature/Update.hs 66;" f
crUpdate src/Dodge/Creature/Update.hs 67;" f
crUpdateInvidLocations src/Dodge/Inventory/Location.hs 66;" f
crUpdateItemLocations src/Dodge/Inventory/Location.hs 48;" f
crVocalizationSound src/Dodge/Creature/Vocalization.hs 15;" f
@@ -3259,7 +3260,7 @@ doTextInputOverUniverse src/Dodge/Update/Input/Text.hs 12;" f
doThrust src/Dodge/Projectile/Update.hs 132;" f
doTimeScroll src/Dodge/Update.hs 212;" f
doTmWdWd src/Dodge/WorldEffect.hs 104;" f
doWallRotate src/Dodge/Update/Camera.hs 227;" f
doWallRotate src/Dodge/Update/Camera.hs 228;" f
doWdBl src/Dodge/WorldBool.hs 10;" f
doWdCrBl src/Dodge/CreatureEffect.hs 18;" f
doWdP2f src/Dodge/WdP2f.hs 10;" f
@@ -3402,7 +3403,7 @@ drawZone src/Dodge/Debug/Picture.hs 152;" f
drawZoneCirc src/Dodge/Debug/Picture.hs 293;" f
drawZoneCol src/Dodge/Debug/Picture.hs 149;" f
drawZoneNearPointCursor src/Dodge/Debug/Picture.hs 286;" f
dropAll src/Dodge/Creature/Update.hs 120;" f
dropAll src/Dodge/Creature/Update.hs 121;" f
dropInventoryPath src/Dodge/HeldUse.hs 1346;" f
dropItem src/Dodge/Creature/Action.hs 155;" f
dropper src/Dodge/Item/Scope.hs 82;" f
@@ -3490,13 +3491,13 @@ extraWeaponLinksBelow src/Dodge/Item/Grammar.hs 99;" f
extractRoomPos src/Dodge/RoomPos.hs 6;" f
faceEdges src/Polyhedra.hs 62;" f
facesToVF src/Polyhedra/Geodesic.hs 70;" f
farWallDistDirection src/Dodge/Update/Camera.hs 248;" f
farWallDistDirection src/Dodge/Update/Camera.hs 250;" f
fdiv src/ShortShow.hs 41;" f
feet src/Dodge/Creature/Picture.hs 51;" f
filter3 src/FoldableHelp.hs 76;" f
filterSectionsPair src/Dodge/DisplayInventory.hs 160;" f
findBlips src/Dodge/RadarSweep.hs 63;" f
findBoundDists src/Dodge/Update/Camera.hs 255;" f
findBoundDists src/Dodge/Update/Camera.hs 257;" f
findClosePoint src/Dodge/LevelGen/StaticWalls.hs 155;" f
findClosePoint src/Dodge/LevelGen/StaticWalls/Deprecated.hs 74;" f
findIndex src/IntMapHelp.hs 86;" f
@@ -4423,7 +4424,7 @@ pointerToItemID src/Dodge/Item/Location.hs 42;" f
pointerYourRootItem src/Dodge/Item/Location.hs 33;" f
pointerYourSelectedItem src/Dodge/Item/Location.hs 26;" f
pointsToPoly src/Geometry/ConvexPoly.hs 35;" f
poisonSPic src/Dodge/Creature/Update.hs 116;" f
poisonSPic src/Dodge/Creature/Update.hs 117;" f
poisonSprayer src/Dodge/Item/Held/SprayGuns.hs 17;" f
poke34 src/Shader/Poke.hs 509;" f
pokeArrayOff src/Shader/Poke.hs 521;" f
@@ -4745,6 +4746,7 @@ rotateSHq src/Shape.hs 163;" f
rotateSHx src/Shape.hs 262;" f
rotateSP src/ShapePicture.hs 57;" f
rotateTo src/Polyhedra/Geodesic.hs 65;" f
rotateTo8 src/Dodge/Update/Camera/Rotate.hs 5;" f
rotateToOverlappingWall src/Dodge/Update/Camera.hs 216;" f
rotateToZ src/Quaternion.hs 35;" f
rotateV src/Geometry/Vector.hs 106;" f
@@ -4790,7 +4792,7 @@ scaleSH src/Shape.hs 266;" f
scalp src/Dodge/Creature/Picture.hs 93;" f
scancodeToHotkey src/Dodge/Creature/YourControl.hs 102;" f
scodeToChar src/Dodge/ScodeToChar.hs 6;" f
scorchSPic src/Dodge/Creature/Update.hs 113;" f
scorchSPic src/Dodge/Creature/Update.hs 114;" f
screenBox src/Dodge/Base/Window.hs 54;" f
screenPolygon src/Dodge/Base/Window.hs 18;" f
screenPolygonBord src/Dodge/Base/Window.hs 28;" f
@@ -4869,7 +4871,7 @@ setTargetMv src/Dodge/Creature/ReaderUpdate.hs 83;" f
setTile src/Dodge/Layout.hs 70;" f
setTiles src/Dodge/Layout.hs 67;" f
setTreeInts src/Dodge/Room/Tutorial.hs 93;" f
setViewDistance src/Dodge/Update/Camera.hs 243;" f
setViewDistance src/Dodge/Update/Camera.hs 245;" f
setViewPos src/Dodge/Creature/ReaderUpdate.hs 69;" f
setViewport src/Dodge/Render.hs 448;" f
setVol src/Dodge/Config.hs 47;" f
@@ -5358,7 +5360,7 @@ updateBackspaceRegex src/Dodge/Update/Input/InGame.hs 484;" f
updateBarrel src/Dodge/Barreloid.hs 44;" f
updateBarreloid src/Dodge/Barreloid.hs 16;" f
updateBaseWheelEvent src/Dodge/Update/Scroll.hs 30;" f
updateBounds src/Dodge/Update/Camera.hs 265;" f
updateBounds src/Dodge/Update/Camera.hs 267;" f
updateBulVel src/Dodge/Bullet.hs 57;" f
updateBullet src/Dodge/Bullet.hs 22;" f
updateBullets src/Dodge/Update.hs 601;" f
@@ -5368,8 +5370,8 @@ updateCloud src/Dodge/Update.hs 836;" f
updateClouds src/Dodge/Update.hs 705;" f
updateCombinePositioning src/Dodge/DisplayInventory.hs 40;" f
updateCombineSections src/Dodge/DisplayInventory.hs 47;" f
updateCreature src/Dodge/Creature/Update.hs 35;" f
updateCreature' src/Dodge/Creature/Update.hs 44;" f
updateCreature src/Dodge/Creature/Update.hs 36;" f
updateCreature' src/Dodge/Creature/Update.hs 45;" f
updateCreatureGroups src/Dodge/Update.hs 573;" f
updateCreatureSoundPositions src/Dodge/Update.hs 552;" f
updateCreatureStride src/Dodge/Update.hs 347;" f
@@ -5377,7 +5379,7 @@ updateCreatureStrides src/Dodge/Update.hs 344;" f
updateDebris src/Dodge/Update.hs 608;" f
updateDebrisChunk src/Dodge/Prop/Moving.hs 16;" f
updateDebugMessageOffset src/Dodge/Update.hs 103;" f
updateDelayedEvents src/Dodge/Update.hs 937;" f
updateDelayedEvents src/Dodge/Update.hs 939;" f
updateDisplaySections src/Dodge/DisplayInventory.hs 116;" f
updateDistortion src/Dodge/Distortion.hs 8;" f
updateDistortions src/Dodge/Update.hs 594;" f
@@ -5432,7 +5434,7 @@ updateObjMapMaybe src/Dodge/Update.hs 578;" f
updatePastWorlds src/Dodge/Update.hs 459;" f
updatePreload src/Preload/Update.hs 21;" f
updateProjectile src/Dodge/Projectile/Update.hs 26;" f
updatePulse src/Dodge/Creature/Update.hs 138;" f
updatePulse src/Dodge/Creature/Update.hs 147;" f
updatePulseBall src/Dodge/Update.hs 484;" f
updatePulseLaser src/Dodge/Update.hs 648;" f
updatePulseLasers src/Dodge/Update.hs 479;" f