Skip to content
Permalink
Browse files

Initialize the ball with a random vertSpeed

  • Loading branch information...
magopian committed Aug 8, 2019
1 parent 6abb97e commit 24d6be334b72f898cd590cd1250c38d34e5974e8
Showing with 21 additions and 7 deletions.
  1. +21 −7 src/Main.elm
@@ -85,9 +85,28 @@ type alias Flags =
Float


randomVertSpeed : Random.Seed -> ( Int, Random.Seed )
randomVertSpeed seed =
Random.step (Random.int -10 10) seed


init : Flags -> ( Model, Cmd Msg )
init seed =
( { ball = initBall
let
initialSeed =
-- A number between 0 and 100
seed
|> (*) 100
|> round
|> Random.initialSeed

( initialVertSpeed, newSeed ) =
randomVertSpeed initialSeed

initialBall =
{ initBall | vertSpeed = initialVertSpeed }
in
( { ball = initialBall
, rightPaddle = RightPaddle <| initPaddle 480
, leftPaddle = LeftPaddle <| initPaddle 10
, rightPaddleMovement = NotMoving
@@ -97,12 +116,7 @@ init seed =
{ rightPlayerScore = 0
, leftPlayerScore = 0
}
, seed =
-- A number between 0 and 100
seed
|> (*) 100
|> round
|> Random.initialSeed
, seed = newSeed
}
, Cmd.none
)

0 comments on commit 24d6be3

Please sign in to comment.
You can’t perform that action at this time.