-
Notifications
You must be signed in to change notification settings - Fork 0
/
View.elm
51 lines (41 loc) · 1.36 KB
/
View.elm
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
module View where
import open Import
import open Model
display : (Int,Int) -> Game -> Element
display (windowWidth, windowHeight) {state,ball,playerL,playerR} =
container windowWidth windowHeight middle $
collage gameWidth gameHeight
[ boardf
, midlinef
, ballf ball
, paddlef playerL.paddle
, paddlef playerR.paddle
, scoresf playerL.score playerR.score
, infof state
]
midlinef : Form
midlinef = let midline = dashed black in
segment (0, -halfHeight) (0,halfHeight)
& traced { midline | width <- 5 }
boardf : Form
boardf = rect (toFloat gameWidth) (toFloat gameHeight)
& filled (rgb 60 100 60)
ballf : Ball -> Form
ballf ball = oval 15 15
& filled white
& move (ball.x, ball.y)
paddlef : Paddle -> Form
paddlef paddle = rect 10 40
& filled white
& move (paddle.x, paddle.y)
scoresf : Int -> Int -> Form
scoresf scoreL scoreR = textf (Text.height 50) (show scoreL ++ " " ++ show scoreR)
& move (0, toFloat gameHeight / 2 - 40)
infof : State -> Form
infof state =
if state == Play
then toForm (spacer 1 1)
else textf id "SPACE to start, WS and ↑↓ to move"
& move (0, 40 - toFloat gameHeight / 2)
textf : (Text -> Text) -> String -> Form
textf f = toForm . text . f . monospace . Text.color (rgb 60 200 160) . toText