Commit before pushing more input events into update

This commit is contained in:
2022-10-29 22:33:10 +01:00
parent afaef480db
commit e3155752ba
36 changed files with 121 additions and 147 deletions
+1 -1
View File
@@ -140,7 +140,7 @@ allVisibleWalls :: World -> [(Point2, Wall)]
{-# INLINE allVisibleWalls #-} {-# INLINE allVisibleWalls #-}
allVisibleWalls w = concatMap (flip (visibleWalls vPos) w . (+.+ vPos)) $ nRays 20 allVisibleWalls w = concatMap (flip (visibleWalls vPos) w . (+.+ vPos)) $ nRays 20
where where
vPos = w ^. cWorld . lWorld . camPos . camViewFrom vPos = w ^. cWorld . camPos . camViewFrom
--allVisibleWalls :: World -> StreamOf (Point2,Wall) --allVisibleWalls :: World -> StreamOf (Point2,Wall)
--{-# INLINE allVisibleWalls #-} --{-# INLINE allVisibleWalls #-}
+1 -1
View File
@@ -78,7 +78,7 @@ useAmmoParams it cr w =
return $ FlechetteTrajectory tpos return $ FlechetteTrajectory tpos
BezierTrajectory{} -> fromMaybe BasicBulletTrajectory $ do BezierTrajectory{} -> fromMaybe BasicBulletTrajectory $ do
tpos <- it ^? itTargeting . tgPos . _Just tpos <- it ^? itTargeting . tgPos . _Just
return $ BezierTrajectory sp tpos (mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos)) return $ BezierTrajectory sp tpos (mouseWorldPos (w ^. input) (w ^. cWorld . camPos))
bounceDir :: (Point2, Either Creature Wall) -> Maybe Point2 bounceDir :: (Point2, Either Creature Wall) -> Maybe Point2
bounceDir (_, Right wl) | _wlBouncy wl = Just $ uncurry (-.-) (_wlLine wl) bounceDir (_, Right wl) | _wlBouncy wl = Just $ uncurry (-.-) (_wlLine wl)
+3 -3
View File
@@ -26,7 +26,7 @@ blinkActionMousePos cr w =
& inverseShockwaveAt cpos 40 2 2 & inverseShockwaveAt cpos 40 2 2
where where
cid = _crID cr cid = _crID cr
p1 = mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) p1 = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
cpos = _crPos cr cpos = _crPos cr
--p2 = bouncePoint (const True) 1 cpos p1 w --p2 = bouncePoint (const True) 1 cpos p1 w
p2 = pushIntoMaybe $ collideCircWalls cpos p1 r (wlsNearSeg cpos p1 w) p2 = pushIntoMaybe $ collideCircWalls cpos p1 r (wlsNearSeg cpos p1 w)
@@ -70,7 +70,7 @@ unsafeBlinkAction cr w
wl <- snd $ collidePointWallsFilter (const True) mwp cpos w wl <- snd $ collidePointWallsFilter (const True) mwp cpos w
return (isLHS mwp `uncurry` _wlLine wl) return (isLHS mwp `uncurry` _wlLine wl)
cid = _crID cr cid = _crID cr
mwp = mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
cpos = _crPos cr cpos = _crPos cr
blinkShockwave :: blinkShockwave ::
@@ -96,7 +96,7 @@ blinkActionFail cr w =
distR = 120 distR = 120
distortionBulge = RadialDistortion cpos (cpos +.+ V2 distR 0) (cpos +.+ V2 0 distR) 1.9 distortionBulge = RadialDistortion cpos (cpos +.+ V2 distR 0) (cpos +.+ V2 0 distR) 1.9
cid = _crID cr cid = _crID cr
p1 = mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) p1 = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
cpos = _crPos cr cpos = _crPos cr
p2 = bouncePoint (const True) 1 cpos p1 w p2 = bouncePoint (const True) 1 cpos p1 w
r = 1.5 * _crRad cr r = 1.5 * _crRad cr
+2 -2
View File
@@ -28,8 +28,8 @@ creatureDisplayText w cr =
cr cr
where where
lw = w ^. cWorld . lWorld lw = w ^. cWorld . lWorld
campos = w ^. cWorld . lWorld . camPos . camViewFrom campos = w ^. cWorld . camPos . camViewFrom
theScale = 0.15 / (w ^. cWorld . lWorld . camPos . camZoom) theScale = 0.15 / (w ^. cWorld . camPos . camZoom)
cpos = _crPos cr cpos = _crPos cr
v = cpos -.- campos v = cpos -.- campos
(V2 x y) = campos +.+ v +.+ _crRad cr *.* normalizeV v (V2 x y) = campos +.+ v +.+ _crRad cr *.* normalizeV v
+4 -4
View File
@@ -57,12 +57,12 @@ wasdWithAiming w speed cr
| otherwise = crMvAbsolute (speed *.* movAbs) . set crMvDir dir | otherwise = crMvAbsolute (speed *.* movAbs) . set crMvDir dir
theTurn cr' = creatureTurnTowardDir (_crMvDir cr') 0.2 cr' theTurn cr' = creatureTurnTowardDir (_crMvDir cr') 0.2 cr'
movDir = wasdDir w movDir = wasdDir w
dir = (w ^. cWorld . lWorld . camPos . camRot) + argV movDir dir = (w ^. cWorld . camPos . camRot) + argV movDir
movAbs = rotateV (w ^. cWorld . lWorld . camPos . camRot) $ normalizeV movDir movAbs = rotateV (w ^. cWorld . camPos . camRot) $ normalizeV movDir
isAiming = _posture (_crStance cr) == Aiming isAiming = _posture (_crStance cr) == Aiming
mouseDir = case cr ^? crInv . ix (crSel cr) . itScope . scopePos of mouseDir = case cr ^? crInv . ix (crSel cr) . itScope . scopePos of
Just _ -> argV $ mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) -.- _crPos cr Just _ -> argV $ mouseWorldPos (w ^. input) (w ^. cWorld . camPos) -.- _crPos cr
_ -> argV (_mousePos (_input w)) + (w ^. cWorld . lWorld . camPos . camRot) _ -> argV (_mousePos (_input w)) + (w ^. cWorld . camPos . camRot)
wasdM :: SDL.Scancode -> Point2 wasdM :: SDL.Scancode -> Point2
wasdM scancode = case scancode of wasdM scancode = case scancode of
+4 -4
View File
@@ -12,7 +12,7 @@ import Geometry
findBoundDists :: Configuration -> World -> (Float, Float, Float, Float) findBoundDists :: Configuration -> World -> (Float, Float, Float, Float)
findBoundDists cfig w findBoundDists cfig w
| debugOn Bound_box_screen cfig = (hh, - hh, hw, - hw) | debugOn Bound_box_screen cfig = (hh, - hh, hw, - hw)
| otherwise = fromMaybe (0, 0, 0, 0) $ farWallDistDirection (w ^. cWorld . lWorld . camPos . camCenter) w | otherwise = fromMaybe (0, 0, 0, 0) $ farWallDistDirection (w ^. cWorld . camPos . camCenter) w
where where
hw = halfWidth cfig hw = halfWidth cfig
hh = halfHeight cfig hh = halfHeight cfig
@@ -20,9 +20,9 @@ findBoundDists cfig w
updateBounds :: Universe -> Universe updateBounds :: Universe -> Universe
updateBounds uv = updateBounds uv =
uv uv
& uvWorld . cWorld . lWorld . camPos . camBoundDist .~ bdists & uvWorld . cWorld . camPos . camBoundDist .~ bdists
& uvWorld . cWorld . lWorld . camPos . camBoundBox & uvWorld . cWorld . camPos . camBoundBox
.~ map ((+.+ w ^. cWorld . lWorld . camPos . camCenter) . rotateV (w ^. cWorld . lWorld . camPos . camRot)) (rectNSWE n s w' e) .~ map ((+.+ w ^. cWorld . camPos . camCenter) . rotateV (w ^. cWorld . camPos . camRot)) (rectNSWE n s w' e)
where where
w = _uvWorld uv w = _uvWorld uv
cfig = _uvConfig uv cfig = _uvConfig uv
+4 -1
View File
@@ -6,6 +6,7 @@
module Dodge.Data.CWorld ( module Dodge.Data.CWorld (
module Dodge.Data.CWorld, module Dodge.Data.CWorld,
module Dodge.Data.LWorld, module Dodge.Data.LWorld,
module Dodge.Data.CamPos
) where ) where
import Dodge.Data.LWorld import Dodge.Data.LWorld
@@ -15,11 +16,13 @@ import Data.Aeson.TH
--import Dodge.Data.GenParams --import Dodge.Data.GenParams
import Dodge.GameRoom import Dodge.GameRoom
import Geometry.ConvexPoly import Geometry.ConvexPoly
import Dodge.Data.CamPos
data CWorld = CWorld data CWorld = CWorld
{ _lWorld :: LWorld { _lWorld :: LWorld
, _camPos :: CamPos
, _cwGen :: CWGen , _cwGen :: CWGen
, _cwClock :: Int , _cClock :: Int
, _pastWorlds :: [LWorld] , _pastWorlds :: [LWorld]
, _timeFlow :: TimeFlowStatus , _timeFlow :: TimeFlowStatus
} }
+6
View File
@@ -9,6 +9,7 @@ import qualified Data.Set as S
import Dodge.Data.CWorld import Dodge.Data.CWorld
import Geometry.Data import Geometry.Data
import SDL (MouseButton, Scancode) import SDL (MouseButton, Scancode)
import qualified Data.Text as T
data Input = Input data Input = Input
{ _mousePos :: Point2 { _mousePos :: Point2
@@ -24,10 +25,15 @@ data Input = Input
, _rSelect :: Point2 , _rSelect :: Point2
, _clickMousePos :: Point2 , _clickMousePos :: Point2
, _backspaceTimer :: Int , _backspaceTimer :: Int
, _textInput :: TextInput
} }
data TextInput = RejectTextInput
| AcceptTextInput {_textInputText :: T.Text}
data WorldHammer data WorldHammer
= SubInvHam = SubInvHam
| DoubleMouseHam | DoubleMouseHam
deriving (Eq, Ord, Show, Read, Enum, Bounded) deriving (Eq, Ord, Show, Read, Enum, Bounded)
makeLenses ''Input makeLenses ''Input
makeLenses ''TextInput
+1 -4
View File
@@ -45,10 +45,8 @@ module Dodge.Data.LWorld (
module Dodge.Data.TractorBeam, module Dodge.Data.TractorBeam,
module Dodge.Data.Wall, module Dodge.Data.Wall,
module Dodge.Data.WorldEffect, module Dodge.Data.WorldEffect,
module Dodge.Data.CamPos
) where ) where
import Dodge.Data.CamPos
import Data.Set (Set) import Data.Set (Set)
import Control.Lens import Control.Lens
import Data.Aeson import Data.Aeson
@@ -100,8 +98,7 @@ import qualified IntMapHelp as IM
import Picture.Data import Picture.Data
data LWorld = LWorld data LWorld = LWorld
{ _camPos :: CamPos { _creatures :: IM.IntMap Creature
, _creatures :: IM.IntMap Creature
, _crZoning :: IM.IntMap (IM.IntMap IS.IntSet) , _crZoning :: IM.IntMap (IM.IntMap IS.IntSet)
, _creatureGroups :: IM.IntMap CrGroupParams , _creatureGroups :: IM.IntMap CrGroupParams
, _itemLocations :: IM.IntMap ItemLocation , _itemLocations :: IM.IntMap ItemLocation
+6 -6
View File
@@ -39,11 +39,11 @@ lineOnScreenCone cfig w p1 p2 =
|| pointInPolygon p2 sp || pointInPolygon p2 sp
|| any (isJust . uncurry (intersectSegSeg p1 p2)) sps || any (isJust . uncurry (intersectSegSeg p1 p2)) sps
where where
sp' = screenPolygon cfig (w ^. cWorld . lWorld . camPos) sp' = screenPolygon cfig (w ^. cWorld . camPos)
vp = w ^. cWorld . lWorld . camPos . camViewFrom vp = w ^. cWorld . camPos . camViewFrom
sp sp
| pointInPolygon vp sp' = sp' | pointInPolygon vp sp' = sp'
| otherwise = orderPolygon ((w ^. cWorld . lWorld . camPos . camViewFrom) : sp') | otherwise = orderPolygon ((w ^. cWorld . camPos . camViewFrom) : sp')
sps = zip sp (tail sp ++ [head sp]) sps = zip sp (tail sp ++ [head sp])
pointOnScreen :: Configuration -> CamPos -> Point2 -> Bool pointOnScreen :: Configuration -> CamPos -> Point2 -> Bool
@@ -56,13 +56,13 @@ drawWallFace cfig w wall
where where
(x, y) = _wlLine wall (x, y) = _wlLine wall
points = extendConeToScreenEdge cfig w sightFrom (x, y) points = extendConeToScreenEdge cfig w sightFrom (x, y)
sightFrom = w ^. cWorld . lWorld . camPos . camViewFrom sightFrom = w ^. cWorld . camPos . camViewFrom
extendConeToScreenEdge :: Configuration -> World -> Point2 -> (Point2, Point2) -> [Point2] extendConeToScreenEdge :: Configuration -> World -> Point2 -> (Point2, Point2) -> [Point2]
extendConeToScreenEdge cfig w c (x, y) = orderPolygon $ wallScreenIntersect ++ [x, y] ++ borderPs ++ cornerPs extendConeToScreenEdge cfig w c (x, y) = orderPolygon $ wallScreenIntersect ++ [x, y] ++ borderPs ++ cornerPs
where where
borderPs = mapMaybe (intersectLinefromScreen cfig w c) [x, y] borderPs = mapMaybe (intersectLinefromScreen cfig w c) [x, y]
scpoly = reverse $ screenPolygon cfig (w ^. cWorld . lWorld . camPos) scpoly = reverse $ screenPolygon cfig (w ^. cWorld . camPos)
cornerPs = filter (pointIsInCone c (x, y)) scpoly cornerPs = filter (pointIsInCone c (x, y)) scpoly
wallScreenIntersect = wallScreenIntersect =
mapMaybe (uncurry $ intersectSegSeg y ((2 *.* y) -.- x)) mapMaybe (uncurry $ intersectSegSeg y ((2 *.* y) -.- x))
@@ -77,4 +77,4 @@ intersectLinefromScreen cfig w a b =
listToMaybe listToMaybe
. mapMaybe (\(x, y) -> intersectSegLineFrom x y b (b +.+ b -.- a)) . mapMaybe (\(x, y) -> intersectSegLineFrom x y b (b +.+ b -.- a))
. loopPairs . loopPairs
$ screenPolygon cfig (w ^. cWorld . lWorld . camPos) $ screenPolygon cfig (w ^. cWorld . camPos)
-28
View File
@@ -1,28 +0,0 @@
module Dodge.Default.Input where
import qualified Data.Map.Strict as M
import qualified Data.Set as S
import Dodge.Data.Hammer
import Dodge.Data.Input
import Geometry.Data
defaultInput :: Input
defaultInput =
Input
{ _clickMousePos = V2 0 0
, _keys = mempty
, _mouseButtons = mempty
, _mousePos = V2 0 0
, _scrollAmount = 0
, _previousScrollAmount = 0
, _hammers = defaultWorldHammers
, _lrLine = (0, 0)
, _lLine = (0, 0)
, _rLine = (0, 0)
, _lSelect = 0
, _rSelect = 0
, _backspaceTimer = 0
}
defaultWorldHammers :: M.Map WorldHammer HammerPosition
defaultWorldHammers = M.fromSet (const HammerUp) $ S.fromList [minBound .. maxBound]
+5 -4
View File
@@ -12,6 +12,7 @@ import System.Random
defaultInput :: Input defaultInput :: Input
defaultInput = Input defaultInput = Input
{ _clickMousePos = V2 0 0 { _clickMousePos = V2 0 0
, _textInput = RejectTextInput
, _keys = S.empty , _keys = S.empty
, _mouseButtons = mempty , _mouseButtons = mempty
, _mousePos = V2 0 0 , _mousePos = V2 0 0
@@ -65,9 +66,10 @@ defaultCWCam =
defaultCWorld :: CWorld defaultCWorld :: CWorld
defaultCWorld = defaultCWorld =
CWorld CWorld
{ _lWorld = defaultLWorld { _camPos = defaultCWCam
, _lWorld = defaultLWorld
, _cwGen = defaultCWGen , _cwGen = defaultCWGen
, _cwClock = 0 , _cClock = 0
, _pastWorlds = [] , _pastWorlds = []
, _timeFlow = NormalTimeFlow , _timeFlow = NormalTimeFlow
} }
@@ -75,8 +77,7 @@ defaultCWorld =
defaultLWorld :: LWorld defaultLWorld :: LWorld
defaultLWorld = defaultLWorld =
LWorld LWorld
{ _camPos = defaultCWCam { _magnets = IM.empty
, _magnets = IM.empty
, _modifications = IM.empty , _modifications = IM.empty
, _creatures = IM.empty , _creatures = IM.empty
, _crZoning = mempty --Zoning IM.empty crZoneSize zoneOfCreature , _crZoning = mempty --Zoning IM.empty crZoneSize zoneOfCreature
+1 -1
View File
@@ -23,7 +23,7 @@ import SDL
handleEvent :: Event -> Universe -> IO (Maybe Universe) handleEvent :: Event -> Universe -> IO (Maybe Universe)
handleEvent e = case eventPayload e of handleEvent e = case eventPayload e of
TextInputEvent tev -> return . Just . handleTextInput (textInputEventText tev) TextInputEvent tev -> return . Just . (handleTextInput (textInputEventText tev))
KeyboardEvent kev -> handleKeyboardEvent kev KeyboardEvent kev -> handleKeyboardEvent kev
MouseMotionEvent mmev -> return . handleMouseMotionEvent mmev MouseMotionEvent mmev -> return . handleMouseMotionEvent mmev
MouseButtonEvent mbev -> return . Just . over uvWorld (handleMouseButtonEvent mbev) MouseButtonEvent mbev -> return . Just . over uvWorld (handleMouseButtonEvent mbev)
+2 -8
View File
@@ -5,10 +5,6 @@ module Dodge.Event.Keyboard (
guardDisconnectedID, guardDisconnectedID,
) where ) where
--import Color
--import Data.List
import Data.Maybe import Data.Maybe
import qualified Data.Set as S import qualified Data.Set as S
--import Data.Text (unpack) --import Data.Text (unpack)
@@ -35,8 +31,8 @@ import SDL
-- also, note that this currently "doubles" the inputs to both terminals if both -- also, note that this currently "doubles" the inputs to both terminals if both
-- are open -- are open
handleTextInput :: T.Text -> Universe -> Universe handleTextInput :: T.Text -> Universe -> Universe
handleTextInput text u = --handleTextInput text = input . textInput . textInputText %~ T.append (T.toUpper text)
u handleTextInput text u = u
& uvScreenLayers . ix 0 . scInput %~ updateText & uvScreenLayers . ix 0 . scInput %~ updateText
& updateTerminalText & updateTerminalText
where where
@@ -152,8 +148,6 @@ spaceAction w = case w ^?! cWorld . lWorld . hud . hudElement of
--theLoc = doWorldPos (fst (_seenLocations (_cWorld w) IM.! _selLocation (_cWorld w))) w --theLoc = doWorldPos (fst (_seenLocations (_cWorld w) IM.! _selLocation (_cWorld w))) w
theLoc = doWorldPos (w ^?! cWorld . lWorld . seenLocations . ix (w ^. cWorld . lWorld . selLocation) . _1) w theLoc = doWorldPos (w ^?! cWorld . lWorld . seenLocations . ix (w ^. cWorld . lWorld . selLocation) . _1) w
-- updateTopCloseObject i w' = w' & closeObjects %~ ( Right (_buttons w' IM.! i) : ) . tail
pauseGame :: Universe -> Universe pauseGame :: Universe -> Universe
pauseGame = uvScreenLayers .~ [pauseMenu] pauseGame = uvScreenLayers .~ [pauseMenu]
+1 -1
View File
@@ -348,7 +348,7 @@ useMod hm = case hm of
directedTelPos it cr w = (p, a) directedTelPos it cr w = (p, a)
where where
p = fromMaybe (_crPos cr) $ it ^? itTargeting . tgPos . _Just p = fromMaybe (_crPos cr) $ it ^? itTargeting . tgPos . _Just
a = argV (mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) -.- p) a = argV (mouseWorldPos (w ^. input) (w ^. cWorld . camPos) -.- p)
moddelay x = itUse . heldConsumption . laAmmoType . amBullet . buDelayFraction .~ x moddelay x = itUse . heldConsumption . laAmmoType . amBullet . buDelayFraction .~ x
modcrpos x cr = modcrpos x cr =
cr & crDir %~ tweenAngles x (_crOldDir cr) cr & crDir %~ tweenAngles x (_crOldDir cr)
+1 -1
View File
@@ -16,7 +16,7 @@ splashScreen =
initialWorld :: World initialWorld :: World
initialWorld = initialWorld =
defaultWorld defaultWorld
& cWorld . lWorld . camPos . camZoom .~ 10 & cWorld . camPos . camZoom .~ 10
& cWorld . lWorld . creatures .~ IM.fromList [(0, startCr)] & cWorld . lWorld . creatures .~ IM.fromList [(0, startCr)]
& cWorld . lWorld . worldEvents .~ SoundStart BackgroundSound (V2 0 0) foamSprayFadeOutS Nothing : & cWorld . lWorld . worldEvents .~ SoundStart BackgroundSound (V2 0 0) foamSprayFadeOutS Nothing :
[MakeStartCloudAt (V3 x y 5) | x <- [-5, -4 .. 5], y <- [-5, -4 .. 5]] [MakeStartCloudAt (V3 x y 5) | x <- [-5, -4 .. 5], y <- [-5, -4 .. 5]]
+2 -2
View File
@@ -148,7 +148,7 @@ circleLaser it cr w
| otherwise = w | otherwise = w
where where
cpos = _crPos cr cpos = _crPos cr
mwp = mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
pos = _crPos cr +.+ rotateV dir (V2 0 (max 70 $ dist cpos mwp)) pos = _crPos cr +.+ rotateV dir (V2 0 (max 70 $ dist cpos mwp))
dir = fromIntegral (_lasCycle (_itParams it)) * pi / 1000 dir = fromIntegral (_lasCycle (_itParams it)) * pi / 1000
phasev = _phaseV . _itParams $ _crInv cr IM.! crSel cr phasev = _phaseV . _itParams $ _crInv cr IM.! crSel cr
@@ -167,7 +167,7 @@ shootDualLaser it cr w =
gap = _dbGap . _itParams $ it gap = _dbGap . _itParams $ it
posl = pos +.+ (- gap) *.* vNormal (unitVectorAtAngle dir) posl = pos +.+ (- gap) *.* vNormal (unitVectorAtAngle dir)
posr = pos +.+ gap *.* vNormal (unitVectorAtAngle dir) posr = pos +.+ gap *.* vNormal (unitVectorAtAngle dir)
mwp = mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
mwp' mwp'
| dist mwp (_crPos cr) < aimlength + 5 = _crPos cr +.+ (aimlength + 5) *.* unitVectorAtAngle dir | dist mwp (_crPos cr) < aimlength + 5 = _crPos cr +.+ (aimlength + 5) *.* unitVectorAtAngle dir
| otherwise = mwp | otherwise = mwp
+4 -4
View File
@@ -83,7 +83,7 @@ targetRBCreatureUp it cr w t
. filter (canseepos . _crPos) . filter (canseepos . _crPos)
$ crsNearCirc mwp 40 w $ crsNearCirc mwp 40 w
canseepos p = hasLOS (_crPos cr) p w canseepos p = hasLOS (_crPos cr) p w
mwp = mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
updatePos t' = t' & tgPos .~ posFromMaybeID (_tgID t') updatePos t' = t' & tgPos .~ posFromMaybeID (_tgID t')
posFromMaybeID Nothing = Nothing posFromMaybeID Nothing = Nothing
posFromMaybeID (Just i) = w ^? cWorld . lWorld . creatures . ix i . crPos posFromMaybeID (Just i) = w ^? cWorld . lWorld . creatures . ix i . crPos
@@ -107,7 +107,7 @@ targetCursorUpdate :: World -> Targeting -> Targeting
targetCursorUpdate w t targetCursorUpdate w t
| SDL.ButtonRight `M.member` _mouseButtons (_input w) = | SDL.ButtonRight `M.member` _mouseButtons (_input w) =
t t
& tgPos . _Just .~ mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) & tgPos . _Just .~ mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
& tgActive .~ True & tgActive .~ True
| otherwise = | otherwise =
t & tgPos %~ const Nothing t & tgPos %~ const Nothing
@@ -117,7 +117,7 @@ targetRBPressUpdate :: World -> Targeting -> Targeting
targetRBPressUpdate w t targetRBPressUpdate w t
| SDL.ButtonRight `M.member` _mouseButtons (_input w) = | SDL.ButtonRight `M.member` _mouseButtons (_input w) =
t t
& tgPos %~ maybe (Just $ mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos)) Just & tgPos %~ maybe (Just $ mouseWorldPos (w ^. input) (w ^. cWorld . camPos)) Just
& tgActive .~ True & tgActive .~ True
| otherwise = | otherwise =
t & tgPos %~ const Nothing t & tgPos %~ const Nothing
@@ -139,7 +139,7 @@ targetLaserUpdate _ cr w t
where where
(mp, _) = reflectLaserAlong 0.2 sp ep w (mp, _) = reflectLaserAlong 0.2 sp ep w
sp = _crPos cr +.+ 15 *.* unitVectorAtAngle (_crDir cr) sp = _crPos cr +.+ 15 *.* unitVectorAtAngle (_crDir cr)
ep = sp +.+ 5000 *.* normalizeV (mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) -.- sp) ep = sp +.+ 5000 *.* normalizeV (mouseWorldPos (w ^. input) (w ^. cWorld . camPos) -.- sp)
addLaserPic = addLaserPic =
cWorld . lWorld . lasers cWorld . lWorld . lasers
.:~ LaserStart .:~ LaserStart
+6 -6
View File
@@ -579,7 +579,7 @@ torqueBefore torque feff item cr w
w w
& randGen .~ g & randGen .~ g
& cWorld . lWorld . creatures . ix cid . crDir +~ rot & cWorld . lWorld . creatures . ix cid . crDir +~ rot
& cWorld . lWorld . camPos . camRot +~ rot & cWorld . camPos . camRot +~ rot
| otherwise = feff item cr $ set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) w | otherwise = feff item cr $ set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) w
where where
cid = _crID cr cid = _crID cr
@@ -600,7 +600,7 @@ torqueBeforeAtLeast minTorque exTorque feff item cr w
w w
& randGen .~ g & randGen .~ g
& cWorld . lWorld . creatures . ix cid . crDir +~ rot' & cWorld . lWorld . creatures . ix cid . crDir +~ rot'
& cWorld . lWorld . camPos . camRot +~ rot' & cWorld . camPos . camRot +~ rot'
| otherwise = feff item cr $ set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot') w | otherwise = feff item cr $ set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot') w
where where
cid = _crID cr cid = _crID cr
@@ -613,7 +613,7 @@ torqueBeforeAtLeast minTorque exTorque feff item cr w
withTorqueAfter :: ChainEffect withTorqueAfter :: ChainEffect
withTorqueAfter feff item cr w withTorqueAfter feff item cr w
-- | cid == 0 = rotateScope $ set randGen g $ over cameraRot (+rot) $ feff item cr w -- | cid == 0 = rotateScope $ set randGen g $ over cameraRot (+rot) $ feff item cr w
| cid == 0 = set randGen g $ over (cWorld . lWorld . camPos . camRot) (+ rot) $ feff item cr w | cid == 0 = set randGen g $ over (cWorld . camPos . camRot) (+ rot) $ feff item cr w
| otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) $ feff item cr w | otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) $ feff item cr w
where where
cid = _crID cr cid = _crID cr
@@ -651,7 +651,7 @@ sideEffectOnFrame i sf f it cr w =
torqueSideEffect :: Float -> Item -> Creature -> World -> World torqueSideEffect :: Float -> Item -> Creature -> World -> World
torqueSideEffect torque _ cr w torqueSideEffect torque _ cr w
| cid == 0 = set randGen g $ over (cWorld . lWorld . camPos . camRot) (+ rot) w | cid == 0 = set randGen g $ over (cWorld . camPos . camRot) (+ rot) w
| otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) w | otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) w
where where
cid = _crID cr cid = _crID cr
@@ -698,12 +698,12 @@ duplicateOffsetsFocus xs eff item cr w = foldr f w poss
& crPos %~ (+.+ pos) & crPos %~ (+.+ pos)
& crDir .~ thedir pos & crDir .~ thedir pos
thedir pos thedir pos
| dist (mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos)) (_crPos cr) < aimingMuzzlePos cr item = | dist (mouseWorldPos (w ^. input) (w ^. cWorld . camPos)) (_crPos cr) < aimingMuzzlePos cr item =
argV argV
( _crPos cr +.+ aimingMuzzlePos cr item *.* unitVectorAtAngle (_crDir cr) ( _crPos cr +.+ aimingMuzzlePos cr item *.* unitVectorAtAngle (_crDir cr)
-.- (_crPos cr +.+ pos) -.- (_crPos cr +.+ pos)
) )
| otherwise = argV (mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) -.- (_crPos cr +.+ pos)) | otherwise = argV (mouseWorldPos (w ^. input) (w ^. cWorld . camPos) -.- (_crPos cr +.+ pos))
duplicateItem :: (Item -> [Item]) -> ChainEffect duplicateItem :: (Item -> [Item]) -> ChainEffect
duplicateItem fit eff itm cr w = foldr f w (fit itm) duplicateItem fit eff itm cr w = foldr f w (fit itm)
+1 -1
View File
@@ -84,7 +84,7 @@ unsafeBlinkGun =
useForceFieldGun :: Item -> Creature -> World -> World useForceFieldGun :: Item -> Creature -> World -> World
useForceFieldGun itm cr w = fromMaybe w $ do useForceFieldGun itm cr w = fromMaybe w $ do
a <- _tgPos $ _itTargeting itm a <- _tgPos $ _itTargeting itm
let mwp = mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) let mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
b = if dist a mwp < 100 then mwp else a +.+ 100 *.* normalizeV (mwp -.- a) b = if dist a mwp < 100 then mwp else a +.+ 100 *.* normalizeV (mwp -.- a)
wlline = (a, b) wlline = (a, b)
return $ return $
+1 -1
View File
@@ -58,7 +58,7 @@ fromEdgeTuple :: (Int,Int,PathEdge) -> PathEdgeNodes
fromEdgeTuple (a,b,pe) = PathEdgeNodes a b pe fromEdgeTuple (a,b,pe) = PathEdgeNodes a b pe
randomCompass :: World -> World randomCompass :: World -> World
randomCompass w = w & cWorld . lWorld . camPos . camRot .~ (takeOne [0, 0.5 * pi, pi, 1.5 * pi] & evalState $ _randGen w) randomCompass w = w & cWorld . camPos . camRot .~ (takeOne [0, 0.5 * pi, pi, 1.5 * pi] & evalState $ _randGen w)
putFloorTiles :: GenWorld -> GenWorld putFloorTiles :: GenWorld -> GenWorld
putFloorTiles gw = gw & gwWorld . cWorld . lWorld . floorTiles .~ floorsFromGenWorld gw putFloorTiles gw = gw & gwWorld . cWorld . lWorld . floorTiles .~ floorsFromGenWorld gw
+1 -1
View File
@@ -98,7 +98,7 @@ boostPoint x cr w = case mayp2 of
where where
cpos = _crPos cr cpos = _crPos cr
r = 1.5 * _crRad cr r = 1.5 * _crRad cr
p1 = cpos +.+ x *.* squashNormalizeV (mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) -.- cpos) p1 = cpos +.+ x *.* squashNormalizeV (mouseWorldPos (w ^. input) (w ^. cWorld . camPos) -.- cpos)
mayp2 = bouncePoint (const True) 1 cpos p1 w mayp2 = bouncePoint (const True) 1 cpos p1 w
addBoostShockwave :: addBoostShockwave ::
+2 -2
View File
@@ -5,7 +5,7 @@ module Dodge.Picture.SizeInvariant
import Control.Lens import Control.Lens
import Data.Maybe import Data.Maybe
import Dodge.Base.Window import Dodge.Base.Window
import Dodge.Data.LWorld import Dodge.Data.CWorld
import Dodge.Data.Config import Dodge.Data.Config
import Geometry import Geometry
import Picture import Picture
@@ -62,7 +62,7 @@ fixedSizePicClampArrow ::
Picture -> Picture ->
Point2 -> Point2 ->
Configuration -> Configuration ->
LWorld -> CWorld ->
Picture Picture
fixedSizePicClampArrow xbord ybord pic p cfig w = fixedSizePicClampArrow xbord ybord pic p cfig w =
pictures pictures
+1 -1
View File
@@ -97,7 +97,7 @@ setRemoteDir cid itid pj w = w & cWorld . lWorld . projectiles . ix (_prjID pj)
| SDL.ButtonRight `M.member` _mouseButtons (_input w) | SDL.ButtonRight `M.member` _mouseButtons (_input w)
&& w ^? cWorld . lWorld . creatures . ix cid . crInvSel . iselPos && w ^? cWorld . lWorld . creatures . ix cid . crInvSel . iselPos
== w ^? cWorld . lWorld . itemLocations . ix itid . ipInvID == w ^? cWorld . lWorld . itemLocations . ix itid . ipInvID
= (w ^. cWorld . lWorld . camPos . camRot) + argV (_mousePos (_input w)) = (w ^. cWorld . camPos . camRot) + argV (_mousePos (_input w))
| otherwise = _prjDir pj | otherwise = _prjDir pj
doThrust :: Proj -> World -> World doThrust :: Proj -> World -> World
+4 -4
View File
@@ -32,14 +32,14 @@ doDrawing pdata u = do
sTicks <- SDL.ticks sTicks <- SDL.ticks
let w = _uvWorld u let w = _uvWorld u
cfig = _uvConfig u cfig = _uvConfig u
rot = w ^. cWorld . lWorld . camPos . camRot rot = w ^. cWorld . camPos . camRot
camzoom = w ^. cWorld . lWorld . camPos . camZoom camzoom = w ^. cWorld . camPos . camZoom
trans = w ^. cWorld . lWorld . camPos . camCenter trans = w ^. cWorld . camPos . camCenter
wins@(V2 winx winy) = V2 (_windowX cfig) (_windowY cfig) wins@(V2 winx winy) = V2 (_windowX cfig) (_windowY cfig)
resFact = resFactorNum $ cfig ^. graphics_resolution_factor resFact = resFactorNum $ cfig ^. graphics_resolution_factor
(wallPointsCol, windowPoints, wallSPics) = wallsToDraw w (wallPointsCol, windowPoints, wallSPics) = wallsToDraw w
lightPoints = lightsToRender cfig w lightPoints = lightsToRender cfig w
viewFroms@(V2 vfx vfy) = w ^. cWorld . lWorld . camPos . camViewFrom viewFroms@(V2 vfx vfy) = w ^. cWorld . camPos . camViewFrom
viewFrom3d = Vector3 vfx vfy 20 viewFrom3d = Vector3 vfx vfy 20
shadV = _pictureShaders pdata shadV = _pictureShaders pdata
lwShad = _lightingWallShadShader pdata lwShad = _lightingWallShadShader pdata
+2 -2
View File
@@ -15,8 +15,8 @@ lightsToRender cfig w =
where where
getLS = getlsparam . _lsParam getLS = getlsparam . _lsParam
getTLS = getlsparam . _tlsParam getTLS = getlsparam . _tlsParam
cbox = w ^. cWorld . lWorld . camPos . camBoundBox cbox = w ^. cWorld . camPos . camBoundBox
cpos = w ^. cWorld . lWorld . camPos . camCenter cpos = w ^. cWorld . camPos . camCenter
getlsparam ls getlsparam ls
| not (pointInPolygon lpos cbox) && extraculltest = Nothing | not (pointInPolygon lpos cbox) && extraculltest = Nothing
| otherwise = Just (_lsPos ls, rad ^ (2 :: Int), _lsCol ls) | otherwise = Just (_lsPos ls, rad ^ (2 :: Int), _lsCol ls)
+17 -17
View File
@@ -116,8 +116,8 @@ shiftDraw' fpos fdir fdraw x =
cullPoint :: Configuration -> World -> Point2 -> Bool cullPoint :: Configuration -> World -> Point2 -> Bool
cullPoint cfig w p cullPoint cfig w p
| debugOn Close_shape_culling cfig = pointInPolygon p (w ^. cWorld . lWorld . camPos . camBoundBox) | debugOn Close_shape_culling cfig = pointInPolygon p (w ^. cWorld . camPos . camBoundBox)
| otherwise = dist (w ^. cWorld . lWorld . camPos . camCenter) p < (w ^. cWorld . lWorld . camPos . camViewDistance) | otherwise = dist (w ^. cWorld . camPos . camCenter) p < (w ^. cWorld . camPos . camViewDistance)
extraPics :: Configuration -> World -> Picture extraPics :: Configuration -> World -> Picture
extraPics cfig w = extraPics cfig w =
@@ -176,7 +176,7 @@ debugDraw' cfig w bl = case bl of
Inspect_wall -> drawInspectWalls w Inspect_wall -> drawInspectWalls w
Cr_awareness -> drawCreatureDisplayTexts w Cr_awareness -> drawCreatureDisplayTexts w
Show_sound -> pictures $ M.map (soundPic cfig w) $ _playingSounds w Show_sound -> pictures $ M.map (soundPic cfig w) $ _playingSounds w
Cr_status -> drawCrInfo cfig (w ^. cWorld . lWorld) Cr_status -> drawCrInfo cfig (w ^. cWorld)
Mouse_position -> drawMousePosition cfig w Mouse_position -> drawMousePosition cfig w
Walls_info -> drawWlIDs cfig w Walls_info -> drawWlIDs cfig w
Pathing -> drawPathing cfig w Pathing -> drawPathing cfig w
@@ -195,7 +195,7 @@ drawCollisionTest cfig w =
<> foldMap (drawLabCrossCol cfig cam blue) (xIntercepts crZoneSize a b) <> foldMap (drawLabCrossCol cfig cam blue) (xIntercepts crZoneSize a b)
where where
(a, b) = _lrLine (_input w) (a, b) = _lrLine (_input w)
cam = w ^. cWorld . lWorld . camPos cam = w ^. cWorld . camPos
drawCreatureDisplayTexts :: World -> Picture drawCreatureDisplayTexts :: World -> Picture
drawCreatureDisplayTexts w = foldMap (creatureDisplayText w) (w ^. cWorld . lWorld . creatures) drawCreatureDisplayTexts w = foldMap (creatureDisplayText w) (w ^. cWorld . lWorld . creatures)
@@ -279,7 +279,7 @@ drawFarWallDetect w =
$ getViewpoints p (_cWorld w) $ getViewpoints p (_cWorld w)
-- $ runIdentity $ S.toList_ $ streamViewpoints p w -- $ runIdentity $ S.toList_ $ streamViewpoints p w
where where
p = w ^. cWorld . lWorld . camPos . camViewFrom p = w ^. cWorld . camPos . camViewFrom
drawDDATest :: World -> Picture drawDDATest :: World -> Picture
drawDDATest w = drawDDATest w =
@@ -290,8 +290,8 @@ drawDDATest w =
-- <> color blue (runIdentity (S.foldMap_ drawCross qs')) -- <> color blue (runIdentity (S.foldMap_ drawCross qs'))
<> setLayer DebugLayer (color yellow (line [cvf, mwp])) <> setLayer DebugLayer (color yellow (line [cvf, mwp]))
where where
cvf = w ^. cWorld . lWorld . camPos . camViewFrom cvf = w ^. cWorld . camPos . camViewFrom
mwp = mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
--ps = ddaStreamX 50 cvf mwp --ps = ddaStreamX 50 cvf mwp
ps = zoneOfSeg 50 cvf mwp ps = zoneOfSeg 50 cvf mwp
@@ -317,7 +317,7 @@ drawWallSearchRays w = foldMap (f . fst) $ allVisibleWalls w
setLayer DebugLayer $ setLayer DebugLayer $
color yellow $ color yellow $
uncurryV translate p (circle 5) uncurryV translate p (circle 5)
<> line [w ^. cWorld . lWorld . camPos . camViewFrom , p] <> line [w ^. cWorld . camPos . camViewFrom , p]
testPic :: Configuration -> World -> Picture testPic :: Configuration -> World -> Picture
testPic _ _ = mempty testPic _ _ = mempty
@@ -333,7 +333,7 @@ testPic _ _ = mempty
drawBoundingBox :: World -> Picture drawBoundingBox :: World -> Picture
drawBoundingBox w = setLayer DebugLayer $ color green $ line $ (x : xs) ++ [x] drawBoundingBox w = setLayer DebugLayer $ color green $ line $ (x : xs) ++ [x]
where where
(x : xs) = w ^. cWorld . lWorld . camPos . camBoundBox (x : xs) = w ^. cWorld . camPos . camBoundBox
clDraw :: Cloud -> Picture clDraw :: Cloud -> Picture
clDraw c = translate3 (_clPos c) (drawCloud (_clPict c) c) clDraw c = translate3 (_clPos c) (drawCloud (_clPict c) c)
@@ -357,11 +357,11 @@ mcSPic mc =
rotateSP (_mcDir mc) (drawMachine mc) rotateSP (_mcDir mc) (drawMachine mc)
soundPic :: Configuration -> World -> Sound -> Picture soundPic :: Configuration -> World -> Sound -> Picture
soundPic cfig w s = fixedSizePicClampArrow 50 50 thePic p cfig (w ^. cWorld . lWorld) soundPic cfig w s = fixedSizePicClampArrow 50 50 thePic p cfig (w ^. cWorld)
where where
p = _soundPos s p = _soundPos s
thePic = thePic =
rotate (w ^. cWorld . lWorld . camPos . camRot) rotate (w ^. cWorld . camPos . camRot)
. scale theScale theScale . scale theScale theScale
. centerText . centerText
. soundToOnomato . soundToOnomato
@@ -377,8 +377,8 @@ drawMousePosition cfig w =
. text . text
$ shortPoint2 mwp $ shortPoint2 mwp
where where
p = worldPosToScreen (w ^. cWorld . lWorld . camPos) mwp p = worldPosToScreen (w ^. cWorld . camPos) mwp
mwp = mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
drawWlIDs :: Configuration -> World -> Picture drawWlIDs :: Configuration -> World -> Picture
drawWlIDs cfig w = setLayer FixedCoordLayer $ foldMap f (w ^. cWorld . lWorld . walls) drawWlIDs cfig w = setLayer FixedCoordLayer $ foldMap f (w ^. cWorld . lWorld . walls)
@@ -392,7 +392,7 @@ drawWlIDs cfig w = setLayer FixedCoordLayer $ foldMap f (w ^. cWorld . lWorld .
. text . text
$ show $ _wlID wl $ show $ _wlID wl
where where
p = worldPosToScreen (w ^. cWorld . lWorld . camPos) $ 0.5 *.* uncurry (+.+) (_wlLine wl) p = worldPosToScreen (w ^. cWorld . camPos) $ 0.5 *.* uncurry (+.+) (_wlLine wl)
edgeToPic :: [Point2] -> PathEdge -> Picture edgeToPic :: [Point2] -> PathEdge -> Picture
edgeToPic poly pe edgeToPic poly pe
@@ -405,7 +405,7 @@ edgeToPic poly pe
drawPathing :: Configuration -> World -> Picture drawPathing :: Configuration -> World -> Picture
drawPathing cfig w = drawPathing cfig w =
setLayer DebugLayer $ setLayer DebugLayer $
foldMap (edgeToPic (screenPolygon cfig (w ^. cWorld . lWorld . camPos)) . (^?! _3)) (FGL.labEdges gr) foldMap (edgeToPic (screenPolygon cfig (w ^. cWorld . camPos)) . (^?! _3)) (FGL.labEdges gr)
<> foldMap dispInc (graphToIncidence gr) <> foldMap dispInc (graphToIncidence gr)
where where
dispInc (p, n) = setDepth 2 . uncurryV translate p . scale 0.1 0.1 $ text $ show n dispInc (p, n) = setDepth 2 . uncurryV translate p . scale 0.1 0.1 $ text $ show n
@@ -436,11 +436,11 @@ crDisplayInfo cfig cam cr
fpreShow :: (Show a, Functor f) => String -> f a -> f String fpreShow :: (Show a, Functor f) => String -> f a -> f String
fpreShow str = fmap (((rightPad 7 '.' str ++ "...") ++) . show) fpreShow str = fmap (((rightPad 7 '.' str ++ "...") ++) . show)
drawCrInfo :: Configuration -> LWorld -> Picture drawCrInfo :: Configuration -> CWorld -> Picture
drawCrInfo cfig w = drawCrInfo cfig w =
setLayer FixedCoordLayer $ setLayer FixedCoordLayer $
renderInfoListsAt (2 * hw - 400) 0 cfig cam $ renderInfoListsAt (2 * hw - 400) 0 cfig cam $
mapMaybe (crDisplayInfo cfig cam) $ IM.elems $ w ^. creatures mapMaybe (crDisplayInfo cfig cam) $ IM.elems $ w ^. lWorld . creatures
where where
cam = w ^. camPos cam = w ^. camPos
hw = halfWidth cfig hw = halfWidth cfig
+1 -1
View File
@@ -26,7 +26,7 @@ wallsToDraw w =
<*> L.premap getWallSPic L.mconcat <*> L.premap getWallSPic L.mconcat
) )
(wlsFromIXs w $ zonesExtract (w ^. cWorld . lWorld . wlZoning) $ zoneOfSight wlZoneSize cam) (wlsFromIXs w $ zonesExtract (w ^. cWorld . lWorld . wlZoning) $ zoneOfSight wlZoneSize cam)
cam = w ^. cWorld . lWorld . camPos cam = w ^. cWorld . camPos
--wallsToDraw --wallsToDraw
-- :: World -- :: World
+2 -2
View File
@@ -212,9 +212,9 @@ soundAngle p w
. radToDeg . radToDeg
. normalizeAngle . normalizeAngle
. (+ pi) . (+ pi)
$ argV (vNormal (p -.- earPos)) - (w ^. cWorld . lWorld . camPos . camRot) $ argV (vNormal (p -.- earPos)) - (w ^. cWorld . camPos . camRot)
where where
earPos = w ^. cWorld . lWorld . camPos . camViewFrom earPos = w ^. cWorld . camPos . camViewFrom
{- | Uses the first free origin from a list. {- | Uses the first free origin from a list.
Does nothing if all origins are already creating sounds. Does nothing if all origins are already creating sounds.
+3 -3
View File
@@ -23,7 +23,7 @@ targetDistanceDraw :: Item -> Creature -> Configuration -> World -> Picture
targetDistanceDraw itm _ cfig w = fromMaybe mempty $ do targetDistanceDraw itm _ cfig w = fromMaybe mempty $ do
p <- itm ^? itTargeting . tgPos . _Just p <- itm ^? itTargeting . tgPos . _Just
let p1 = worldPosToScreen cam p let p1 = worldPosToScreen cam p
mwp = mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
p2 = worldPosToScreen cam mwp p2 = worldPosToScreen cam mwp
thecol = if dist p mwp > 100 then red else white thecol = if dist p mwp > 100 then red else white
return $ return $
@@ -33,7 +33,7 @@ targetDistanceDraw itm _ cfig w = fromMaybe mempty $ do
line [p1, p2] line [p1, p2]
<> transMidLine p1 p2 (scale 0.1 0.1 . text . shortShow $ dist p mwp) <> transMidLine p1 p2 (scale 0.1 0.1 . text . shortShow $ dist p mwp)
where where
cam = w ^. cWorld . lWorld . camPos cam = w ^. cWorld . camPos
targetDraw :: (Item -> Picture) -> Item -> Creature -> Configuration -> World -> Picture targetDraw :: (Item -> Picture) -> Item -> Creature -> Configuration -> World -> Picture
targetDraw f it _ cfig w = fromMaybe mempty $ do targetDraw f it _ cfig w = fromMaybe mempty $ do
@@ -45,7 +45,7 @@ targetDraw f it _ cfig w = fromMaybe mempty $ do
uncurryV translate (worldPosToScreen cam p) $ uncurryV translate (worldPosToScreen cam p) $
f it f it
where where
cam = w ^. cWorld . lWorld . camPos cam = w ^. cWorld . camPos
activeTargetCursorPic :: Picture activeTargetCursorPic :: Picture
activeTargetCursorPic = activeTargetCursorPic =
+9 -8
View File
@@ -64,14 +64,19 @@ import Sound.Data
import StrictHelp import StrictHelp
updateUniverse :: Universe -> Universe updateUniverse :: Universe -> Universe
updateUniverse = updateUniverseLast . updateUniverseFirst updateUniverse u = updateUniverseLast . updateUniverseMid
. over uvWorld (updateCamera cfig)
. over (uvWorld . cWorld . cClock) ( + 1)
$ updateBounds u -- where should this go? next to update camera?
where
cfig = u ^. uvConfig
updateUniverseLast :: Universe -> Universe updateUniverseLast :: Universe -> Universe
updateUniverseLast = over uvWorld (input . mouseButtons . each .~ True) -- to determine if the mouse button is held updateUniverseLast = over uvWorld (input . mouseButtons . each .~ True) -- to determine if the mouse button is held
{- For most menus the only way to change the world is using event handling. -} {- For most menus the only way to change the world is using event handling. -}
updateUniverseFirst :: Universe -> Universe updateUniverseMid :: Universe -> Universe
updateUniverseFirst u updateUniverseMid u
| concurrentblocking = u | concurrentblocking = u
| otherwise = case _uvScreenLayers u of | otherwise = case _uvScreenLayers u of
(OptionScreen{_scOptionFlag = GameOverOptions} : _) -> (OptionScreen{_scOptionFlag = GameOverOptions} : _) ->
@@ -156,7 +161,6 @@ functionalUpdate w =
. over uvWorld updateDistortions . over uvWorld updateDistortions
. over uvWorld updateCreatureSoundPositions . over uvWorld updateCreatureSoundPositions
. over uvWorld ppEvents . over uvWorld ppEvents
. over uvWorld (updateCamera cfig)
. colCrsWalls . colCrsWalls
. over uvWorld simpleCrSprings . over uvWorld simpleCrSprings
. over uvWorld zoneCreatures . over uvWorld zoneCreatures
@@ -197,12 +201,9 @@ functionalUpdate w =
. over uvWorld updateSeenWalls . over uvWorld updateSeenWalls
. over uvWorld updateTerminal . over uvWorld updateTerminal
. over uvWorld updateRBList . over uvWorld updateRBList
. updateBounds -- where should this go? next to update camera?
. over uvWorld updateCloseObjects . over uvWorld updateCloseObjects
. over uvWorld updateWheelEvents . over uvWorld updateWheelEvents
$ over uvWorld updatePastWorlds w $ over uvWorld updatePastWorlds w
where
cfig = _uvConfig w
updateWheelEvents :: World -> World updateWheelEvents :: World -> World
updateWheelEvents w = foldr ($) w (replicate (abs y) (updateWheelEvent (signum y))) updateWheelEvents w = foldr ($) w (replicate (abs y) (updateWheelEvent (signum y)))
@@ -249,7 +250,7 @@ zoneClouds w =
foldl' (flip zoneCloud) zn (w ^. cWorld . lWorld . clouds) foldl' (flip zoneCloud) zn (w ^. cWorld . lWorld . clouds)
updateWorldSelect' :: World -> World updateWorldSelect' :: World -> World
updateWorldSelect' w = over input (updateWorldSelect (w ^. cWorld . lWorld . camPos)) w updateWorldSelect' w = over input (updateWorldSelect (w ^. cWorld . camPos)) w
updateWorldSelect :: CamPos -> Input -> Input updateWorldSelect :: CamPos -> Input -> Input
updateWorldSelect cam inp = f . g $ case (inp ^? mouseButtons . ix ButtonLeft, inp ^? mouseButtons . ix ButtonRight) of updateWorldSelect cam inp = f . g $ case (inp ^? mouseButtons . ix ButtonLeft, inp ^? mouseButtons . ix ButtonRight) of
+19 -19
View File
@@ -32,7 +32,7 @@ update where your avatar's view is from. -}
updateCamera :: Configuration -> World -> World updateCamera :: Configuration -> World -> World
updateCamera cfig w = updateCamera cfig w =
w w
& over (cWorld . lWorld . camPos) (setViewDistance cfig) & over (cWorld . camPos) (setViewDistance cfig)
& moveZoomCamera cfig & moveZoomCamera cfig
& updateScopeZoom & updateScopeZoom
& rotateCamera cfig & rotateCamera cfig
@@ -40,11 +40,11 @@ updateCamera cfig w =
moveZoomCamera :: Configuration -> World -> World moveZoomCamera :: Configuration -> World -> World
moveZoomCamera cfig w = moveZoomCamera cfig w =
w w
& cWorld . lWorld . camPos . camCenter .~ newcen & cWorld . camPos . camCenter .~ newcen
& cWorld . lWorld . camPos . camViewFrom .~ newvf & cWorld . camPos . camViewFrom .~ newvf
& cWorld . lWorld . camPos . camZoom .~ newzoom & cWorld . camPos . camZoom .~ newzoom
& cWorld . lWorld . camPos . camDefaultZoom .~ newDefaultZoom & cWorld . camPos . camDefaultZoom .~ newDefaultZoom
& cWorld . lWorld . camPos . camItemZoom .~ newItemZoom & cWorld . camPos . camItemZoom .~ newItemZoom
where where
--cfig = _uvConfig uv --cfig = _uvConfig uv
--w = _uvWorld uv --w = _uvWorld uv
@@ -59,23 +59,23 @@ moveZoomCamera cfig w =
guard (SDL.ButtonRight `M.member` _mouseButtons (_input w)) guard (SDL.ButtonRight `M.member` _mouseButtons (_input w))
yourItem w ^? _Just . itScope . scopePos yourItem w ^? _Just . itScope . scopePos
newcen = cpos +.+ fromMaybe (V2 0 0) mscopeoffset +.+ offset newcen = cpos +.+ fromMaybe (V2 0 0) mscopeoffset +.+ offset
offset = rotateV (w ^. cWorld . lWorld . camPos . camRot) $ ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos (_input w) offset = rotateV (w ^. cWorld . camPos . camRot) $ ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos (_input w)
newzoom = case yourItem w ^? _Just . itScope of newzoom = case yourItem w ^? _Just . itScope of
Just zs@ZoomScope{} -> _scopeZoom zs Just zs@ZoomScope{} -> _scopeZoom zs
_ -> newDefaultZoom * newItemZoom _ -> newDefaultZoom * newItemZoom
idealDefaultZoom = clipZoom wallZoom idealDefaultZoom = clipZoom wallZoom
newDefaultZoom = case yourItem w ^? _Just . itScope of newDefaultZoom = case yourItem w ^? _Just . itScope of
Just zs@ZoomScope{} -> _scopeZoom zs Just zs@ZoomScope{} -> _scopeZoom zs
_ -> changeZoom (w ^. cWorld . lWorld . camPos . camDefaultZoom) idealDefaultZoom _ -> changeZoom (w ^. cWorld . camPos . camDefaultZoom) idealDefaultZoom
idealItemZoom = fromMaybe 1 $ do idealItemZoom = fromMaybe 1 $ do
guard $ crIsAiming (you w) guard $ crIsAiming (you w)
zoomFromItem' <$> (yourItem w ^? _Just . itUse . heldAim . aimZoom) zoomFromItem' <$> (yourItem w ^? _Just . itUse . heldAim . aimZoom)
newItemZoom = changeZoom (w ^. cWorld . lWorld . camPos . camItemZoom) idealItemZoom newItemZoom = changeZoom (w ^. cWorld . camPos . camItemZoom) idealItemZoom
changeZoom curZoom idealZoom changeZoom curZoom idealZoom
| curZoom > idealZoom + 0.01 = ((zoomOutSpeed -1) * curZoom + idealZoom) / zoomOutSpeed | curZoom > idealZoom + 0.01 = ((zoomOutSpeed -1) * curZoom + idealZoom) / zoomOutSpeed
| curZoom < idealZoom - 0.01 = ((zoomInSpeed -1) * curZoom + idealZoom) / zoomInSpeed | curZoom < idealZoom - 0.01 = ((zoomInSpeed -1) * curZoom + idealZoom) / zoomInSpeed
| otherwise = idealZoom | otherwise = idealZoom
wallZoom = min4 (w ^. cWorld . lWorld . camPos . camBoundDist) wallZoom = min4 (w ^. cWorld . camPos . camBoundDist)
min4 (a, b, c, d) = minimum [hh / maxd a, hh / maxd (- b), hw / maxd c, hw / maxd (- d)] min4 (a, b, c, d) = minimum [hh / maxd a, hh / maxd (- b), hw / maxd c, hw / maxd (- d)]
maxd = max distFromEqmnt maxd = max distFromEqmnt
distFromEqmnt = foldl' max 1 $ IM.mapMaybe (_eeViewDist . _equipEffect . _itUse) $ getCrEquipment $ you w distFromEqmnt = foldl' max 1 $ IM.mapMaybe (_eeViewDist . _equipEffect . _itUse) $ getCrEquipment $ you w
@@ -129,7 +129,7 @@ zoomInLongGun w
ycr = you w ycr = you w
Just currentZoom = wp ^? itScope . scopeZoom Just currentZoom = wp ^? itScope . scopeZoom
newzoom = (wp ^?! itScope . scopeZoom) / zoomSpeed newzoom = (wp ^?! itScope . scopeZoom) / zoomSpeed
mousep = rotateV (w ^. cWorld . lWorld . camPos . camRot) $ _mousePos (_input w) mousep = rotateV (w ^. cWorld . camPos . camRot) $ _mousePos (_input w)
zoomOutLongGun :: World -> World zoomOutLongGun :: World -> World
zoomOutLongGun w zoomOutLongGun w
@@ -166,22 +166,22 @@ rotateToOverlappingWall w =
p = _crPos (you w) p = _crPos (you w)
doWallRotate :: Wall -> World -> World doWallRotate :: Wall -> World -> World
doWallRotate wl' w = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl') - (w ^. cWorld . lWorld . camPos . camRot) doWallRotate wl' w = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl') - (w ^. cWorld . camPos . camRot)
where where
rotateUsing a rotateUsing a
| b - b' > 0.01 = w & cWorld . lWorld . camPos . camRot +~ 0.01 | b - b' > 0.01 = w & cWorld . camPos . camRot +~ 0.01
| b - b' < negate 0.01 = w & cWorld . lWorld . camPos . camRot -~ 0.01 | b - b' < negate 0.01 = w & cWorld . camPos . camRot -~ 0.01
| otherwise = w | otherwise = w
where where
--b = a * (2 / pi) --b = a * (2 / pi)
b = a * (4 / pi) b = a * (4 / pi)
b' = fromIntegral (round b :: Int) b' = fromIntegral (round b :: Int)
rotateCameraBy :: Float -> LWorld -> LWorld rotateCameraBy :: Float -> CWorld -> CWorld
rotateCameraBy x w = rotateCameraBy x w =
w w
& camPos . camRot +~ x & camPos . camRot +~ x
& creatures . ix 0 . crInv . ix (crSel (w ^?! creatures . ix 0)) & lWorld . creatures . ix 0 . crInv . ix (crSel (w ^?! lWorld . creatures . ix 0))
. itScope . itScope
. scopePos . scopePos
%~ rotateV x %~ rotateV x
@@ -189,8 +189,8 @@ rotateCameraBy x w =
rotateCamera :: Configuration -> World -> World rotateCamera :: Configuration -> World -> World
rotateCamera cfig w rotateCamera cfig w
| keyl && keyr = w | keyl && keyr = w
| keyl = over (cWorld . lWorld) (rotateCameraBy 0.025) w | keyl = over cWorld (rotateCameraBy 0.025) w
| keyr = over (cWorld . lWorld) (rotateCameraBy (-0.025)) w | keyr = over cWorld (rotateCameraBy (-0.025)) w
| otherwise = ifConfigWallRotate cfig w | otherwise = ifConfigWallRotate cfig w
where where
keyl = SDL.ScancodeQ `Set.member` _keys (_input w) && notAtTerminal w keyl = SDL.ScancodeQ `Set.member` _keys (_input w) && notAtTerminal w
@@ -239,7 +239,7 @@ farWallDistDirection p w =
boundPoints $ boundPoints $
map f $ getViewpoints p (_cWorld w) map f $ getViewpoints p (_cWorld w)
where where
f q = (rotateV (negate (w ^. cWorld . lWorld . camPos . camRot)) . (-.- p)) (foldl' findPoint q (wls q)) f q = (rotateV (negate (w ^. cWorld . camPos . camRot)) . (-.- p)) (foldl' findPoint q (wls q))
wls q = filter wlIsOpaque $ wlsNearSeg p q w wls q = filter wlIsOpaque $ wlsNearSeg p q w
findPoint q = fromMaybe q . uncurry (intersectSegSeg p q) . _wlLine findPoint q = fromMaybe q . uncurry (intersectSegSeg p q) . _wlLine
+1 -1
View File
@@ -31,7 +31,7 @@ updateWheelEvent yi w = case w ^. cWorld . lWorld . hud . hudElement of
(_, EquipOptions{}) -> scrollRBOption y w (_, EquipOptions{}) -> scrollRBOption y w
(Nothing, _) -> closeObjScrollDir y w (Nothing, _) -> closeObjScrollDir y w
(Just f, _) -> doHeldScroll f y (you w) w (Just f, _) -> doHeldScroll f y (you w) w
| lbDown -> w & cWorld . lWorld . camPos . camZoom +~ y | lbDown -> w & cWorld . camPos . camZoom +~ y
| invKeyDown -> changeSwapInvSel yi w | invKeyDown -> changeSwapInvSel yi w
| otherwise -> stopSoundFrom (CrReloadSound 0) $ changeAugInvSel yi w | otherwise -> stopSoundFrom (CrReloadSound 0) $ changeAugInvSel yi w
DisplayInventory (TweakInventory mi) DisplayInventory (TweakInventory mi)
+1 -1
View File
@@ -60,7 +60,7 @@ pressedMBEffectsNoInventory pkeys w
w & input . hammers . ix DoubleMouseHam .~ HammerDown w & input . hammers . ix DoubleMouseHam .~ HammerDown
| isDown ButtonRight && inTopInv = w | isDown ButtonRight && inTopInv = w
| isDown ButtonMiddle = | isDown ButtonMiddle =
w & cWorld . lWorld . camPos . camRot -~ rotation w & cWorld . camPos . camRot -~ rotation
& input . clickMousePos .~ _mousePos (_input w) & input . clickMousePos .~ _mousePos (_input w)
| isDown ButtonLeft = w & input . hammers . ix DoubleMouseHam .~ HammerDown | isDown ButtonLeft = w & input . hammers . ix DoubleMouseHam .~ HammerDown
| otherwise = w | otherwise = w
+1 -1
View File
@@ -58,7 +58,7 @@ accessTerminal mtmid w = case mtmid of
torqueCr :: Float -> Int -> World -> World torqueCr :: Float -> Int -> World -> World
torqueCr x cid w torqueCr x cid w
| cid == 0 = set randGen g $ over (cWorld . lWorld . camPos . camRot) (+ rot) w | cid == 0 = set randGen g $ over (cWorld . camPos . camRot) (+ rot) w
| otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) w | otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) w
where where
(rot, g) = randomR (- x, x) $ _randGen w (rot, g) = randomR (- x, x) $ _randGen w
+1 -1
View File
@@ -72,4 +72,4 @@ makeFlamerSmokeAt p w = makeCloudAt (CloudColor 4 300 (greyN x)) 6 200 40 p w
spawnSmokeAtCursor :: World -> World spawnSmokeAtCursor :: World -> World
spawnSmokeAtCursor w = shellTrailCloud (V3 x y 20) w spawnSmokeAtCursor w = shellTrailCloud (V3 x y 20) w
where where
V2 x y = mouseWorldPos (w ^. input) (w ^. cWorld . lWorld . camPos) V2 x y = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)