Refactor projectiles

This commit is contained in:
2022-07-20 09:55:07 +01:00
parent 9daf872878
commit 330a81a955
14 changed files with 196 additions and 200 deletions
+2 -2
View File
@@ -14,7 +14,7 @@ import Dodge.Prop.Gib
--import Dodge.Item.Weapon.Grenade --import Dodge.Item.Weapon.Grenade
import Dodge.Item.Equipment.Booster import Dodge.Item.Equipment.Booster
import Dodge.Item.Weapon.Utility import Dodge.Item.Weapon.Utility
import Dodge.Item.Weapon.Drone --import Dodge.Item.Weapon.Drone
import Dodge.Item.Craftable import Dodge.Item.Craftable
import Dodge.Creature.LauncherCrit import Dodge.Creature.LauncherCrit
import Dodge.Creature.PistolCrit import Dodge.Creature.PistolCrit
@@ -277,7 +277,7 @@ stackedInventory = IM.fromList $ zip [0..]
,flameThrower ,flameThrower
,poisonSprayer ,poisonSprayer
,launcher ,launcher
,droneLauncher -- ,droneLauncher
--,lasGun --,lasGun
--,grenade --,grenade
--,ltAutoGun,flamer,multGun,spreadGun,remoteLauncher --,ltAutoGun,flamer,multGun,spreadGun,remoteLauncher
+35 -32
View File
@@ -159,6 +159,7 @@ data World = World
, _gusts :: IM.IntMap Gust , _gusts :: IM.IntMap Gust
, _gsZoning :: Zoning IM.IntMap Gust , _gsZoning :: Zoning IM.IntMap Gust
, _props :: IM.IntMap Prop , _props :: IM.IntMap Prop
, _projectiles :: IM.IntMap Proj
, _instantBullets :: [Bullet] , _instantBullets :: [Bullet]
, _bullets :: [Bullet] , _bullets :: [Bullet]
, _instantParticles :: [Particle] , _instantParticles :: [Particle]
@@ -718,16 +719,40 @@ data Modification
, _mdExternalID2 :: Int , _mdExternalID2 :: Int
, _mdUpdate :: Modification -> World -> World , _mdUpdate :: Modification -> World -> World
} }
data Prop data Proj
= Projectile = RemoteShell
{ _prPos :: Point2 { _prjPos :: Point2
, _pjStartPos :: Point2 , _prjStartPos :: Point2
, _pjVel :: Point2 , _prjVel :: Point2
, _prDraw :: Prop -> SPic , _prjDraw :: ProjectileDraw
, _pjID :: Int , _prjID :: Int
, _pjUpdate :: Prop -> World -> World , _prjUpdate :: Proj -> World -> World
, _prjPayload :: Payload
} }
| PropZ | Shell
{ _prjPos :: Point2
, _prjStartPos :: Point2
, _prjVel :: Point2
, _prjAcc :: Point2
, _prjDir :: Float
, _prjSpin :: Float
, _prjDraw :: ProjectileDraw
, _prjID :: Int
, _prjUpdate :: Proj -> World -> World
, _prjPayload :: Payload
, _prjTimer :: Int
, _prjZ :: Float
}
data Prop
-- = Projectile
-- { _prPos :: Point2
-- , _pjStartPos :: Point2
-- , _pjVel :: Point2
-- , _prDraw :: Prop -> SPic
-- , _pjID :: Int
-- , _pjUpdate :: Prop -> World -> World
-- }
= PropZ
{ _prPos :: Point2 { _prPos :: Point2
, _pjStartPos :: Point2 , _pjStartPos :: Point2
, _pjVel :: Point2 , _pjVel :: Point2
@@ -773,29 +798,6 @@ data Prop
, _prDraw :: Prop -> SPic , _prDraw :: Prop -> SPic
, _prToggle :: Bool , _prToggle :: Bool
} }
| RemoteShell
{ _prPos :: Point2
, _pjStartPos :: Point2
, _pjVel :: Point2
, _prDraw :: Prop -> SPic
, _pjID :: Int
, _pjUpdate :: Prop -> World -> World
, _pjPayload :: Point2 -> World -> World
}
| Shell
{ _prPos :: Point2
, _pjStartPos :: Point2
, _pjVel :: Point2
, _pjAcc :: Point2
, _pjDir :: Float
, _pjSpin :: Float
, _prDraw :: Prop -> SPic
, _pjID :: Int
, _pjUpdate :: Prop -> World -> World
, _pjPayload :: Point2 -> World -> World
, _pjTimer :: Int
, _pjZ :: Float
}
| Bomb | Bomb
{ _prPos :: Point2 { _prPos :: Point2
, _pjVel :: Point2 , _pjVel :: Point2
@@ -1307,6 +1309,7 @@ makeLenses ''ItemConsumption
makeLenses ''AmmoType makeLenses ''AmmoType
makeLenses ''TweakParam makeLenses ''TweakParam
makeLenses ''Prop makeLenses ''Prop
makeLenses ''Proj
makeLenses ''Modification makeLenses ''Modification
makeLenses ''Particle makeLenses ''Particle
makeLenses ''PressPlate makeLenses ''PressPlate
+2 -1
View File
@@ -2,6 +2,7 @@
--{-# LANGUAGE StrictData #-} --{-# LANGUAGE StrictData #-}
module Dodge.Data.Ammo where module Dodge.Data.Ammo where
data ProjectileDraw = DrawShell | DrawRemoteShell data ProjectileDraw = DrawShell | DrawRemoteShell | DrawDrone | DrawBlankProjectile
data ProjectileCreate = CreateShell data ProjectileCreate = CreateShell
data ProjectileUpdate = LaunchPJ | SpinPJ | ThrustPJ | FloatPJ
+3 -3
View File
@@ -2,13 +2,13 @@ module Dodge.Default.Prop where
import Dodge.Data import Dodge.Data
import Geometry import Geometry
defaultProp :: Prop defaultProp :: Prop
defaultProp = Projectile defaultProp = ShapeProp
{ _prPos = V2 0 0 { _prPos = V2 0 0
, _pjStartPos = V2 0 0
, _pjVel = V2 0 0
, _prDraw = const mempty , _prDraw = const mempty
, _pjID = 0 , _pjID = 0
, _pjUpdate = const id , _pjUpdate = const id
, _prToggle = True
, _pjRot = 0
} }
defaultShapeProp :: Prop defaultShapeProp :: Prop
defaultShapeProp = ShapeProp defaultShapeProp = ShapeProp
+13 -14
View File
@@ -1,21 +1,20 @@
module Dodge.Default.Shell module Dodge.Default.Shell
where where
import Dodge.Data import Dodge.Data
import Picture
import Geometry.Data import Geometry.Data
defaultShell :: Prop defaultShell :: Proj
defaultShell = Shell defaultShell = Shell
{ _prPos = V2 0 0 { _prjPos = V2 0 0
, _pjZ = 20 , _prjZ = 20
, _pjStartPos = V2 0 0 , _prjStartPos = V2 0 0
, _pjVel = V2 0 0 , _prjVel = V2 0 0
, _pjAcc = V2 0 0 , _prjAcc = V2 0 0
, _pjDir = 0 , _prjDir = 0
, _pjSpin = 0 , _prjSpin = 0
, _prDraw = const (mempty, blank) , _prjDraw = DrawShell
, _pjID = 0 , _prjID = 0
, _pjTimer = 0 , _prjTimer = 0
, _pjUpdate = const id , _prjUpdate = const id
, _pjPayload = const id , _prjPayload = ExplosionPayload
} }
+1
View File
@@ -39,6 +39,7 @@ defaultWorld = World
, _gsZoning = Zoning IM.empty clZoneSize (zonePos _guPos) , _gsZoning = Zoning IM.empty clZoneSize (zonePos _guPos)
, _itemPositions = IM.empty , _itemPositions = IM.empty
, _props = IM.empty , _props = IM.empty
, _projectiles = IM.empty
, _instantBullets = [] , _instantBullets = []
, _bullets = [] , _bullets = []
, _instantParticles = [] , _instantParticles = []
+17 -23
View File
@@ -1,5 +1,5 @@
module Dodge.Item.Weapon.Drone where module Dodge.Item.Weapon.Drone where
import Dodge.Projectile.Draw --import Dodge.Projectile.Draw
import Dodge.Data import Dodge.Data
import Dodge.Default.Weapon import Dodge.Default.Weapon
--import Dodge.Default --import Dodge.Default
@@ -7,17 +7,10 @@ import Dodge.SoundLogic.LoadSound
import Dodge.Item.Weapon.TriggerType import Dodge.Item.Weapon.TriggerType
import Geometry import Geometry
import Picture import Picture
import qualified IntMapHelp as IM
import ShapePicture import ShapePicture
import Shape import Shape
--import qualified Data.Set as S
--import qualified SDL
--import Data.Maybe
import Control.Lens import Control.Lens
--import Control.Applicative
--import Control.Monad.State
--import System.Random
droneLauncher :: Item droneLauncher :: Item
droneLauncher = defaultWeapon droneLauncher = defaultWeapon
@@ -49,18 +42,19 @@ aDroneWithItemParams
-> Creature -> Creature
-> World -> World
-> World -> World
aDroneWithItemParams it cr w = over props (IM.insert i theShell) w aDroneWithItemParams = undefined
where --aDroneWithItemParams it cr w = over props (IM.insert i theShell) w
am = _itConsumption it -- where
i = IM.newKey $ _props w -- am = _itConsumption it
pos = _crPos cr +.+ ((_crRad cr +1) *.* unitVectorAtAngle dir) -- i = IM.newKey $ _props w
dir = _crDir cr -- pos = _crPos cr +.+ ((_crRad cr +1) *.* unitVectorAtAngle dir)
--ammoMvs pj w' = foldr (\pjP -> _pjMoveParam pjP (_pjIntParam pjP) it cr pj) w' (_amPjParams am) -- dir = _crDir cr
theShell = Drone -- --ammoMvs pj w' = foldr (\pjP -> _pjMoveParam pjP (_pjIntParam pjP) it cr pj) w' (_amPjParams am)
{ _prPos = pos -- theShell = Drone
, _pjStartPos = pos -- { _prPos = pos
, _pjVel = rotateV dir (V2 1 0) -- , _pjStartPos = pos
, _prDraw = drawProjectile (_amPjDraw $ _laAmmoType am) -- , _pjVel = rotateV dir (V2 1 0)
, _pjID = i -- , _prDraw = undefined
, _pjUpdate = const id -- , _pjID = i
} -- , _pjUpdate = const id
-- }
+37 -36
View File
@@ -15,7 +15,6 @@ import ShapePicture
import Shape import Shape
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
import Data.Maybe
import Control.Lens import Control.Lens
--grenade :: Item --grenade :: Item
@@ -218,41 +217,43 @@ moveRemoteBomb itid time pID w
throwRemoteBomb :: Creature -> World -> World throwRemoteBomb :: Creature -> World -> World
throwRemoteBomb cr w = setLocation throwRemoteBomb = undefined
$ removePict --throwRemoteBomb cr w = undefined
$ resetFire -- setLocation
-- $ resetName -- $ removePict
$ over props addG w -- $ resetFire
where ---- $ resetName
cid = _crID cr -- $ over props addG w
addG = IM.insert i $ Projectile -- where
{ _prPos = p -- cid = _crID cr
, _pjStartPos = p -- addG = IM.insert i $ Projectile
, _pjVel = v -- { _prPos = p
, _prDraw = const mempty -- , _pjStartPos = p
, _pjID = i -- , _pjVel = v
, _pjUpdate = \_ -> moveRemoteBomb itid 50 i -- , _prDraw = const mempty
} -- , _pjID = i
i = IM.newKey $ _props w -- , _pjUpdate = \_ -> moveRemoteBomb itid 50 i
v' = 0.02 / _cameraZoom w *.* rotateV (_cameraRot w) ( _mousePos w) -- }
v | magV v' > 6 = 6 *.* normalizeV v' -- i = IM.newKey $ _props w
| otherwise = v' -- v' = 0.02 / _cameraZoom w *.* rotateV (_cameraRot w) ( _mousePos w)
j = crSel cr -- v | magV v' > 6 = 6 *.* normalizeV v'
-- resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTE" -- | otherwise = v'
removePict = id -- set (creatures . ix cid . crInv . ix j . itEquipPict) $ \ _ _ -> mempty -- j = crSel cr
resetFire = set (creatures . ix cid . crInv . ix j . itUse . rUse) ---- resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTE"
$ \_ -> explodeRemoteBomb itid i -- removePict = id -- set (creatures . ix cid . crInv . ix j . itEquipPict) $ \ _ _ -> mempty
p' = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr) 0) -- resetFire = set (creatures . ix cid . crInv . ix j . itUse . rUse)
p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr-4) 0) -- $ \_ -> explodeRemoteBomb itid i
| otherwise = p' -- p' = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr) 0)
maybeitid = w ^? creatures . ix cid . crInv . ix j . itID . _Just -- p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr-4) 0)
setLocation :: World -> World -- | otherwise = p'
setLocation w' = case maybeitid of -- maybeitid = w ^? creatures . ix cid . crInv . ix j . itID . _Just
Nothing -> w' & creatures . ix cid . crInv . ix j . itID ?~ newitid -- setLocation :: World -> World
& itemPositions %~ IM.insert newitid (InInv cid j) -- setLocation w' = case maybeitid of
_ -> w' -- Nothing -> w' & creatures . ix cid . crInv . ix j . itID ?~ newitid
newitid = IM.newKey $ _itemPositions w -- & itemPositions %~ IM.insert newitid (InInv cid j)
itid = fromMaybe newitid maybeitid -- _ -> w'
-- newitid = IM.newKey $ _itemPositions w
-- itid = fromMaybe newitid maybeitid
explodeRemoteBomb :: Int -> Int -> Creature -> World -> World explodeRemoteBomb :: Int -> Int -> Creature -> World -> World
explodeRemoteBomb itid pjid cr w explodeRemoteBomb itid pjid cr w
+60 -67
View File
@@ -6,7 +6,6 @@ module Dodge.Item.Weapon.Launcher
) where ) where
import Dodge.Data import Dodge.Data
import Dodge.Payload import Dodge.Payload
import Dodge.Projectile.Draw
import Dodge.Reloading.Action import Dodge.Reloading.Action
import Dodge.EnergyBall import Dodge.EnergyBall
import Dodge.Default.Weapon import Dodge.Default.Weapon
@@ -128,14 +127,14 @@ thrustParam = TweakParam
, _nameTweak = "THRUST DELAY" , _nameTweak = "THRUST DELAY"
} }
pjThrust :: Int -> Prop -> World -> World pjThrust :: Int -> Proj -> World -> World
pjThrust i = pjEffTimeRange (st,et) doThrust pjThrust i = pjEffTimeRange (st,et) doThrust
where where
et | i == 0 = 36 et | i == 0 = 36
| otherwise = 40 - (i * 20) | otherwise = 40 - (i * 20)
st = et - 100 st = et - 100
pjTrack :: Int -> Int -> Prop -> World -> World pjTrack :: Int -> Int -> Proj -> World -> World
pjTrack itid i pj w = pjEffTimeRange (st,et) rotateToTarget pj w pjTrack itid i pj w = pjEffTimeRange (st,et) rotateToTarget pj w
where where
et | i == 0 = 36 et | i == 0 = 36
@@ -143,22 +142,23 @@ pjTrack itid i pj w = pjEffTimeRange (st,et) rotateToTarget pj w
st = et - 100 st = et - 100
rotateToTarget _ = fromMaybe id $ do rotateToTarget _ = fromMaybe id $ do
tpos <- w ^? itPoint . itTargeting . tgPos . _Just tpos <- w ^? itPoint . itTargeting . tgPos . _Just
return $ props . ix (_pjID pj) . pjSpin .~ turnToAmount 0.15 (_prPos pj) tpos (argV $ _pjAcc pj) return $ projectiles . ix (_prjID pj) . prjSpin .~ turnToAmount 0.15 (_prjPos pj) tpos
(argV $ _prjAcc pj)
itPoint = pointToItem $ _itemPositions w IM.! itid itPoint = pointToItem $ _itemPositions w IM.! itid
doThrust :: Prop -> World -> World doThrust :: Proj -> World -> World
doThrust pj w = w doThrust pj w = w
& randGen .~ g & randGen .~ g
& props . ix i . pjVel %~ (\v -> accel +.+ frict *.* v) & projectiles . ix i . prjVel %~ (\v -> accel +.+ frict *.* v)
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1) & soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
& makeFlamelet (oldPos -.- vel) 0 (vel +.+ rotateV (pi+sparkD) accel) 3 10 & makeFlamelet (oldPos -.- vel) 0 (vel +.+ rotateV (pi+sparkD) accel) 3 10
& shellTrailCloud (addZ 20 (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos))) & shellTrailCloud (addZ 20 (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos)))
where where
accel = _pjAcc pj accel = _prjAcc pj
i = _pjID pj i = _prjID pj
oldPos = _prPos pj oldPos = _prjPos pj
vel = _pjVel pj vel = _prjVel pj
newPos = oldPos +.+ vel newPos = oldPos +.+ vel
(frict,g) = randomR (0.6,0.9) $ _randGen w (frict,g) = randomR (0.6,0.9) $ _randGen w
(sparkD,_) = randomR (-0.2,0.2) $ _randGen w (sparkD,_) = randomR (-0.2,0.2) $ _randGen w
r1 = randInCirc 10 & evalState $ _randGen w r1 = randInCirc 10 & evalState $ _randGen w
@@ -175,7 +175,7 @@ fireShell it cr = makeShell it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID c
spinamount = _shellSpinAmount params spinamount = _shellSpinAmount params
thrustdelay = _shellThrustDelay params thrustdelay = _shellThrustDelay params
moveShell :: Prop -- ^ Projectile id moveShell :: Proj -- ^ Projectile id
-> World -> World
-> World -> World
moveShell pj w moveShell pj w
@@ -186,56 +186,51 @@ moveShell pj w
| time > -300 = w | time > -300 = w
| otherwise = doExplode | otherwise = doExplode
where where
time = _pjTimer pj time = _prjTimer pj
doExplode = w doExplode = w
& _pjPayload pj oldPos & usePayload (_prjPayload pj) oldPos
& stopSoundFrom (ShellSound i) & stopSoundFrom (ShellSound i)
& props %~ IM.delete i & projectiles %~ IM.delete i
i = _pjID pj i = _prjID pj
oldPos = _prPos pj oldPos = _prjPos pj
vel = _pjVel pj vel = _prjVel pj
newPos = oldPos +.+ vel newPos = oldPos +.+ vel
reduceSpinBy :: Float -> Prop -> World -> World reduceSpinBy :: Float -> Proj -> World -> World
reduceSpinBy x pj = props . ix (_pjID pj) . pjSpin *~ x reduceSpinBy x pj = projectiles . ix (_prjID pj) . prjSpin *~ x
--shellShape :: Shape
--shellShape = colorSH black $ upperPrismPoly 4 $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)]
pjEffTimeRange pjEffTimeRange
:: (Int,Int) :: (Int,Int)
-> (Prop -> World -> World) -> (Proj -> World -> World)
-> Prop -> Proj
-> World -> World
-> World -> World
pjEffTimeRange (st,et) f pj pjEffTimeRange (st,et) f pj
| t <= et && t >= st = f pj | t <= et && t >= st = f pj
| otherwise = id | otherwise = id
where where
t = _pjTimer pj t = _prjTimer pj
pjEffAtTime pjEffAtTime
:: Int :: Int
-> (Prop -> World -> World) -> (Proj -> World -> World)
-> Prop -> Proj
-> World -> World
-> World -> World
pjEffAtTime t f pj pjEffAtTime t f pj
| _pjTimer pj == t = f pj | _prjTimer pj == t = f pj
| otherwise = id | otherwise = id
trySpinByCID trySpinByCID
:: Int -- ^ creature id :: Int -- ^ creature id
-> Int -- ^ Spin amount -> Int -- ^ Spin amount
-> Prop -> Proj
-> World -> World
-> World -> World
trySpinByCID cid i pj w = w & props . ix pjid . pjSpin .~ newSpin trySpinByCID cid i pj w = w & projectiles . ix pjid . prjSpin .~ newSpin
where where
pjid = _pjID pj pjid = _prjID pj
dir = argV $ _pjVel pj dir = argV $ _prjVel pj
newSpin = case w ^? creatures . ix cid of newSpin = case w ^? creatures . ix cid of
Just cr -> negate $ min 0.2 $ max (-0.2) $ normalizeAnglePi (dir - _crDir cr) / spinFactor Just cr -> negate $ min 0.2 $ max (-0.2) $ normalizeAnglePi (dir - _crDir cr) / spinFactor
_ -> 0 _ -> 0
@@ -252,27 +247,26 @@ remoteLauncher = launcher
fireRemoteShell :: Item -> Creature -> World -> World fireRemoteShell :: Item -> Creature -> World -> World
fireRemoteShell it cr w = set (creatures . ix cid . crInv . ix j . itUse . rUse) fireRemoteShell it cr w = set (creatures . ix cid . crInv . ix j . itUse . rUse)
(\_ _ -> explodeRemoteRocket itid i) (\_ _ -> explodeRemoteRocket itid i)
-- $ set (creatures . ix cid . crInv . ix j . itName) remoteLauncherName
$ addRemRocket w' $ addRemRocket w'
where where
(w',itid) = getHeldItemLoc cr w (w',itid) = getHeldItemLoc cr w
i = IM.newKey $ _props w i = IM.newKey $ _props w
cid = _crID cr cid = _crID cr
addRemRocket = makeShell it cr $ \pj -> addRemRocket = makeShell it cr $ \pj ->
decTimMvVel pj . setRemoteScope itid pj . moveRemoteShell cid itid pj decTimMvVel pj . setRemoteScope itid (_prjPos pj) . moveRemoteShell cid itid pj
j = crSel cr j = crSel cr
moveRemoteShell :: Int -> Int -> Prop -> World -> World moveRemoteShell :: Int -> Int -> Proj -> World -> World
moveRemoteShell cid itid pj w moveRemoteShell cid itid pj w
| time > 40 = if circOnSomeWall oldPos 4 w | time > 40 = if circOnSomeWall oldPos 4 w
then doExplosion then doExplosion
else w else w
| anythingHitCirc 2 oldPos newPos w = doExplosion | anythingHitCirc 2 oldPos newPos w = doExplosion
| time >= 20 = w & props . ix i . pjDir .~ newdir | time >= 20 = w & projectiles . ix i . prjDir .~ newdir
| time > -99 = w & set randGen g | time > -99 = w & set randGen g
& props . ix i %~ & projectiles . ix i %~
( ( pjVel %~ ( (accel +.+) . (frict *.*) ) ) ( ( prjVel %~ ( (accel +.+) . (frict *.*) ) )
. ( pjDir .~ newdir ) . ( prjDir .~ newdir )
) )
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1) & soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
& smokeGen & smokeGen
@@ -280,16 +274,16 @@ moveRemoteShell cid itid pj w
| time > -200 = w | time > -200 = w
| otherwise = doExplosion | otherwise = doExplosion
where where
time = _pjTimer pj time = _prjTimer pj
i = _pjID pj i = _prjID pj
oldPos = _prPos pj oldPos = _prjPos pj
vel = _pjVel pj vel = _prjVel pj
newPos = oldPos +.+ vel newPos = oldPos +.+ vel
newdir newdir
| SDL.ButtonRight `M.member` _mouseButtons w | SDL.ButtonRight `M.member` _mouseButtons w
&& w ^? creatures . ix cid . crInvSel . iselPos == w ^? itemPositions . ix itid . ipInvID && w ^? creatures . ix cid . crInvSel . iselPos == w ^? itemPositions . ix itid . ipInvID
= _cameraRot w + argV (_mousePos w) = _cameraRot w + argV (_mousePos w)
| otherwise = _pjDir pj | otherwise = _prjDir pj
accel = rotateV newdir (V2 2 0) accel = rotateV newdir (V2 2 0)
(frict,g) = randomR (0.6,0.9) $ _randGen w (frict,g) = randomR (0.6,0.9) $ _randGen w
(sparkD,_) = randomR (-0.5,0.5) $ _randGen w (sparkD,_) = randomR (-0.5,0.5) $ _randGen w
@@ -303,21 +297,20 @@ anythingHitCirc rad sp ep w = hitCr || isJust (sequence hitWl)
hitCr = runIdentity $ S.any_ (const True) $ overlap1SegCrs sp ep $ crsNearSeg sp ep w hitCr = runIdentity $ S.any_ (const True) $ overlap1SegCrs sp ep $ crsNearSeg sp ep w
hitWl = collideCircWallsStream sp ep rad $ wlsNearPoint ep w hitWl = collideCircWallsStream sp ep rad $ wlsNearPoint ep w
-- this should probably be wallsOnLine or something -- this should probably be wallsOnLine or something
explodeRemoteRocket explodeRemoteRocket
:: Int -- ^ Item id :: Int -- ^ Item id
-> Int -- ^ Projectile id -> Int -- ^ Projectile id
-> World -> World
-> World -> World
explodeRemoteRocket itid pjid w = w explodeRemoteRocket itid pjid w = w
& props . ix pjid . pjUpdate .~ (\_ -> retireRemoteProj fireRemoteShell itid 30 pjid) & projectiles . ix pjid . prjUpdate .~ (\_ -> retireRemoteProj fireRemoteShell itid 30 pjid)
& props . ix pjid . prDraw .~ const mempty & projectiles . ix pjid . prjDraw .~ DrawBlankProjectile
& itPoint . itUse . rUse .~ (\_ _ -> id) & itPoint . itUse . rUse .~ (\_ _ -> id)
-- & itPoint . itName .~ "REMOTELAUNCHER" -- & itPoint . itName .~ "REMOTELAUNCHER"
& _pjPayload thepj (_prPos thepj) & usePayload (_prjPayload thepj) (_prjPos thepj)
where where
itPoint = pointToItem $ _itemPositions w IM.! itid itPoint = pointToItem $ _itemPositions w IM.! itid
thepj = _props w IM.! pjid thepj = _projectiles w IM.! pjid
fireTrackingShell :: Item -> Creature -> World -> World fireTrackingShell :: Item -> Creature -> World -> World
fireTrackingShell it cr w = addTrackRocket w' fireTrackingShell it cr w = addTrackRocket w'
@@ -334,20 +327,20 @@ fireTrackingShell it cr w = addTrackRocket w'
spindrag = _shellSpinDrag params spindrag = _shellSpinDrag params
params = _itParams it params = _itParams it
makeShell :: Item -> Creature -> (Prop -> World -> World) -> World -> World makeShell :: Item -> Creature -> (Proj -> World -> World) -> World -> World
makeShell it cr theupdate w = w & props %~ IM.insert i Shell makeShell it cr theupdate w = w & projectiles %~ IM.insert i Shell
{ _prPos = pos { _prjPos = pos
, _pjZ = 20 , _prjZ = 20
, _pjStartPos = pos , _prjStartPos = pos
, _pjVel = rotateV dir (V2 1 0) , _prjVel = rotateV dir (V2 1 0)
, _prDraw = drawProjectile (_amPjDraw $ _laAmmoType am) , _prjDraw = DrawShell
, _pjID = i , _prjID = i
, _pjUpdate = theupdate , _prjUpdate = theupdate
, _pjAcc = rotateV dir (V2 3 0) , _prjAcc = rotateV dir (V2 3 0)
, _pjDir = dir , _prjDir = dir
, _pjSpin = 0 , _prjSpin = 0
, _pjPayload = usePayload $ _amPayload $ _laAmmoType am , _prjPayload = _amPayload $ _laAmmoType am
, _pjTimer = 50 , _prjTimer = 50
} }
where where
i = IM.newKey $ _props w i = IM.newKey $ _props w
+3 -3
View File
@@ -40,9 +40,9 @@ setRemoteBombScope itid pj w' = case _itemPositions w' IM.! itid of
.~ (defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5}) .~ (defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5})
_ -> w' _ -> w'
setRemoteScope :: Int -> Prop -> World -> World setRemoteScope :: Int -> Point2 -> World -> World
setRemoteScope itid pj w' = case w' ^? itemPositions . ix itid of setRemoteScope itid pos w' = case w' ^? itemPositions . ix itid of
Just (InInv cid' invid ) Just (InInv cid' invid )
-> w' & creatures . ix cid' . crInv . ix invid . itScope -> w' & creatures . ix cid' . crInv . ix invid . itScope
. scopePos .~ (_prPos pj -.- _crPos (_creatures w' IM.! cid')) . scopePos .~ (pos -.- _crPos (_creatures w' IM.! cid'))
_ -> w' _ -> w'
+8 -8
View File
@@ -5,13 +5,13 @@ import Dodge.Data
import Geometry.Vector import Geometry.Vector
import Control.Lens import Control.Lens
decTimMvVel :: Prop -> World -> World decTimMvVel :: Proj -> World -> World
decTimMvVel pj = props . ix pjid %~ decTimMvVel pj = projectiles . ix pjid %~
( (pjTimer -~ 1) ( (prjTimer -~ 1)
. (prPos %~ (+.+ vel) ) . (prjPos %~ (+.+ vel) )
. (pjAcc %~ rotateV rot ) . (prjAcc %~ rotateV rot )
) )
where where
rot = _pjSpin pj rot = _prjSpin pj
vel = _pjVel pj vel = _prjVel pj
pjid = _pjID pj pjid = _prjID pj
+12 -11
View File
@@ -5,19 +5,20 @@ import Picture
import Shape import Shape
import ShapePicture import ShapePicture
drawProjectile :: ProjectileDraw -> Prop -> SPic drawProjectile :: Proj -> SPic
drawProjectile pd = case pd of drawProjectile prj = case _prjDraw prj of
DrawShell -> drawShell DrawShell -> drawShell prj
DrawRemoteShell -> drawRemoteShell DrawRemoteShell -> drawRemoteShell prj
DrawDrone -> drawShell prj
drawShell :: Prop -> SPic DrawBlankProjectile -> mempty
drawShell :: Proj -> SPic
drawShell pj = noPic drawShell pj = noPic
. translateSHz 18 . translateSHz 18
. uncurryV translateSHf (_prPos pj) . uncurryV translateSHf (_prjPos pj)
$ rotateSH (argV $ _pjAcc pj) shellShape $ rotateSH (argV $ _prjAcc pj) shellShape
shellShape :: Shape shellShape :: Shape
shellShape = colorSH black $ upperPrismPoly 4 $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)] shellShape = colorSH black $ upperPrismPoly 4 $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)]
drawRemoteShell :: Prop -> SPic drawRemoteShell :: Proj -> SPic
drawRemoteShell pj drawRemoteShell pj
| rem (t+200) 20 < 9 | rem (t+200) 20 < 9
= doposition $ noPic shellShape = doposition $ noPic shellShape
@@ -25,8 +26,8 @@ drawRemoteShell pj
where where
col | t > (-99) = green col | t > (-99) = green
| otherwise = red | otherwise = red
t = _pjTimer pj t = _prjTimer pj
doposition = translateSPz 18 . uncurryV translateSPf (_prPos pj) . rotateSP (_pjDir pj) doposition = translateSPz 18 . uncurryV translateSPf (_prjPos pj) . rotateSP (_prjDir pj)
remoteShellShape :: Color -> SPic remoteShellShape :: Color -> SPic
remoteShellShape col = (shellShape remoteShellShape col = (shellShape
, setLayer BloomNoZWrite . setDepth 4.5 . color col $ circleSolid 3 , setLayer BloomNoZWrite . setDepth 4.5 . color col $ circleSolid 3
+2
View File
@@ -2,6 +2,7 @@ module Dodge.Render.ShapePicture
( worldSPic ( worldSPic
) where ) where
import Dodge.RadarSweep.Draw import Dodge.RadarSweep.Draw
import Dodge.Projectile.Draw
import Dodge.Item.Draw.SPic import Dodge.Item.Draw.SPic
import Dodge.EnergyBall.Draw import Dodge.EnergyBall.Draw
import Dodge.Creature.Picture.Awareness import Dodge.Creature.Picture.Awareness
@@ -53,6 +54,7 @@ worldSPic :: Configuration -> World -> SPic
worldSPic cfig w worldSPic cfig w
= singleSPic (mempty, extraPics cfig w) = singleSPic (mempty, extraPics cfig w)
<> foldup (dbArg _prDraw) (filtOn _prPos _props) <> foldup (dbArg _prDraw) (filtOn _prPos _props)
<> foldup drawProjectile (filtOn _prjPos _projectiles)
<> foldup (shiftDraw _blPos _blDir _blDraw) (filtOn _blPos _blocks) <> foldup (shiftDraw _blPos _blDir _blDraw) (filtOn _blPos _blocks)
<> foldup (shiftDraw _fsPos _fsDir (const _fsSPic)) (filtOn _fsPos _foregroundShapes) <> foldup (shiftDraw _fsPos _fsDir (const _fsSPic)) (filtOn _fsPos _foregroundShapes)
<> foldup (dbArg _cpPict) (filtOn _cpPos _corpses) <> foldup (dbArg _cpPict) (filtOn _cpPos _corpses)
+1
View File
@@ -87,6 +87,7 @@ functionalUpdate cfig w = checkEndGame
. updateFlares . updateFlares
. updateBeams . updateBeams
. updateIMl _props _pjUpdate . updateIMl _props _pjUpdate
. updateIMl _projectiles _prjUpdate
. updateLightSources . updateLightSources
. updateClouds . updateClouds
. updateGusts . updateGusts