-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.ref
More file actions
147 lines (116 loc) · 2.81 KB
/
Main.ref
File metadata and controls
147 lines (116 loc) · 2.81 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
*$FROM LibraryEx
$EXTERN Map;
*$FROM Raylib
$EXTERN
InitWindow,
WindowShouldClose,
CloseWindow,
BeginDrawing,
EndDrawing,
ClearBackground,
DrawText,
DrawRectangle,
GetFrameTime,
SetTargetFPS,
IsMouseButtonPressed,
GetMousePosition,
GetRandomValue;
WIDTH { = 800 }
HEIGHT { = 600 }
BOX_SIZE { = 50 }
RAYWHITE { = (245 245 245 255) }
NICEDARK { = (24 24 24 255) }
MOUSE_LEFT_BUTTON { = 0 }
MOUSE_RIGHT_BUTTON { = 1 }
MOUSE_MIDDLE_BUTTON { = 2 }
COLORS {
0 = (253 249 0 255);
1 = (0 228 48 255);
2 = (255 161 0 255);
3 = (102 191 255 255);
4 = (230 41 55 255);
5 = (190 33 55 255);
6 = (255 203 0 255);
7 = (0 158 47 255);
8 = (0 117 44 255);
9 = (255 109 194 255);
10 = (0 121 241 255);
11 = (112 31 126 255);
12 = (200 122 255 255);
13 = (135 60 190 255);
14 = (0 82 172 255);
}
$ENTRY Go {
= <InitWindow 800 600 'Hello, Refal!'> :
= <SetTargetFPS 60> :
= <Loop
((50) (50) (1) (1) <GetRandomColor>)
((50) (150) (1) (1) <GetRandomColor>)
>;
}
GetRandomColor {
= <COLORS <GetRandomValue 0 14>>;
}
GetRandomVelocity {
= <GetRandomValue 0 1> <GetRandomValue 0 1> : {
0 0 = (1) (1);
0 1 = (1) ('-' 1);
1 0 = ('-' 1) (1);
1 1 = ('-' 1) ('-' 1);
};
}
Loop {
e.Boxes
= <WindowShouldClose> : {
0 = <Loop <DrawFrame e.Boxes>>;
1 = <CloseWindow>;
};
}
DrawFrame {
e.Boxes
= <ClearBackground <NICEDARK>> :
= <DrawText
'This example is written in Refal language and uses Raylib library'
40 40 20 <RAYWHITE>
> :
= <Map &DrawBox e.Boxes> : e.Boxes^
= <EndDrawing> :
= <IsMouseButtonPressed <MOUSE_LEFT_BUTTON>> : {
0 = e.Boxes;
1
= <GetMousePosition> : s.X s.Y
= ((s.X) (s.Y) <GetRandomVelocity> <GetRandomColor>) e.Boxes;
};
}
DrawBox {
((e.X) (e.Y) (e.VX) (e.VY) t.Color)
= <DrawRectangle e.X e.Y <BOX_SIZE> <BOX_SIZE> t.Color> :
= <Move (e.X) (e.Y) (e.VX) (e.VY) 4> : (e.X^) (e.Y^) (e.nVX) (e.nVY)
= <{ (e.nVX) (e.nVY) = t.Color; e._ e._ = <GetRandomColor> } (e.VX) (e.VY)> : t.Color^
= ((e.X) (e.Y) (e.nVX) (e.nVY) t.Color);
}
CollisionX {
(e.X) (e.VX), <Compare (e.X) 0> : '-'
= (0) (<Neg e.VX>);
(e.X) (e.VX), <Compare (e.X) <Sub <WIDTH> <BOX_SIZE>>> : '+'
= (<Sub <WIDTH> <BOX_SIZE>>) (<Neg e.VX>);
(e.X) (e.VX) = (e.X) (e.VX);
}
CollisionY {
(e.Y) (e.VY), <Compare (e.Y) 0> : '-'
= (0) (<Neg e.VY>);
(e.Y) (e.VY), <Compare (e.Y) <Sub <HEIGHT> <BOX_SIZE>>> : '+'
= (<Sub <HEIGHT> <BOX_SIZE>>) (<Neg e.VY>);
(e.Y) (e.VY) = (e.Y) (e.VY);
}
Move {
(e.X) (e.Y) (e.VX) (e.VY) s.DT
= <Add (e.X) <Mul (e.VX) s.DT>> : e.X^
= <Add (e.Y) <Mul (e.VY) s.DT>> : e.Y^
= <CollisionX (e.X) (e.VX)> : (e.X^) (e.VX^)
= <CollisionY (e.Y) (e.VY)> : (e.Y^) (e.VY^)
= (e.X) (e.Y) (e.VX) (e.VY);
}
Neg {
e.X = <Sub 0 e.X>;
}