Start projectile refactor

This commit is contained in:
2022-07-20 01:44:16 +01:00
parent 6e901d3086
commit 9daf872878
6 changed files with 56 additions and 38 deletions
+4 -2
View File
@@ -10,6 +10,7 @@ circular imports are probably not a good idea.
{-# LANGUAGE DerivingStrategies #-}
module Dodge.Data
( module Dodge.Data
, module Dodge.Data.Ammo
, module Dodge.Data.Payload
, module Dodge.Data.RadarSweep
, module Dodge.Data.PosEvent
@@ -54,6 +55,7 @@ module Dodge.Data
, module Dodge.Data.RadarBlip
, module Dodge.Data.PathGraph
) where
import Dodge.Data.Ammo
import Dodge.Data.Payload
import Dodge.Data.RadarSweep
import Dodge.Data.PosEvent
@@ -590,9 +592,9 @@ type HitEffect' = Flame
data AmmoType
= ProjectileAmmo
{ _amPayload :: Point2 -> World -> World
{ _amPayload :: Payload
, _amString :: String
, _amPjDraw :: Prop -> SPic
, _amPjDraw :: ProjectileDraw
, _amPjCreation :: Item -> Creature -> World -> World
}
| BulletAmmo
+3
View File
@@ -2,3 +2,6 @@
--{-# LANGUAGE StrictData #-}
module Dodge.Data.Ammo where
data ProjectileDraw = DrawShell | DrawRemoteShell
data ProjectileCreate = CreateShell
+2 -1
View File
@@ -1,4 +1,5 @@
module Dodge.Item.Weapon.Drone where
import Dodge.Projectile.Draw
import Dodge.Data
import Dodge.Default.Weapon
--import Dodge.Default
@@ -59,7 +60,7 @@ aDroneWithItemParams it cr w = over props (IM.insert i theShell) w
{ _prPos = pos
, _pjStartPos = pos
, _pjVel = rotateV dir (V2 1 0)
, _prDraw = _amPjDraw $ _laAmmoType am
, _prDraw = drawProjectile (_amPjDraw $ _laAmmoType am)
, _pjID = i
, _pjUpdate = const id
}
+9 -32
View File
@@ -5,12 +5,13 @@ module Dodge.Item.Weapon.Launcher
, fireTrackingShell
) where
import Dodge.Data
import Dodge.Payload
import Dodge.Projectile.Draw
import Dodge.Reloading.Action
import Dodge.EnergyBall
import Dodge.Default.Weapon
import Dodge.Item.Location
import Dodge.SoundLogic.LoadSound
import Dodge.WorldEvent.Explosion
import Dodge.Item.Weapon.Shell
import Dodge.Item.Weapon.Remote
import Dodge.Item.Weapon.TriggerType
@@ -21,11 +22,7 @@ import Dodge.SoundLogic
import Dodge.WorldEvent.Cloud
import RandomHelp
import Geometry
import Picture
import qualified IntMapHelp as IM
--import Padding
import ShapePicture
import Shape
import qualified Streaming.Prelude as S
--import qualified Data.Set as S
@@ -38,9 +35,9 @@ launcher :: Item
launcher = defaultWeapon
{ _itConsumption = defaultLoadable
& laAmmoType .~ ProjectileAmmo
{ _amPayload = makeExplosionAt
{ _amPayload = ExplosionPayload
, _amString = "EXPLOSIVE SHELL"
, _amPjDraw = drawShell
, _amPjDraw = DrawShell
, _amPjCreation = fireShell
}
& laMax .~ 1
@@ -202,30 +199,10 @@ moveShell pj w
reduceSpinBy :: Float -> Prop -> World -> World
reduceSpinBy x pj = props . ix (_pjID pj) . pjSpin *~ x
drawShell :: Prop -> SPic
drawShell pj = noPic
. translateSHz 18
. uncurryV translateSHf (_prPos pj)
$ rotateSH (argV $ _pjAcc pj) shellShape
shellShape :: Shape
shellShape = colorSH black $ upperPrismPoly 4 $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)]
--shellShape :: Shape
--shellShape = colorSH black $ upperPrismPoly 4 $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)]
remoteShellShape :: Color -> SPic
remoteShellShape col = (shellShape
, setLayer BloomNoZWrite . setDepth 4.5 . color col $ circleSolid 3
)
drawRemoteShell :: Prop -> SPic
drawRemoteShell pj
| rem (t+200) 20 < 9
= doposition $ noPic shellShape
| otherwise = doposition $ remoteShellShape col
where
col | t > (-99) = green
| otherwise = red
t = _pjTimer pj
doposition = translateSPz 18 . uncurryV translateSPf (_prPos pj) . rotateSP (_pjDir pj)
pjEffTimeRange
:: (Int,Int)
@@ -269,7 +246,7 @@ remoteLauncher = launcher
& itType . iyBase .~ HELD REMOTELAUNCHER
& itUse . rUse .~ fireRemoteShell
& itScope .~ RemoteScope (V2 0 0) 1 True
& itConsumption . laAmmoType . amPjDraw .~ drawRemoteShell
& itConsumption . laAmmoType . amPjDraw .~ DrawRemoteShell
-- TODO consider allowing tweaking rocket speed
fireRemoteShell :: Item -> Creature -> World -> World
@@ -363,13 +340,13 @@ makeShell it cr theupdate w = w & props %~ IM.insert i Shell
, _pjZ = 20
, _pjStartPos = pos
, _pjVel = rotateV dir (V2 1 0)
, _prDraw = _amPjDraw $ _laAmmoType am
, _prDraw = drawProjectile (_amPjDraw $ _laAmmoType am)
, _pjID = i
, _pjUpdate = theupdate
, _pjAcc = rotateV dir (V2 3 0)
, _pjDir = dir
, _pjSpin = 0
, _pjPayload = _amPayload $ _laAmmoType am
, _pjPayload = usePayload $ _amPayload $ _laAmmoType am
, _pjTimer = 50
}
where
+4 -3
View File
@@ -1,8 +1,9 @@
module Dodge.Projectile where
import Dodge.Data
--createProjectile :: ProjectileType -> Item -> Creature -> World -> World
--createProjectile pt = case pt of
-- ShellType -> fireShell
createProjectile :: ProjectileCreate -> Item -> Creature -> World -> World
createProjectile pt = case pt of
CreateShell -> undefined
--
--fireShell :: Item -> Creature -> World -> World
--fireShell it cr = makeShell it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
+34
View File
@@ -0,0 +1,34 @@
module Dodge.Projectile.Draw where
import Dodge.Data
import Geometry
import Picture
import Shape
import ShapePicture
drawProjectile :: ProjectileDraw -> Prop -> SPic
drawProjectile pd = case pd of
DrawShell -> drawShell
DrawRemoteShell -> drawRemoteShell
drawShell :: Prop -> SPic
drawShell pj = noPic
. translateSHz 18
. uncurryV translateSHf (_prPos pj)
$ rotateSH (argV $ _pjAcc pj) shellShape
shellShape :: Shape
shellShape = colorSH black $ upperPrismPoly 4 $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)]
drawRemoteShell :: Prop -> SPic
drawRemoteShell pj
| rem (t+200) 20 < 9
= doposition $ noPic shellShape
| otherwise = doposition $ remoteShellShape col
where
col | t > (-99) = green
| otherwise = red
t = _pjTimer pj
doposition = translateSPz 18 . uncurryV translateSPf (_prPos pj) . rotateSP (_pjDir pj)
remoteShellShape :: Color -> SPic
remoteShellShape col = (shellShape
, setLayer BloomNoZWrite . setDepth 4.5 . color col $ circleSolid 3
)