Add concept of GameRoom, check viewing distance based on rooms

This commit is contained in:
2021-09-02 23:24:29 +01:00
parent 9d2f42dbc9
commit c69af7a5f4
30 changed files with 295 additions and 151 deletions
+8 -8
View File
@@ -34,12 +34,12 @@ incCharMode
:: Int -- ^ Inventory selection
-> World
-> World
incCharMode i = creatures . ix 0 . crInv . ix i . itAttachment . _Just %~ incCharMode'
incCharMode i = creatures . ix 0 . crInv . ix i . itAttachment %~ incCharMode'
decCharMode
:: Int -- ^ Inventory selection
-> World
-> World
decCharMode i = creatures . ix 0 . crInv . ix i . itAttachment . _Just %~ decCharMode'
decCharMode i = creatures . ix 0 . crInv . ix i . itAttachment %~ decCharMode'
charFiringStrat
:: [(Char, Creature -> World -> World)] -- ^ Different firing effects for different characters
@@ -47,7 +47,7 @@ charFiringStrat
-> World
-> World
charFiringStrat strats cr w = case w ^? creatures . ix cid . crInv
. ix (_crInvSel $ _creatures w IM.! cid) . itAttachment . _Just . itCharMode of
. ix (_crInvSel $ _creatures w IM.! cid) . itAttachment . itCharMode of
Just (c :<| _) -> fromJust (Prelude.lookup c strats) cr w
_ -> w
where
@@ -60,7 +60,7 @@ charFiringStratI
-> World
-> World
charFiringStratI strats eff item cr w = case w ^? creatures . ix cid . crInv
. ix (_crInvSel $ _creatures w IM.! cid) . itAttachment . _Just . itCharMode of
. ix (_crInvSel $ _creatures w IM.! cid) . itAttachment . itCharMode of
Just (c :<| _) -> fromJust (Prelude.lookup c strats) eff item cr w
_ -> w
where
@@ -75,8 +75,8 @@ increaseFuse fuse itid w = w
& creatures . ix 0 . crInv . ix itid %~
( itScrollUp .~ decreaseFuse newTime )
. (itScrollDown .~ increaseFuse newTime )
. ( itAttachment ?~ ItFuse newTime )
. ( itZoom .~ defaultItZoom{_itAimZoomMax = zm, _itAimZoomMin = zm} )
. ( itAttachment .~ ItFuse newTime )
. ( itAimZoom .~ defaultItZoom{_itZoomMax = zm, _itZoomMin = zm} )
where
newTime = min (fuse + 5) 90
zm = 50 / fromIntegral newTime
@@ -89,8 +89,8 @@ decreaseFuse fuse itid w = w
& creatures . ix 0 . crInv . ix itid %~
( itScrollUp .~ decreaseFuse newTime )
. ( itScrollDown .~ increaseFuse newTime )
. ( itAttachment ?~ ItFuse newTime )
. ( itZoom .~ defaultItZoom {_itAimZoomMax = zm, _itAimZoomMin = zm} )
. ( itAttachment .~ ItFuse newTime )
. ( itAimZoom .~ defaultItZoom {_itZoomMax = zm, _itZoomMin = zm} )
where
newTime = max (fuse - 5) 20
zm = 50 / fromIntegral newTime
+3 -2
View File
@@ -9,15 +9,16 @@ import qualified Data.Sequence as Seq
data ItAttachment
= ItScope
{_scopePos :: Point2
{_scopePos :: Point2 -- ^ a camera offset
,_scopeZoomChange :: Int
,_scopeZoom :: Float
,_scopeIsCamera :: Bool
,_scopeIsCamera :: Bool -- ^ if the camera offset is also the center of vision
}
| ItFuse {_itFuseTime :: Int}
| ItMode {_itMode :: Int}
| ItCharMode {_itCharMode :: Seq.Seq Char }
| ItTargetPos { _itTargetPos :: Point2 }
| ItInt { _itInt :: Int }
| NoItAttachment
makeLenses ''ItAttachment
+36 -27
View File
@@ -24,10 +24,11 @@ import Dodge.Item.Weapon.Laser
import Dodge.Item.Weapon.Shell
import Dodge.Item.Weapon.Bullet
import Dodge.Item.Weapon.AmmoParams
import Dodge.Item.Attachment.Data
import Dodge.Default.Weapon
import Dodge.Item.Weapon.Booster
import Dodge.Item.Weapon.Grenade
import Dodge.Item.Attachment.Data
--import Dodge.Item.Attachment.Data
import Dodge.Item.Attachment
import Geometry
import Geometry.Vector3D
@@ -80,7 +81,7 @@ pistol = defaultGun
, _itAimingRange = 0
, _itZoom = defaultItZoom
, _itEquipPict = pictureWeaponOnAim pistolPic
, _itAttachment = Nothing
, _itAttachment = NoItAttachment
, _itID = Nothing
, _itEffect = wpRecock
, _itInvDisplay = basicWeaponDisplay
@@ -187,7 +188,7 @@ lasGun = defaultAutoGun
, _itAimingSpeed = 0.4
, _itAimingRange = 1
, _itEquipPict = pictureWeaponOnAim lasGunPic
, _itAttachment = Just $ ItCharMode $ Seq.fromList "/VZ"
, _itAttachment = ItCharMode $ Seq.fromList "/VZ"
, _itScroll = scrollCharMode
, _itInvDisplay = basicWeaponDisplay
}
@@ -253,7 +254,7 @@ tractorGun = defaultAutoGun
removeItAttachment :: Int -> Int -> World -> World
removeItAttachment i _ w = w & creatures . ix i . crInv . ix itRef . itAttachment .~ Nothing
removeItAttachment i _ w = w & creatures . ix i . crInv . ix itRef . itAttachment .~ NoItAttachment
where
cr = _creatures w IM.! i
itRef = _crInvSel cr
@@ -278,7 +279,7 @@ remoteLauncher = defaultGun
, _itAimingSpeed = 0.2
, _itAimingRange = 0.5
, _itEquipPict = pictureWeaponOnAim $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5)
, _itAttachment = Just $ ItScope (V2 0 0) 0 1 True
, _itAttachment = ItScope (V2 0 0) 0 1 True
}
hvAutoGun :: Item
hvAutoGun = defaultAutoGun
@@ -470,7 +471,8 @@ multGun = defaultGun
, _itFloorPict = onLayer FlItLayer multGunPic
, _itAimingSpeed = 0.4
, _itAimingRange = 1
, _itZoom = defaultItZoom {_itAimZoomFac = 1.5}
, _itZoom = defaultItZoom
, _itAimZoom = defaultItZoom {_itZoomFac = 1.5}
, _itEquipPict = pictureWeaponOnAim multGunPic
, _itAimStance = TwoHandTwist
, _wpAmmo = basicBullet
@@ -514,10 +516,11 @@ longGun = defaultGun
, _itFloorPict = onLayer FlItLayer longGunPic
, _itAimingSpeed = 0.2
, _itAimingRange = 1
, _itZoom = defaultItZoom {_itAimZoomMax = 0.5, _itAimZoomMin = 0.5}
, _itZoom = defaultItZoom
, _itAimZoom = defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5}
, _itEquipPict = pictureWeaponOnAim longGunPic
, _itScroll = zoomLongGun
, _itAttachment = Just $ ItScope (V2 0 0) 0 1 False
, _itAttachment = ItScope (V2 0 0) 0 1 False
, _itEffect = itemLaserScopeEffect
, _wpAmmo = hvBullet
, _itAimStance = TwoHandTwist
@@ -533,10 +536,10 @@ zoomLongGun x cr
startZoomInLongGun :: Int -> World -> World
startZoomInLongGun _ w = w & creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
. itAttachment . _Just . scopeZoomChange %~ \x -> max 5 (x + 5)
. itAttachment . scopeZoomChange %~ \x -> max 5 (x + 5)
startZoomOutLongGun :: Int -> World -> World
startZoomOutLongGun _ w = w & creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
. itAttachment . _Just . scopeZoomChange %~ \x -> min (-5) (x-5)
. itAttachment . scopeZoomChange %~ \x -> min (-5) (x-5)
poisonSprayer :: Item
poisonSprayer = defaultAutoGun
{ _itName = "POISON"
@@ -586,9 +589,10 @@ flamer = defaultAutoGun
, _itFloorPict = onLayer FlItLayer flamerPic
, _itAimingSpeed = 0.5
, _itAimingRange = 0
, _itZoom = defaultItZoom {_itAimZoomMax = 5, _itAimZoomMin = 1.5}
, _itZoom = defaultItZoom
, _itAimZoom = defaultItZoom {_itZoomMax = 5, _itZoomMin = 1.5}
, _itEquipPict = pictureWeaponOnAim flamerPic
, _itAttachment = Nothing
, _itAttachment = NoItAttachment
}
flamerPic :: Picture
flamerPic = color yellow $ pictures
@@ -709,7 +713,7 @@ pointToItem (OnFloor flid) = floorItems . ix flid . flIt
retireRemoteRocket :: Int -> Int -> Int -> World -> World
retireRemoteRocket itid 0 pjid w =
set (pointToItem (_itemPositions w IM.! itid) . itAttachment . _Just . scopePos) (V2 0 0)
set (pointToItem (_itemPositions w IM.! itid) . itAttachment . scopePos) (V2 0 0)
$ set (pointToItem (_itemPositions w IM.! itid) . itUse) (const fireRemoteLauncher)
(w & projectiles %~ IM.delete pjid)
retireRemoteRocket itid t pjid w = setScope w
@@ -718,13 +722,13 @@ retireRemoteRocket itid t pjid w = setScope w
setScope w' = case _itemPositions w' IM.! itid of
InInv cid invid -> w'
& creatures . ix cid . crInv . ix invid . itAttachment
. _Just . scopePos .~ (pos -.- _crPos (_creatures w' IM.! cid))
. scopePos .~ (pos -.- _crPos (_creatures w' IM.! cid))
_ -> w'
pos = fromMaybe (V2 0 0) $ w ^? projectiles . ix pjid . pjPos
retireRemoteBomb :: Int -> Int -> Int -> World -> World
retireRemoteBomb itid 0 pjid w = w
& pointToItem (_itemPositions w IM.! itid) %~
( (itAttachment . _Just . scopePos .~ V2 0 0)
( (itAttachment . scopePos .~ V2 0 0)
. (itZoom .~ defaultItZoom)
. (itUse .~ const throwRemoteBomb)
)
@@ -735,7 +739,7 @@ retireRemoteBomb itid t pjid w = setScope w
setScope w' = case _itemPositions w' IM.! itid of
InInv cid invid -> w'
& creatures . ix cid . crInv . ix invid . itAttachment
. _Just . scopePos .~ (pos -.- _crPos (_creatures w' IM.! cid))
. scopePos .~ (pos -.- _crPos (_creatures w' IM.! cid))
_ -> w'
pos = fromMaybe (V2 0 0) $ w ^? projectiles . ix pjid . pjPos
@@ -782,16 +786,16 @@ setRemoteScope :: Int -> Projectile -> World -> World
setRemoteScope itid pj w' = case w' ^? itemPositions . ix itid of
Just (InInv cid' invid )
-> w' & creatures . ix cid' . crInv . ix invid . itAttachment
. _Just . scopePos .~ (_pjPos pj -.- _crPos (_creatures w' IM.! cid'))
. scopePos .~ (_pjPos pj -.- _crPos (_creatures w' IM.! cid'))
_ -> w'
setRemoteBombScope :: Int -> Projectile -> World -> World
setRemoteBombScope itid pj w' = case _itemPositions w' IM.! itid of
InInv cid invid
-> w' & creatures . ix cid . crInv . ix invid . itAttachment
. _Just . scopePos .~ (_pjPos pj -.- _crPos (_creatures w' IM.! cid))
& creatures . ix cid . crInv . ix invid . itZoom
.~ (defaultItZoom {_itAimZoomMax = 0.5, _itAimZoomMin = 0.5})
. scopePos .~ (_pjPos pj -.- _crPos (_creatures w' IM.! cid))
& creatures . ix cid . crInv . ix invid . itAimZoom
.~ (defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5})
_ -> w'
grenade :: Item
@@ -809,12 +813,13 @@ grenade = Throwable
]
, _itAimingSpeed = 1
, _itAimingRange = 0
, _itZoom = defaultItZoom {_itAimZoomMax = f fuseTime, _itAimZoomMin = f fuseTime}
, _itZoom = defaultItZoom
, _itAimZoom = defaultItZoom {_itZoomMax = f fuseTime, _itZoomMin = f fuseTime}
, _itEquipPict = pictureWeaponOnAim $ grenadePic fuseTime
, _itID = Nothing
, _itUseRate = 25
, _itUseTime = 0
, _itAttachment = Just $ ItFuse fuseTime
, _itAttachment = ItFuse fuseTime
, _itInvColor = white
, _itInvDisplay = basicWeaponDisplay
, _itEffect = wpRecock
@@ -860,7 +865,7 @@ remoteBomb = defaultThrowable
, _itUseModifiers =
[ hammerCheckI
]
, _itAttachment = Just $ ItScope (V2 0 0) 0 1 True
, _itAttachment = ItScope (V2 0 0) 0 1 True
, _itEquipPict = pictureWeaponOnAim remoteBombUnarmedPic
}
@@ -1062,7 +1067,8 @@ radar = defaultGun
, _itAmount = 1
, _itMaxStack = 1
, _itAimingRange = 1
, _itZoom = defaultItZoom {_itAimZoomMax = 1, _itZoomMax = 1}
, _itZoom = defaultItZoom { _itZoomMax = 1}
, _itAimZoom = defaultItZoom { _itZoomMax = 1}
, _itEquipPict = pictureWeaponOnAim $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
}
{- |
@@ -1087,7 +1093,8 @@ sonar = defaultGun
, _itAmount = 1
, _itMaxStack = 1
, _itAimingRange = 1
, _itZoom = defaultItZoom {_itAimZoomMax = 1, _itZoomMax = 1}
, _itZoom = defaultItZoom {_itZoomMax = 1}
, _itAimZoom = defaultItZoom {_itZoomMax = 1}
, _itEquipPict = pictureWeaponOnAim $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
}
{- |
@@ -1104,7 +1111,8 @@ autoSonar = defaultEquipment
, _itID = Nothing
, _itAimingSpeed = 1
, _itAimingRange = 0
, _itZoom = defaultItZoom {_itAimZoomMax = 1, _itZoomMax = 1}
, _itZoom = defaultItZoom {_itZoomMax = 1}
, _itAimZoom = defaultItZoom {_itZoomMax = 1}
}
{- |
Automatically sends out pulses that display walls. -}
@@ -1120,7 +1128,8 @@ autoRadar = defaultEquipment
, _itID = Nothing
, _itAimingSpeed = 1
, _itAimingRange = 0
, _itZoom = defaultItZoom {_itAimZoomMax = 1, _itZoomMax = 1}
, _itZoom = defaultItZoom {_itZoomMax = 1}
, _itAimZoom = defaultItZoom {_itZoomMax = 1}
}
{- |
Creates a creature next to the creature using the item. -}
+3 -2
View File
@@ -48,10 +48,11 @@ autoGun = defaultAutoGun
, _itFloorPict = onLayer FlItLayer autoGunPic
, _itAimingSpeed = 0.4
, _itAimingRange = 1
, _itZoom = defaultItZoom {_itAimZoomFac = 1.5}
, _itZoom = defaultItZoom
, _itAimZoom = defaultItZoom {_itZoomFac = 1.5}
, _itEquipPict = pictureWeaponOnAim autoGunPic
, _itEffect = wpRecock
, _itAttachment = Just $ ItCharMode $ Seq.fromList "MS"
, _itAttachment = ItCharMode $ Seq.fromList "MS"
, _itScroll = scrollCharMode
, _itInvDisplay = basicWeaponDisplay
, _wpAmmo = basicBullet
+2 -1
View File
@@ -8,6 +8,7 @@ import Dodge.Item.Draw
import Dodge.Item.Weapon.Targeting
import Dodge.Item.Weapon.TriggerType
import Dodge.Item.Weapon.ExtraEffect
import Dodge.Item.Attachment.Data
import Dodge.Default
import Dodge.Particle.Bullet.Spawn
import Dodge.Particle.Bullet.HitEffect
@@ -35,7 +36,7 @@ bezierGun = defaultGun
]
, _itFloorPict = onLayer FlItLayer bezierGunPic
, _itEquipPict = pictureWeaponOnAim bezierGunPic
, _itAttachment = Nothing
, _itAttachment = NoItAttachment
, _itScroll = removeItTarget 0
, _itHammer = HammerUp
, _itEffect = rbSetTarget
+3 -3
View File
@@ -41,14 +41,14 @@ boostSelfL x cr invid w = case boostPoint x cr w of
cpos = _crPos cr
r = _crRad cr
pid = fromMaybe (IM.newKey $ _projectiles w)
(cr ^? crInv . ix invid . itAttachment . _Just . itInt)
(cr ^? crInv . ix invid . itAttachment . itInt)
crEff p ammoEff = addBoostShockwave pid p (r *.* normalizeV (p -.- cpos)) w
& creatures . ix cid %~
(crPos .~ p)
. (crInv . ix invid %~
ammoEff
. (itEffect . itEffectCounter .~ 1)
. (itAttachment ?~ ItInt pid)
. (itAttachment .~ ItInt pid)
)
boostSelf
@@ -120,7 +120,7 @@ resetAttachmentID :: ItEffect
resetAttachmentID = ItInvEffect f 0
where
f iteff cr invid w
| _itEffectCounter iteff < 0 = w & pointToIt . itAttachment .~ Nothing
| _itEffectCounter iteff < 0 = w & pointToIt . itAttachment .~ NoItAttachment
| otherwise = w & pointToIt . itEffect . itEffectCounter -~ 1
where
pointToIt = creatures . ix (_crID cr) . crInv . ix invid
+2 -2
View File
@@ -9,7 +9,7 @@ import Dodge.Base
import Dodge.Item.Data
import Dodge.Item.Weapon.Decoration
import Dodge.Item.Weapon.UseEffect
--import Dodge.Item.Attachment.Data
import Dodge.Item.Attachment.Data
import Dodge.WorldEvent.Flash
import Dodge.WorldEvent.ThingsHit
import Dodge.Picture.Layer
@@ -49,7 +49,7 @@ bezierRecock = ItInvEffect
f _ cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust fOnIt i
fOnIt it = case _itHammer it of
HammerDown -> it & itHammer .~ HammerUp
_ -> it & itAttachment .~ Nothing
_ -> it & itAttachment .~ NoItAttachment
{- |
Creates a laser scope and recocks the weapon.
-}
+1 -2
View File
@@ -15,7 +15,6 @@ import Picture
import Geometry
import Control.Lens
import Data.Maybe (fromJust)
import qualified Data.IntMap.Strict as IM
--import System.Random
@@ -90,7 +89,7 @@ throwGrenade explosion cr w = setWp $ removePict $ over projectiles addG w
dir = argV v
setWp :: World -> World
setWp w' = w' & creatures . ix n . crInv . ix j . itEffect .~ throwArmReset 20
fuseTime = _itFuseTime $ fromJust $ _itAttachment $ _crInv cr IM.! j
fuseTime = _itFuseTime $ _itAttachment $ _crInv cr IM.! j
throwArmReset :: Int -> ItEffect
throwArmReset x = ItInvEffect {_itInvEffect = f ,_itEffectCounter = x }
+1 -1
View File
@@ -13,7 +13,7 @@ import Control.Lens
--import Control.Monad
{- | Displays the item name, ammo if loaded, and any selected '_itCharMode'. -}
basicWeaponDisplay :: Item -> String
basicWeaponDisplay it = case it ^? itAttachment . _Just of
basicWeaponDisplay it = case it ^? itAttachment of
Just ItCharMode {_itCharMode = (c :<| _)} -> midPadL 10 ' ' (_itName it) (' ' : aIfLoaded) ++ [' ',c]
Just ItMode {_itMode = i} -> midPadL 10 ' ' (_itName it) (' ' : aIfLoaded) ++ show i
_ -> midPadL 10 ' ' (_itName it) (' ' : aIfLoaded)
+1 -1
View File
@@ -31,7 +31,7 @@ aLaser cr w = over particles (makeLaserAt phaseV pos dir : )
pos = _crPos cr +.+ ((_crRad cr +3) *.* unitVectorAtAngle dir)
dir = _crDir cr
phaseV = charToPhaseV
$ fromMaybe '/' $ Seq.lookup 0 =<< cr ^? crInv . ix j . itAttachment . _Just . itCharMode
$ fromMaybe '/' $ Seq.lookup 0 =<< cr ^? crInv . ix j . itAttachment . itCharMode
j = _crInvSel cr
charToPhaseV :: Fractional p => Char -> p
+3 -3
View File
@@ -272,12 +272,12 @@ withTempLight time rad col eff item cr = eff item cr
. over tempLightSources (theTLS :)
where
theTLS = defaultTLS
{ _tlsPos = V3 x y 20
{ _tlsPos = V3 x y 10
, _tlsRad=rad
, _tlsIntensity = col
, _tlsTime = time
}
V2 x y = _crPos cr +.+ 5 *.* unitVectorAtAngle (_crDir cr)
V2 x y = _crPos cr +.+ 15 *.* unitVectorAtAngle (_crDir cr)
withMuzFlareI :: ChainEffect
withMuzFlareI f it cr w = tempLightForAt 3 pos2 -- . muzzleFlashAt pos2
@@ -346,7 +346,7 @@ torqueAfterI torque feff item cr w
cid = _crID cr
(rot, g) = randomR (-torque,torque) $ _randGen w
rotateScope = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
. itAttachment . _Just . scopePos %~ rotateV rot
. itAttachment . scopePos %~ rotateV rot
spreadNumI :: ChainEffect
spreadNumI eff item cr w = foldr f w dirs
where