From 8a620f742e7df356773e99c59cf4e8bb08e8dc0c Mon Sep 17 00:00:00 2001 From: nek0 Date: Tue, 15 May 2018 19:27:40 +0200 Subject: [PATCH] nonuniform movement speeds for NPCs --- src/Test.hs | 6 +++++- src/Types/UserData.hs | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Test.hs b/src/Test.hs index d80bb48..0ac4620 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -64,9 +64,11 @@ loadMap = do } void $ mapM_ (\(V2 nr nc) -> do -- ttl <- liftIO $ randomRIO (5, 30) + fact <- liftIO $ randomRIO (0.5, 1.5) newEntity $ defEntity { pos = Just (V2 (nr + 0.5) (nc + 0.5)) , vel = Just (V2 0 0) + , velFact = Just fact , npcState = Just (NPCStanding 0) } ) npcposs @@ -181,10 +183,12 @@ updateMap dt = do emap $ do without player with vel + with velFact with pos pos'@(V2 pr pc) <- E.get pos vel' <- E.get vel - let npos@(V2 nr nc) = pos' + fmap (* dt) vel' + fact' <- E.get velFact + let npos@(V2 nr nc) = pos' + fmap (* (dt * fact')) vel' dpos = npos - pos' ent = defEntity' { pos = Set $ npos diff --git a/src/Types/UserData.hs b/src/Types/UserData.hs index 263aa9b..172e0df 100644 --- a/src/Types/UserData.hs +++ b/src/Types/UserData.hs @@ -147,6 +147,7 @@ data Entity f = Entity { pos :: Component f 'Field (V2 Double) , gridPos :: Component f 'Field (V2 Int) , vel :: Component f 'Field (V2 Double) + , velFact :: Component f 'Field Double , rot :: Component f 'Field Direction , obstacle :: Component f 'Field (Boundaries Double) , player :: Component f 'Unique ()