From 2e25c4cfccccf7394471c881cdc19a258507a7e2 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sat, 1 May 2021 22:16:06 +0200 Subject: [PATCH] introduce and propagate view direction --- src/Scenes/Test/EventHandler.hs | 7 +++++ src/Scenes/Test/Load.hs | 1 + src/Types/Player.hs | 48 ++++++++++++++++++++------------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/Scenes/Test/EventHandler.hs b/src/Scenes/Test/EventHandler.hs index 9f4d6f6..fb6c550 100644 --- a/src/Scenes/Test/EventHandler.hs +++ b/src/Scenes/Test/EventHandler.hs @@ -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)) $ diff --git a/src/Scenes/Test/Load.hs b/src/Scenes/Test/Load.hs index 19d53a9..73d85e5 100644 --- a/src/Scenes/Test/Load.hs +++ b/src/Scenes/Test/Load.hs @@ -82,6 +82,7 @@ load level progress = do tex False Nothing + ViewRight [] oil = PowerUp (realToFrac <$> (startpos + V2 200 0)) diff --git a/src/Types/Player.hs b/src/Types/Player.hs index 48f7295..cbde911 100644 --- a/src/Types/Player.hs +++ b/src/Types/Player.hs @@ -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)) =