module CloudStep where import Vec2 (..) import Geometry (..) import Player (..) import Board (boardSize, boardDiagonal) import Point (..) import RandomValues (..) import Physics (getMove) import Cloud (..) import Config (..) cloudStep : Float -> RandomValues -> Player -> Cloud -> (Cloud, Int) cloudStep time randomValues player {points, spawn, lastSpawn} = let pointsToCatch = presentPoints time (points player.config) presentAndNotCaughtPoints = filter (not . (playerPointCollision time player)) pointsToCatch addScore = (length pointsToCatch) - (length presentAndNotCaughtPoints) presentOtherPoints = presentPoints time (points (otherConfig player.config)) newCloud = if time > lastSpawn + spawn then let newPoint1 = newPoint time randomValues.point1 newPoint2 = newPoint time randomValues.point2 in { points config = if(config == player.config) then newPoint1 :: presentAndNotCaughtPoints else newPoint2 :: presentOtherPoints , spawn = spawn - sqrt(spawn) / 50 , lastSpawn = time } else { points config = if(config == player.config) then presentAndNotCaughtPoints else presentOtherPoints , 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 }