-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.lcpp
More file actions
88 lines (87 loc) · 1.72 KB
/
game.lcpp
File metadata and controls
88 lines (87 loc) · 1.72 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
pong = {window}>(
{random} = window.Math,
screenSize={x<=400,y<=600},
center = [screenSize.x/2,screenSize.y/2],
paddlePos = 0.9 * center.0,
ballSize = 5,
paddleSize = 5,
state = newState 0,
newState = gameNumber>(
playerPos<=[
[paddlePos center.1]
[-paddlePos center.1]
],
num <= gameNumber,
score<=[0 0],
ball <= [center [1 1]],
),
update_ball = {playerPos ball score}>(
p = playerPos,
b = ball,
s = score,
ball.1 = bounceOffpaddles=>(
x = b.0.0,
p.reduce [[velocity p i]>(p.0 - x).abs.< paddleSize velocity [[1,-1].[i],velocity.y] , ball.1]
),
checkScore=>(
x = b.0.0,
{score scoredPoint} = (
x.<ballSize,
({score scoredPoint<=\\$1},score.0=++score.0),
x.>(screenSize.x - ballSize)
({score scoredPoint<=\\$1},score.1=++score.1)
{score scoredPoint<= 0}
),
state = newState (++state.num),
state = (state,state.score = score),
(scoredPoint \state<$2,a>a)a>a,
),
bounceOffWalls=>(
x = b.0.0,
{score scoredPoint} = (
x.<0,
({score scoredPoint<=\\$1},score.0=++score.0),
x.>screenSize.x
({score scoredPoint<=\\$1},score.1=++score.1)
{score scoredPoint<= 0}
),
state = newState,
state = (state,state.score = score),
(scoredPoint \state<$2,a>a)a>a,
),
),
),
Z = f>(a>a a)(x>f(λ a x)),
Monad = monadFoo>Z (//Monad:<value>λZ()
//monadFoo:λλvalue
self>//:Monad
x>//:value
foo>(//:λvalue
foo == ()
x
self λ$0,monadFoo foo x
)
)λ$0,
maybe = Monad f>x>x == () () (f x),
Y = f>(a>a a)(x>f(x x)),
(
(
(
(
(
(
(
x>(is0 x 1,f,--x)
f = (Lazy\x x)
)
)
x = x>f(x x)
)
(Lazy\--x)
)
x = 3
)
f = Lazy \x x x = x>f(x x)
)
f = f>x>(is0 x 1,f,--x)
)