diff --git a/src/AnimationHelpers.elm b/src/AnimationHelpers.elm index c5ac096..5695983 100644 --- a/src/AnimationHelpers.elm +++ b/src/AnimationHelpers.elm @@ -31,6 +31,18 @@ movePosition position direction distance = ( x, y ) +wrapLocation : Point -> Point -> Point +wrapLocation maxLocation location = + let + ( x, y ) = + location + + ( maxX, maxY ) = + maxLocation + in + ( (fmod x maxX), (fmod y maxY) ) + + distanceFromSpeed : Float -> Float -> Float distanceFromSpeed pixPerSec millis = pixPerSec * millis / 1000 diff --git a/src/GLOBALS.elm b/src/GLOBALS.elm index 0083fac..82b0268 100644 --- a/src/GLOBALS.elm +++ b/src/GLOBALS.elm @@ -9,9 +9,9 @@ character_radius = 20 -playAreaSize = +play_area_size = ( 800, 880 ) -backgroundColor = +background_color = "black" diff --git a/src/Updates/Player.elm b/src/Updates/Player.elm index f9cdc5a..631f892 100644 --- a/src/Updates/Player.elm +++ b/src/Updates/Player.elm @@ -7,8 +7,8 @@ import Types , Msg(Tick, Tock, Press) , KeyAction(MoveUp, MoveDown, MoveLeft, MoveRight, NoKeyAction) ) -import AnimationHelpers exposing (movePosition, distanceFromSpeed) -import GLOBALS exposing (player_move_speed) +import AnimationHelpers exposing (movePosition, distanceFromSpeed, wrapLocation) +import GLOBALS exposing (player_move_speed, play_area_size) update : Msg -> PlayerModel -> ( PlayerModel, Cmd Msg ) @@ -36,8 +36,12 @@ update msg model = distance = distanceFromSpeed player_move_speed timeDiff + + newLocation = + movePosition model.location direction distance + |> wrapLocation play_area_size in - ( { model | location = movePosition model.location direction distance } + ( { model | location = newLocation } , Cmd.none ) else diff --git a/src/Views/Body.elm b/src/Views/Body.elm index ac8d4da..d6c66d7 100644 --- a/src/Views/Body.elm +++ b/src/Views/Body.elm @@ -1,7 +1,7 @@ module Views.Body exposing (..) import Html exposing (Html, h1, div, text) -import GLOBALS exposing (playAreaSize) +import GLOBALS exposing (play_area_size) import Types exposing (Model, Range) import Views.PlayArea @@ -10,7 +10,7 @@ view : Model -> Html msg view model = let ( width, height ) = - playAreaSize + play_area_size in div [] [ h1 [] [ text "ElmMan!" ] diff --git a/src/Views/Map.elm b/src/Views/Map.elm index 9347e66..7161715 100644 --- a/src/Views/Map.elm +++ b/src/Views/Map.elm @@ -1,6 +1,6 @@ module Views.Map exposing (..) -import GLOBALS exposing (backgroundColor, playAreaSize) +import GLOBALS exposing (background_color, play_area_size) import Svg exposing (Svg, g, path, rect) import Svg.Attributes exposing (d, fill, x, y, width, height) import Svg.Path exposing (pathToString, lineTo, subpath, startAt, closed) @@ -10,11 +10,11 @@ render : Svg msg render = let ( areaWidth, areaHeight ) = - playAreaSize + play_area_size in g [] [ rect - [ fill backgroundColor + [ fill background_color , width (toString areaWidth) , height (toString areaHeight) , x (toString 0)