introduce and propagate view direction

This commit is contained in:
nek0 2021-05-01 22:16:06 +02:00
parent 58ae21724b
commit 2e25c4cfcc
3 changed files with 37 additions and 19 deletions

View File

@ -25,6 +25,13 @@ singleHandler level event = do
changeDirection cat state =
Just cat
{ pcMoveState = if multiplier > 0 then Just state else Nothing
, pcViewDirection = if multiplier > 0 && pcGrounded cat
then
if state == MoveRight
then ViewRight
else ViewLeft
else
pcViewDirection cat
}
liftIO $ atomically $ modifyTVar (testPlayer level) (\(Just pituicat) ->
A.log Debug ("Grounded: " <> fromString (show $ pcGrounded pituicat)) $

View File

@ -82,6 +82,7 @@ load level progress = do
tex
False
Nothing
ViewRight
[]
oil = PowerUp
(realToFrac <$> (startpos + V2 200 0))

View File

@ -30,28 +30,32 @@ catMoveVelocity :: Double
catMoveVelocity = 100
data Pituicat = Pituicat
{ pcPos :: V2 Double
, pcVel :: V2 Double
, pcMoveVel :: V2 Double
, pcTMoveVel :: V2 Double
, pcAcc :: V2 Double
, pcHealth :: Int
, pcTexture :: Texture
, pcGrounded :: Bool
, pcMoveState :: Maybe Action
, pcEffects :: [EffectHolder]
{ pcPos :: V2 Double
, pcVel :: V2 Double
, pcMoveVel :: V2 Double
, pcTMoveVel :: V2 Double
, pcAcc :: V2 Double
, pcHealth :: Int
, pcTexture :: Texture
, pcGrounded :: Bool
, pcMoveState :: Maybe Action
, pcViewDirection :: ViewDirection
, pcEffects :: [EffectHolder]
}
deriving (Eq, Show)
data ViewDirection = ViewLeft | ViewRight
deriving (Eq, Show)
instance Drawable Pituicat where
toVertices (Pituicat (V2 x y) _ (V2 mx _) _ _ _ _ _ _ _) =
toVertices (Pituicat (V2 x y) _ _ _ _ _ _ _ _ vd _) =
( V.fromList [0, 1, 2, 2, 3, 0]
, V.fromList
[ newVertex
(V3 (realToFrac x - 25) (realToFrac y - 25) 0)
(V4 1 1 1 1)
(if mx >= 0
(if vd == ViewRight
then V2 0 (1 - 50 / 1024)
else V2 (50 / 1024) (1 - 50 / 1024)
)
@ -59,7 +63,7 @@ instance Drawable Pituicat where
, newVertex
(V3 (realToFrac x + 25) (realToFrac y - 25) 0)
(V4 1 1 1 1)
( if mx >= 0
(if vd == ViewRight
then V2 (50 / 1024) (1 - 50 / 1024)
else V2 0 (1 - 50 / 1024)
)
@ -67,7 +71,7 @@ instance Drawable Pituicat where
, newVertex
(V3 (realToFrac x + 25) (realToFrac y + 25) 0)
(V4 1 1 1 1)
(if mx >= 0
(if vd == ViewRight
then V2 (50 / 1024) 1
else V2 0 1
)
@ -75,7 +79,7 @@ instance Drawable Pituicat where
, newVertex
(V3 (realToFrac x - 25) (realToFrac y + 25) 0)
(V4 1 1 1 1)
(if mx >= 0
(if vd == ViewRight
then V2 0 1
else V2 (50 / 1024) 1
)
@ -174,10 +178,16 @@ instance Mass Pituicat where
instance Collidible Pituicat where
boundary _ =
( V2 (-18) (-25)
, V2 25 15
)
boundary cat =
if pcViewDirection cat == ViewRight
then
( V2 (-18) (-25)
, V2 25 15
)
else
( V2 (-25) (-25)
, V2 18 15
)
collide cat _ NoCollision = cat
collide cat other collr@(Collision ddt (V2 dirx diry)) =