Added simple movement to model updates.

This commit is contained in:
John Shaver 2017-06-27 15:25:06 -07:00
parent 84170a58b6
commit 9b2a65f64d
3 changed files with 57 additions and 4 deletions

View file

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

View file

@ -1,8 +1,8 @@
module GLOBALS exposing (..) module GLOBALS exposing (..)
move_speed = player_move_speed =
60 120
character_radius = character_radius =

View file

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