walking animation
This commit is contained in:
parent
f6db4f5e5c
commit
fbcc1b0e45
4 changed files with 79 additions and 16 deletions
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 4 KiB After Width: | Height: | Size: 12 KiB |
19
src/Init.hs
19
src/Init.hs
|
@ -81,17 +81,24 @@ load = do
|
||||||
-- (zipWith (\a b -> (a, [b])) [0..] $ [ImgIntrE .. ImgIntrN] ++ [ImgIntrNE])
|
-- (zipWith (\a b -> (a, [b])) [0..] $ [ImgIntrE .. ImgIntrN] ++ [ImgIntrNE])
|
||||||
let imgs = zipWith (\a b -> (a, fromJust b)) [ImgWallAsc ..] mimgs
|
let imgs = zipWith (\a b -> (a, fromJust b)) [ImgWallAsc ..] mimgs
|
||||||
directions = [E .. N] ++ [NE]
|
directions = [E .. N] ++ [NE]
|
||||||
animIds = map (AnimId 0 "standing") directions
|
standIds = map (AnimId 0 "standing") directions
|
||||||
animConfigs = map
|
walkIds = map (AnimId 0 "walking") directions
|
||||||
|
standConfigs = map
|
||||||
(\i -> AnimationConfig (0, i * 74) (64, 74) 1 0 APLoop)
|
(\i -> AnimationConfig (0, i * 74) (64, 74) 1 0 APLoop)
|
||||||
[0 .. length animIds]
|
[0 .. length standIds - 1]
|
||||||
animations <- loadAnimationSprites "assets/intruder.png" nvg
|
walkConfigs = map
|
||||||
(zip animIds animConfigs)
|
(\i -> AnimationConfig (64, i * 74) (64, 74) 6 1 APLoop)
|
||||||
|
[0 .. length walkIds - 1]
|
||||||
|
playerStanding <- loadAnimationSprites "assets/intruder.png" nvg
|
||||||
|
(zip standIds standConfigs)
|
||||||
|
playerWalking <- loadAnimationSprites "assets/intruder.png" nvg
|
||||||
|
(zip walkIds walkConfigs)
|
||||||
return UserData
|
return UserData
|
||||||
{ state = Menu
|
{ state = Menu
|
||||||
, subsystems = subs
|
, subsystems = subs
|
||||||
, assetImages = M.fromList imgs
|
, assetImages = M.fromList imgs
|
||||||
, assetAnimations = M.fromList animations
|
, assetAnimations = M.fromList
|
||||||
|
(playerStanding ++ playerWalking)
|
||||||
, assetFonts = M.fromList
|
, assetFonts = M.fromList
|
||||||
[ (FontBedstead, "bedstead")
|
[ (FontBedstead, "bedstead")
|
||||||
]
|
]
|
||||||
|
|
76
src/Test.hs
76
src/Test.hs
|
@ -320,14 +320,42 @@ updateMap dt = do
|
||||||
stat <- query anim
|
stat <- query anim
|
||||||
let npos = pos' + fmap (* (dt * fact')) vel'
|
let npos = pos' + fmap (* (dt * fact')) vel'
|
||||||
aId = asId stat
|
aId = asId stat
|
||||||
|
nstat = case aiName aId of
|
||||||
|
"walking"
|
||||||
|
| sqrt (vel' `dot` vel') > 0 ->
|
||||||
|
stat
|
||||||
|
{ asId = aId
|
||||||
|
{ aiDirection = direction vel' rot'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| otherwise ->
|
||||||
|
stat
|
||||||
|
{ asId = aId
|
||||||
|
{ aiDirection = direction vel' rot'
|
||||||
|
, aiName = "standing"
|
||||||
|
}
|
||||||
|
, asCurrentFrame = 0
|
||||||
|
}
|
||||||
|
"standing"
|
||||||
|
| sqrt (vel' `dot` vel') > 0 ->
|
||||||
|
stat
|
||||||
|
{ asId = aId
|
||||||
|
{ aiDirection = direction vel' rot'
|
||||||
|
, aiName = "walking"
|
||||||
|
}
|
||||||
|
, asCurrentFrame = 0
|
||||||
|
}
|
||||||
|
| otherwise ->
|
||||||
|
stat
|
||||||
|
{ asId = aId
|
||||||
|
{ aiDirection = direction vel' rot'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x -> error ("unknown animation name" ++ x)
|
||||||
ent = unchanged
|
ent = unchanged
|
||||||
{ pos = Set npos
|
{ pos = Set npos
|
||||||
, rot = Set $ direction vel' rot'
|
, rot = Set $ direction vel' rot'
|
||||||
, anim = Set stat
|
, anim = Set nstat
|
||||||
{ asId = aId
|
|
||||||
{ aiDirection = direction vel' rot'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ent
|
return ent
|
||||||
emap allEnts $ do
|
emap allEnts $ do
|
||||||
|
@ -343,6 +371,38 @@ updateMap dt = do
|
||||||
let npos = pos' + fmap (* dt) vel'
|
let npos = pos' + fmap (* dt) vel'
|
||||||
dpos@(V2 dpr dpc) = npos - pos'
|
dpos@(V2 dpr dpc) = npos - pos'
|
||||||
aId = asId stat
|
aId = asId stat
|
||||||
|
nstat = case aiName aId of
|
||||||
|
"walking"
|
||||||
|
| sqrt (vel' `dot` vel') > 0 ->
|
||||||
|
stat
|
||||||
|
{ asId = aId
|
||||||
|
{ aiDirection = direction vel' rot'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| otherwise ->
|
||||||
|
stat
|
||||||
|
{ asId = aId
|
||||||
|
{ aiDirection = direction vel' rot'
|
||||||
|
, aiName = "standing"
|
||||||
|
}
|
||||||
|
, asCurrentFrame = 0
|
||||||
|
}
|
||||||
|
"standing"
|
||||||
|
| sqrt (vel' `dot` vel') > 0 ->
|
||||||
|
stat
|
||||||
|
{ asId = aId
|
||||||
|
{ aiDirection = direction vel' rot'
|
||||||
|
, aiName = "walking"
|
||||||
|
}
|
||||||
|
, asCurrentFrame = 0
|
||||||
|
}
|
||||||
|
| otherwise ->
|
||||||
|
stat
|
||||||
|
{ asId = aId
|
||||||
|
{ aiDirection = direction vel' rot'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x -> error ("unknown animation name" ++ x)
|
||||||
len = sqrt (dpos `dot` dpos)
|
len = sqrt (dpos `dot` dpos)
|
||||||
lll = (,)
|
lll = (,)
|
||||||
<$> (
|
<$> (
|
||||||
|
@ -374,11 +434,7 @@ updateMap dt = do
|
||||||
(A.log A.Verbose (show lll ++ " " ++ show len) lll)
|
(A.log A.Verbose (show lll ++ " " ++ show len) lll)
|
||||||
)
|
)
|
||||||
, rot = Set (direction vel' rot')
|
, rot = Set (direction vel' rot')
|
||||||
, anim = Set stat
|
, anim = Set nstat
|
||||||
{ asId = aId
|
|
||||||
{ aiDirection = direction vel' rot'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ent
|
return ent
|
||||||
updateNPCs
|
updateNPCs
|
||||||
|
|
Loading…
Reference in a new issue