nonuniform movement speeds for NPCs

This commit is contained in:
nek0 2018-05-15 19:27:40 +02:00
parent 1c9076c838
commit 8a620f742e
2 changed files with 6 additions and 1 deletions

View file

@ -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

View file

@ -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 ()