Add menu option for auto camera rotation

This commit is contained in:
2021-09-11 20:22:44 +01:00
parent f2553ded0e
commit ea333a363b
5 changed files with 34 additions and 22 deletions
+4 -17
View File
@@ -197,6 +197,7 @@ reflectCircCreatures rad p1 p2 cs
$ IM.mapMaybe (reflectCircCreature rad p1 p2) cs $ IM.mapMaybe (reflectCircCreature rad p1 p2) cs
where where
f (a,_,_) = magV (a -.- p1) f (a,_,_) = magV (a -.- p1)
-- | collides a point with forcefields -- | collides a point with forcefields
-- if found, returns point of collision, deflection if required, and the id -- if found, returns point of collision, deflection if required, and the id
collidePointFFs :: a collidePointFFs :: a
@@ -204,24 +205,10 @@ collidePointFFs = undefined
collidePointFF :: a collidePointFF :: a
collidePointFF = undefined collidePointFF = undefined
-- --
--collidePointFFs :: Point2 -> Point2 -> StdGen -> IM.IntMap ForceField -- | Looks for overlap of a circle with walls.
-- -> Maybe (Point2,(Maybe (Point2,StdGen),Int))
--collidePointFFs p1 p2 g fs = listToMaybe $ sortBy f $ IM.elems
-- $ IM.mapMaybe (collidePointFF p1 p2 g) fs
-- where f (a,_) (b,_) = compare (magV (p1 -.- a)) (magV (p1 -.- b))
--
--collidePointFF :: Point2 -> Point2 -> StdGen -> ForceField
-- -> Maybe (Point2,(Maybe (Point2,StdGen),Int))
--collidePointFF p1 p2 g ff = fmap f ip
-- where (p3:p4:_) = _ffLine ff
-- ip = intersectSegSeg p1 p2 p3 p4
-- ref = (_ffDeflect ff) <*> Just g <*> Just (p2 -.- p1) <*> Just ff
-- f p = (p, (ref, _ffID ff))
-- | Looks for first collision of a circle with walls.
-- If found, gives wall -- If found, gives wall
collideCircWallsReturnWall :: Point2 -> Float -> IM.IntMap Wall -> Maybe Wall overlapCircWallsReturnWall :: Point2 -> Float -> IM.IntMap Wall -> Maybe Wall
collideCircWallsReturnWall p rad ws overlapCircWallsReturnWall p rad ws
= L.fold (safeMinimumOnMaybeL (fmap (dist p) . f . _wlLine)) = L.fold (safeMinimumOnMaybeL (fmap (dist p) . f . _wlLine))
ws ws
where where
+3
View File
@@ -12,6 +12,7 @@ module Dodge.Config.Data (
, resolution_factor , resolution_factor
, windowX , windowX
, windowY , windowY
, rotate_to_wall
) where ) where
import Data.Aeson import Data.Aeson
@@ -27,6 +28,7 @@ data Configuration = Configuration
, _resolution_factor :: Int -- ^ Higher values divide screen size, i.e. make the resolution worse , _resolution_factor :: Int -- ^ Higher values divide screen size, i.e. make the resolution worse
, _windowX :: Float , _windowX :: Float
, _windowY :: Float , _windowY :: Float
, _rotate_to_wall :: Bool
} }
deriving (Generic, Show) deriving (Generic, Show)
makeLenses ''Configuration makeLenses ''Configuration
@@ -46,4 +48,5 @@ defaultConfig = Configuration
, _resolution_factor = 1 , _resolution_factor = 1
, _windowX = 800 , _windowX = 800
, _windowY = 600 , _windowY = 600
, _rotate_to_wall = True
} }
+2 -1
View File
@@ -1,6 +1,7 @@
module Dodge.Event.Menu module Dodge.Event.Menu
( handlePressedKeyInMenu ( handlePressedKeyInMenu
) where )
where
import Dodge.Data import Dodge.Data
import Dodge.Debug.Terminal import Dodge.Debug.Terminal
import Dodge.Menu import Dodge.Menu
+16 -1
View File
@@ -12,7 +12,6 @@ import Preload.Update
import Dodge.Base.Window import Dodge.Base.Window
import Dodge.SoundLogic import Dodge.SoundLogic
import Picture import Picture
--import Geometry
import Control.Lens import Control.Lens
import Data.Maybe import Data.Maybe
@@ -27,6 +26,7 @@ optionsOptions :: [MenuOption]
optionsOptions = optionsOptions =
[ Toggle ScancodeV (pushScreen soundMenu) (const "VOLUME") [ Toggle ScancodeV (pushScreen soundMenu) (const "VOLUME")
, Toggle ScancodeG (pushScreen graphicsMenu) (const "GRAPHICS") , Toggle ScancodeG (pushScreen graphicsMenu) (const "GRAPHICS")
, Toggle ScancodeP (pushScreen gameplayOptionsMenu) (const "GAMEPLAY")
] ]
levelMenuOptions :: [MenuOption] levelMenuOptions :: [MenuOption]
levelMenuOptions = levelMenuOptions =
@@ -34,6 +34,21 @@ levelMenuOptions =
, InvisibleToggle ScancodeO (pushScreen optionMenu) , InvisibleToggle ScancodeO (pushScreen optionMenu)
, InvisibleToggle ScancodeC (pushScreen displayControls) , InvisibleToggle ScancodeC (pushScreen displayControls)
] ]
gameplayOptionsMenu :: ScreenLayer
gameplayOptionsMenu = OptionScreen
{ _scTitle = const "OPTIONS:GAMEPLAY"
, _scOptions = gameplayMenuOptions
, _scDefaultEff = popScreen . writeConfig
, _scOptionFlag = NormalOptions
}
gameplayMenuOptions :: [MenuOption]
gameplayMenuOptions =
[ Toggle
ScancodeR
(Just . (config . rotate_to_wall %~ not))
(\w -> "ROTATE TO WALL:" ++ show (_rotate_to_wall $ _config w))
]
soundMenu :: ScreenLayer soundMenu :: ScreenLayer
soundMenu = OptionScreen soundMenu = OptionScreen
{ _scTitle = const "OPTIONS:VOLUME" { _scTitle = const "OPTIONS:VOLUME"
+8 -2
View File
@@ -8,6 +8,7 @@ module Dodge.Update
import Dodge.Data import Dodge.Data
import Dodge.Menu import Dodge.Menu
import Dodge.Zone.Data import Dodge.Zone.Data
import Dodge.Config.Data
import Dodge.World.Trigger.Data import Dodge.World.Trigger.Data
--import Dodge.Config.Data --import Dodge.Config.Data
import Dodge.Base import Dodge.Base
@@ -60,7 +61,7 @@ functionalUpdate w = case _menuLayers w of
. ppEvents . ppEvents
. updateCamera . updateCamera
. colCrsWalls . colCrsWalls
. rotateToOverlappingWall . ifConfigWallRotate
. simpleCrSprings . simpleCrSprings
. zoneCreatures . zoneCreatures
. updateWalls . updateWalls
@@ -252,6 +253,11 @@ crCrSpring c1 c2 w
overlap2 = ((comRad - diff) * _crMass c1 * 0.5 / massT) *.* errorNormalizeV 56 vec overlap2 = ((comRad - diff) * _crMass c1 * 0.5 / massT) *.* errorNormalizeV 56 vec
massT = _crMass c1 + _crMass c2 massT = _crMass c1 + _crMass c2
ifConfigWallRotate :: World -> World
ifConfigWallRotate w
| _rotate_to_wall $ _config w = rotateToOverlappingWall w
| otherwise = w
rotateToOverlappingWall :: World -> World rotateToOverlappingWall :: World -> World
rotateToOverlappingWall w = case theWall of rotateToOverlappingWall w = case theWall of
Nothing -> w Nothing -> w
@@ -267,7 +273,7 @@ rotateToOverlappingWall w = case theWall of
b' = fromIntegral $ (round b :: Int) b' = fromIntegral $ (round b :: Int)
cr = you w cr = you w
p = _crPos cr p = _crPos cr
theWall = collideCircWallsReturnWall p (_crRad cr + 5) (wallsNearPoint p w) theWall = overlapCircWallsReturnWall p (_crRad cr + 5) (wallsNearPoint p w)
{- {-
Finds the IDs of visible walls from a point to another point. -} Finds the IDs of visible walls from a point to another point. -}