From ce6775641639943a2aee00fa9c2d684aa434bc21 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sun, 15 Mar 2015 09:40:58 +0100 Subject: Moving boardSize to Game model --- src/Update/CloudUpdate.elm | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/Update/CloudUpdate.elm') diff --git a/src/Update/CloudUpdate.elm b/src/Update/CloudUpdate.elm index ce45beb..9863650 100644 --- a/src/Update/CloudUpdate.elm +++ b/src/Update/CloudUpdate.elm @@ -7,7 +7,7 @@ import Random (..) import Model.Vec2 (..) import Model.Player (..) -import Model.Board (boardSize, boardDiagonal) +import Model.Board (boardDiagonal) import Model.Point (..) import Model.Cloud (..) import Model.Config (..) @@ -15,16 +15,16 @@ import Model.Config (..) import Utils.Geometry (..) import Utils.Physics (getMove, getWaveMove) -cloudUpdate : Float -> Seed -> Player -> Cloud -> (Cloud, Int, Seed) -cloudUpdate time seed player {points, spawn, lastSpawn} = - let pointsToCatch = presentPoints time (points player.config) +cloudUpdate : Float -> Vec2 -> Seed -> Player -> Cloud -> (Cloud, Int, Seed) +cloudUpdate time boardSize seed player {points, spawn, lastSpawn} = + let pointsToCatch = presentPoints time boardSize (points player.config) presentAndNotCaughtPoints = List.filter (not << (playerPointCollision time player)) pointsToCatch addScore = (List.length pointsToCatch) - (List.length presentAndNotCaughtPoints) - presentOtherPoints = presentPoints time (points (otherConfig player.config)) + presentOtherPoints = presentPoints time boardSize (points (otherConfig player.config)) (newCloud, seed''') = if time > lastSpawn + spawn then - let (newPoint1, seed') = getNewPoint time seed - (newPoint2, seed'') = getNewPoint time seed' + let (newPoint1, seed') = getNewPoint time boardSize seed + (newPoint2, seed'') = getNewPoint time boardSize seed' in ( { points config = if(config == player.config) then @@ -49,16 +49,16 @@ cloudUpdate time seed player {points, spawn, lastSpawn} = ) in (newCloud, addScore, seed''') -presentPoints : Float -> List Point -> List Point -presentPoints time points = - let isPresent point = (distance (pointMove point time) originVec) < pointAwayDist +presentPoints : Float -> Vec2 -> List Point -> List Point +presentPoints time boardSize points = + let isPresent point = (distance (pointMove point time) originVec) < (pointAwayDist boardSize) in List.filter isPresent points -getNewPoint : Float -> Seed -> (Point, Seed) -getNewPoint time seed = - let (initPos, seed') = pointInitPos seed - (initDest, seed'') = pointDestination seed' +getNewPoint : Float -> Vec2 -> Seed -> (Point, Seed) +getNewPoint time boardSize seed = + let (initPos, seed') = pointInitPos boardSize seed + (initDest, seed'') = pointDestination boardSize seed' in ( { initTime = time , initPos = initPos , initDest = initDest @@ -70,17 +70,17 @@ getNewPoint time seed = , seed'' ) -pointInitPos : Seed -> (Vec2, Seed) -pointInitPos seed = +pointInitPos : Vec2 -> Seed -> (Vec2, Seed) +pointInitPos boardSize seed = let (rand, seed') = generate floatGen seed angle = rand * (degrees 360) - dist = boardDiagonal * 3 / 5 + dist = (boardDiagonal boardSize) * 3 / 5 in (polarToCartesian angle dist, seed') -pointDestination : Seed -> (Vec2, Seed) -pointDestination seed = +pointDestination : Vec2 -> Seed -> (Vec2, Seed) +pointDestination boardSize seed = let ([r1, r2, r3, r4], seed') = generateMany 4 floatGen seed - in ( randomBoardPosition (r1, r2) (r3, r4) + in ( randomBoardPosition boardSize (r1, r2) (r3, r4) , seed' ) @@ -97,8 +97,8 @@ generateMany count gen seed = floatGen : Generator Float floatGen = float 0 1 -randomBoardPosition : (Float, Float) -> (Float, Float) -> Vec2 -randomBoardPosition (randomX, randomY) (percentX, percentY) = +randomBoardPosition : Vec2 -> (Float, Float) -> (Float, Float) -> Vec2 +randomBoardPosition boardSize (randomX, randomY) (percentX, percentY) = let width = boardSize.x * percentX height = boardSize.y * percentY in { x = width * randomX - width / 2 -- cgit v1.2.3