Added auto wrapping of location.

This commit is contained in:
John Shaver 2017-06-29 10:50:54 -07:00
parent d07e68a16f
commit 292ee99eab
5 changed files with 26 additions and 10 deletions

View file

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

View file

@ -9,9 +9,9 @@ character_radius =
20
playAreaSize =
play_area_size =
( 800, 880 )
backgroundColor =
background_color =
"black"

View file

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

View file

@ -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!" ]

View file

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