From 4521cdf1bb5725c9d497e5fb0c03943ad03a052f Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sun, 5 Oct 2014 23:10:18 +0200 Subject: Adding multiple moving points to catch --- src/CloudStep.elm | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/CloudStep.elm (limited to 'src/CloudStep.elm') 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 + } -- cgit v1.2.3