diff --git a/src/Dodge/Base.hs b/src/Dodge/Base.hs index db0f6153b..aaaf00603 100644 --- a/src/Dodge/Base.hs +++ b/src/Dodge/Base.hs @@ -197,6 +197,7 @@ reflectCircCreatures rad p1 p2 cs $ IM.mapMaybe (reflectCircCreature rad p1 p2) cs where f (a,_,_) = magV (a -.- p1) + -- | collides a point with forcefields -- if found, returns point of collision, deflection if required, and the id collidePointFFs :: a @@ -204,24 +205,10 @@ collidePointFFs = undefined collidePointFF :: a collidePointFF = undefined -- ---collidePointFFs :: Point2 -> Point2 -> StdGen -> IM.IntMap ForceField --- -> 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. +-- | Looks for overlap of a circle with walls. -- If found, gives wall -collideCircWallsReturnWall :: Point2 -> Float -> IM.IntMap Wall -> Maybe Wall -collideCircWallsReturnWall p rad ws +overlapCircWallsReturnWall :: Point2 -> Float -> IM.IntMap Wall -> Maybe Wall +overlapCircWallsReturnWall p rad ws = L.fold (safeMinimumOnMaybeL (fmap (dist p) . f . _wlLine)) ws where diff --git a/src/Dodge/Config/Data.hs b/src/Dodge/Config/Data.hs index f27331273..f6ba13e29 100644 --- a/src/Dodge/Config/Data.hs +++ b/src/Dodge/Config/Data.hs @@ -12,6 +12,7 @@ module Dodge.Config.Data ( , resolution_factor , windowX , windowY + , rotate_to_wall ) where import Data.Aeson @@ -27,6 +28,7 @@ data Configuration = Configuration , _resolution_factor :: Int -- ^ Higher values divide screen size, i.e. make the resolution worse , _windowX :: Float , _windowY :: Float + , _rotate_to_wall :: Bool } deriving (Generic, Show) makeLenses ''Configuration @@ -46,4 +48,5 @@ defaultConfig = Configuration , _resolution_factor = 1 , _windowX = 800 , _windowY = 600 + , _rotate_to_wall = True } diff --git a/src/Dodge/Event/Menu.hs b/src/Dodge/Event/Menu.hs index 0874e7d7f..b7f1a0334 100644 --- a/src/Dodge/Event/Menu.hs +++ b/src/Dodge/Event/Menu.hs @@ -1,6 +1,7 @@ module Dodge.Event.Menu ( handlePressedKeyInMenu - ) where + ) + where import Dodge.Data import Dodge.Debug.Terminal import Dodge.Menu diff --git a/src/Dodge/Menu.hs b/src/Dodge/Menu.hs index 26b5e3920..20ab12586 100644 --- a/src/Dodge/Menu.hs +++ b/src/Dodge/Menu.hs @@ -12,7 +12,6 @@ import Preload.Update import Dodge.Base.Window import Dodge.SoundLogic import Picture ---import Geometry import Control.Lens import Data.Maybe @@ -25,8 +24,9 @@ optionMenu = OptionScreen } optionsOptions :: [MenuOption] optionsOptions = - [ Toggle ScancodeV (pushScreen soundMenu) (const "VOLUME") + [ Toggle ScancodeV (pushScreen soundMenu) (const "VOLUME") , Toggle ScancodeG (pushScreen graphicsMenu) (const "GRAPHICS") + , Toggle ScancodeP (pushScreen gameplayOptionsMenu) (const "GAMEPLAY") ] levelMenuOptions :: [MenuOption] levelMenuOptions = @@ -34,6 +34,21 @@ levelMenuOptions = , InvisibleToggle ScancodeO (pushScreen optionMenu) , 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 = OptionScreen { _scTitle = const "OPTIONS:VOLUME" diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index fb3d278e1..bd913c64d 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -8,6 +8,7 @@ module Dodge.Update import Dodge.Data import Dodge.Menu import Dodge.Zone.Data +import Dodge.Config.Data import Dodge.World.Trigger.Data --import Dodge.Config.Data import Dodge.Base @@ -60,7 +61,7 @@ functionalUpdate w = case _menuLayers w of . ppEvents . updateCamera . colCrsWalls - . rotateToOverlappingWall + . ifConfigWallRotate . simpleCrSprings . zoneCreatures . updateWalls @@ -252,6 +253,11 @@ crCrSpring c1 c2 w overlap2 = ((comRad - diff) * _crMass c1 * 0.5 / massT) *.* errorNormalizeV 56 vec massT = _crMass c1 + _crMass c2 +ifConfigWallRotate :: World -> World +ifConfigWallRotate w + | _rotate_to_wall $ _config w = rotateToOverlappingWall w + | otherwise = w + rotateToOverlappingWall :: World -> World rotateToOverlappingWall w = case theWall of Nothing -> w @@ -267,7 +273,7 @@ rotateToOverlappingWall w = case theWall of b' = fromIntegral $ (round b :: Int) cr = you w 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. -}