1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
}
|