This commit is contained in:
2024-12-27 22:32:56 +00:00
parent 3b19e7e530
commit 9168acf12e
5 changed files with 123 additions and 107 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ data Projectile
= Shell
{ _prjPos :: Point2
, _prjVel :: Point2
, _prjAcc :: Point2
-- , _prjAcc :: Point2
, _prjDir :: Float
, _prjSpin :: Float
, _prjDraw :: ProjectileDraw
+1 -1
View File
@@ -36,7 +36,7 @@ createShell homing mdetonator mscreen smokestatus pjtype payload muz cr w = w
, _prjVel = rotateV dir (V2 speed 0) + cr ^. crPos - cr ^. crOldPos
, _prjDraw = homingDrawType homing
, _prjID = i
, _prjAcc = rotateV dir (V2 3 0)
-- , _prjAcc = rotateV dir (V2 3 0)
, _prjDir = dir
, _prjSpin = 0
, _prjPayload = payload
+1 -1
View File
@@ -22,7 +22,7 @@ drawShell pj =
noPic
. translateSHz (_prjZ pj)
. uncurryV translateSHxy (_prjPos pj)
$ rotateSH (argV $ _prjAcc pj) shellShape
$ rotateSH (_prjDir pj) shellShape
shellShape :: Shape
shellShape = colorSH black $ upperPrismPoly Small Typical 4 $ map toV2 [(-6, 4), (-6, -4), (6, -4), (8, 0), (6, 4)]
+58 -45
View File
@@ -3,10 +3,9 @@ module Dodge.Projectile.Update (
updateProjectile,
) where
import Data.List (delete)
import LensHelp
import Control.Monad
import Data.Foldable
import Data.List (delete)
import Data.Maybe
import Dodge.Base
import Dodge.Data.World
@@ -18,6 +17,7 @@ import Dodge.SoundLogic
import Dodge.WorldEvent.Cloud
import Geometry
import qualified IntMapHelp as IM
import LensHelp
import NewInt
import RandomHelp
@@ -26,8 +26,12 @@ updateProjectile pj w = foldl' (\w' pu -> upProjectile pu pj w') w (_prjUpdates
upProjectile :: ProjectileUpdate -> Projectile -> World -> World
upProjectile pu pj = case pu of
CollisionEffectPU mcontrolid mdetonatorid mscreenid -> shellCollisionCheck
mcontrolid mdetonatorid mscreenid pj
CollisionEffectPU mcontrolid mdetonatorid mscreenid ->
shellCollisionCheck
mcontrolid
mdetonatorid
mscreenid
pj
TimePU -> decTimMvVel pj
ThrustPU st et smoke
| act st et -> doThrust pj smoke
@@ -50,21 +54,25 @@ upProjectile pu pj = case pu of
applyGravityPU :: Projectile -> World -> World
applyGravityPU pj w
| newz <= 0 && abs (pj ^. prjZVel) < 1 = w
& topj . prjVel %~ decvel
& topj . prjSpin %~ decspin
| newz < 0 = w & topj . prjZ .~ 0
& topj . prjZVel %~ bouncez
& topj . prjVel %~ decvel
& topj . prjSpin %~ decspin
& soundStart (ShellSound (pj ^. prjID)) (pj ^. prjPos) click1S Nothing
| otherwise = w & topj . prjZ .~ newz
& topj . prjZVel -~ 0.5
| newz <= 0 && abs (pj ^. prjZVel) < 1 =
w
& topj . prjVel %~ decvel
& topj . prjSpin %~ decspin
| newz < 0 =
w & topj . prjZ .~ 0
& topj . prjZVel %~ bouncez
& topj . prjVel %~ decvel
& topj . prjSpin %~ decspin
& soundStart (ShellSound (pj ^. prjID)) (pj ^. prjPos) click1S Nothing
| otherwise =
w & topj . prjZ .~ newz
& topj . prjZVel -~ 0.5
where
topj = cWorld . lWorld . projectiles . ix (pj ^. prjID)
bouncez z | z < -1 = -0.5 * z
bouncez z
| z < -1 = -0.5 * z
| otherwise = 0
decvel v
decvel v
| magV v > 1 = rotateV (5 * pj ^. prjSpin) $ 0.8 * v
| otherwise = 0
decspin x
@@ -73,13 +81,16 @@ applyGravityPU pj w
newz = pj ^. prjZ + pj ^. prjZVel
--shellCollisionCheck :: (Projectile -> World -> World) -> Projectile -> World -> World
shellCollisionCheck :: Maybe (NewInt ItmInt)
-> Maybe (NewInt ItmInt)
-> Maybe (NewInt ItmInt)
-> Projectile -> World -> World
shellCollisionCheck ::
Maybe (NewInt ItmInt) ->
Maybe (NewInt ItmInt) ->
Maybe (NewInt ItmInt) ->
Projectile ->
World ->
World
shellCollisionCheck controlid detid screenid pj w
-- | time > 330 && circOnSomeWall oldPos 4 w = g
-- | time <= 330 && anythingHitCirc 2 oldPos newPos w = g
-- | time > 330 && circOnSomeWall oldPos 4 w = g
-- | time <= 330 && anythingHitCirc 2 oldPos newPos w = g
| anythingHitCirc 2 oldPos newPos w = g
| time <= 0 = g
| otherwise = w
@@ -114,10 +125,11 @@ doThrust pj smoke w =
(addZ 20 (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos)))
where
lifetime = fst . randomR lt $ _randGen w
lt | smoke = (50, 200)
| otherwise = (300,500)
trailfadetime = fst . randomR (100,300) $ _randGen w
accel = _prjAcc pj
lt
| smoke = (50, 200)
| otherwise = (300, 500)
trailfadetime = fst . randomR (100, 300) $ _randGen w
accel = rotateV (pj ^. prjDir) (V2 3 0)
i = _prjID pj
oldPos = _prjPos pj
vel = _prjVel pj
@@ -146,20 +158,18 @@ trySpinByCID cid i pj w = w & cWorld . lWorld . projectiles . ix pjid . prjSpin
-- note this only allows YOU to remotely track projectiles
pjRemoteSetDirection :: ProjectileHoming -> Projectile -> World -> World
pjRemoteSetDirection ph pj w = case ph of
NoHoming -> w
HomeUsingRemoteScreen screenid ->
let newdir
| w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imSelectedItem
== w ^? cWorld . lWorld . itemLocations . ix (_unNInt screenid) . ilInvID =
(w ^. wCam . camRot) + argV (_mousePos (_input w))
| otherwise = _prjDir pj
in w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjAcc
.~ magV (_prjAcc pj) *.* unitVectorAtAngle newdir
HomeUsingTargeting itid -> fromMaybe w $ do
tp <- w ^? pointerToItemID itid . itTargeting . itTgPos . _Just
return $
w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjAcc
%~ vecTurnTo 0.2 (_prjPos pj) tp
HomeUsingRemoteScreen screenid
| lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem
== lw ^? itemLocations . ix (_unNInt screenid) . ilInvID ->
w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjDir
.~ (w ^. wCam . camRot) + argV (w ^. input . mousePos)
HomeUsingTargeting itid
| Just tp <- w ^? pointerToItemID itid . itTargeting . itTgPos . _Just ->
w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjDir
%~ turnTo 0.2 (_prjPos pj) tp
_ -> w
where
lw = w ^. cWorld . lWorld
--pjRemoteSetDirection mscreenid pj w = fromMaybe w $ do
-- screenid <- fmap _unNInt mscreenid
@@ -179,7 +189,7 @@ decTimMvVel pj =
cWorld . lWorld . projectiles . ix pjid
%~ ( (prjTimer -~ 1)
. (prjPos %~ (+.+ vel))
. (prjAcc %~ rotateV rot)
-- . (prjAcc %~ rotateV rot)
. (prjDir +~ rot)
)
where
@@ -187,10 +197,13 @@ decTimMvVel pj =
vel = _prjVel pj
pjid = _prjID pj
explodeShell :: Maybe (NewInt ItmInt) ->
Maybe (NewInt ItmInt) ->
Maybe (NewInt ItmInt) ->
Projectile -> World -> World
explodeShell ::
Maybe (NewInt ItmInt) ->
Maybe (NewInt ItmInt) ->
Maybe (NewInt ItmInt) ->
Projectile ->
World ->
World
explodeShell controlid mdetid screenid pj w =
w
& cWorld . lWorld . projectiles . ix pjid . prjUpdates .~ [DestroyPU screenid 30]