diff options
Diffstat (limited to 'src/CloudStep.elm')
-rw-r--r-- | src/CloudStep.elm | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/CloudStep.elm b/src/CloudStep.elm new file mode 100644 index 0000000..e33d573 --- /dev/null +++ b/src/CloudStep.elm @@ -0,0 +1,68 @@ +module CloudStep where + +import Vec2 (..) +import Geometry (..) +import Player (..) +import Board (boardSize, boardDiagonal) +import Point (..) +import RandomValues (..) +import Physics (getMove) +import Cloud (..) + +cloudStep : Float -> RandomValues -> Player -> Cloud -> (Cloud, Int) +cloudStep time {greenPoint, redPoint} player {greenPoints, redPoints, spawn, lastSpawn} = + let insideGreenPoints = presentPoints time greenPoints + insideNotCaughtGreenPoints = filter (not . (playerPointCollision time player)) insideGreenPoints + addScore = (length insideGreenPoints) - (length insideNotCaughtGreenPoints) + presentRedPoints = presentPoints time redPoints + newCloud = + if time > lastSpawn + spawn then + let newGreenPoint = newPoint time greenPoint + newRedPoint = newPoint time redPoint + in + { greenPoints = newGreenPoint :: insideNotCaughtGreenPoints + , redPoints = newRedPoint :: presentRedPoints + , spawn = spawn - sqrt(spawn) / 50 + , lastSpawn = time + } + else + { greenPoints = insideNotCaughtGreenPoints + , redPoints = presentRedPoints + , spawn = spawn + , lastSpawn = lastSpawn + } + in (newCloud, addScore) + +presentPoints : Float -> [Point] -> [Point] +presentPoints time points = + let isPresent point = (distance (pointMove point time) originVec) < pointAwayDist + in filter isPresent points + +newPoint : Float -> PointRandomValues -> Point +newPoint time pointRandomValues = + { initTime = time + , initPos = pointInitPos pointRandomValues.angle + , initDest = pointDestination pointRandomValues.x pointRandomValues.y + , move initTime initPos initDest time = + let delta = time - initTime + move = getMove (pointSpeed delta) (initDest `sub` initPos) + in initPos `add` move + } + +pointInitPos : Float -> Vec2 +pointInitPos randomAngle = + let angle = randomAngle * (degrees 360) + dist = boardDiagonal * 3 / 5 + in polarToCartesian angle dist + +pointDestination : Float -> Float -> Vec2 +pointDestination randomX randomY = + randomBoardPosition (randomX, randomY) (1, 1) + +randomBoardPosition : (Float, Float) -> (Float, Float) -> Vec2 +randomBoardPosition (randomX, randomY) (percentX, percentY) = + let width = boardSize.x * percentX + height = boardSize.y * percentY + in { x = width * randomX - width / 2 + , y = height * randomY - height / 2 + } |