Added simple movement to model updates.
This commit is contained in:
parent
84170a58b6
commit
9b2a65f64d
3 changed files with 57 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
module AnimationHelpers exposing (..)
|
module AnimationHelpers exposing (..)
|
||||||
|
|
||||||
import Types exposing (Range)
|
import Types exposing (Range)
|
||||||
|
import Svg.Path exposing (Point)
|
||||||
|
|
||||||
|
|
||||||
calculateAnimation : Int -> Int -> Range -> Float
|
calculateAnimation : Int -> Int -> Range -> Float
|
||||||
|
@ -13,3 +14,28 @@ calculateAnimation current cycle range =
|
||||||
end - start
|
end - start
|
||||||
in
|
in
|
||||||
(toFloat (current % (cycle + 1))) / (toFloat (cycle)) * rangeDiff + start
|
(toFloat (current % (cycle + 1))) / (toFloat (cycle)) * rangeDiff + start
|
||||||
|
|
||||||
|
|
||||||
|
movePosition : Point -> Float -> Float -> Point
|
||||||
|
movePosition position direction distance =
|
||||||
|
let
|
||||||
|
rads =
|
||||||
|
degrees direction
|
||||||
|
|
||||||
|
x =
|
||||||
|
(Tuple.first position) + (cos rads * distance)
|
||||||
|
|
||||||
|
y =
|
||||||
|
(Tuple.second position) + (sin rads * distance)
|
||||||
|
in
|
||||||
|
( x, y )
|
||||||
|
|
||||||
|
|
||||||
|
distanceFromSpeed : Float -> Float -> Float
|
||||||
|
distanceFromSpeed pixPerSec millis =
|
||||||
|
pixPerSec * millis / 1000
|
||||||
|
|
||||||
|
|
||||||
|
fmod : Float -> Float -> Float
|
||||||
|
fmod lh rh =
|
||||||
|
lh - (toFloat (floor (lh / rh)) * rh)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
module GLOBALS exposing (..)
|
module GLOBALS exposing (..)
|
||||||
|
|
||||||
|
|
||||||
move_speed =
|
player_move_speed =
|
||||||
60
|
120
|
||||||
|
|
||||||
|
|
||||||
character_radius =
|
character_radius =
|
||||||
|
|
|
@ -1,8 +1,35 @@
|
||||||
module Updates.Player exposing (update)
|
module Updates.Player exposing (update)
|
||||||
|
|
||||||
import Types exposing (PlayerModel, Msg)
|
import Types exposing (Direction(Up, Down, Left, Right), PlayerModel, Msg(Tick, Tock))
|
||||||
|
import AnimationHelpers exposing (movePosition, distanceFromSpeed)
|
||||||
|
import GLOBALS exposing (player_move_speed)
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> PlayerModel -> ( PlayerModel, Cmd Msg )
|
update : Msg -> PlayerModel -> ( PlayerModel, Cmd Msg )
|
||||||
update msg model =
|
update msg model =
|
||||||
( model, Cmd.none )
|
case msg of
|
||||||
|
Tick newTime ->
|
||||||
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
Tock timeDiff ->
|
||||||
|
let
|
||||||
|
direction =
|
||||||
|
case model.direction of
|
||||||
|
Right ->
|
||||||
|
0
|
||||||
|
|
||||||
|
Up ->
|
||||||
|
90
|
||||||
|
|
||||||
|
Left ->
|
||||||
|
180
|
||||||
|
|
||||||
|
Down ->
|
||||||
|
270
|
||||||
|
|
||||||
|
distance =
|
||||||
|
distanceFromSpeed player_move_speed timeDiff
|
||||||
|
in
|
||||||
|
( { model | location = movePosition model.location direction distance }
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue