-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbatball.forth
301 lines (229 loc) · 3.76 KB
/
batball.forth
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// batball
// -------------------------------------------------------
// Terminal Brick Out.
// a dumb game on the terminal using ansi escape codes.
//
8 STRING coff
27 , ' [?25l',
8 STRING con
27 , ' [?25h',
8 STRING cln
27 , ' [2K',
: curoff coff $. ;
: curon con $. ;
: clrln cln $. ;
4 STRING ballone
0xE2 , 0x97 , 0xAF , 0 ,
4 STRING balltwo
0xE2 , 0x8D , 0x9F , 0 ,
4 STRING ballthree
0xE2 , 0x8A , 0x9B , 0 ,
4 STRING ballfour
0xE2 , 0x8A , 0x9A , 0 ,
4 STRING ballfive
0xE2 , 0x9A , 0xAB , 0 ,
4 STRING ballsix
0xE2 , 0x9A , 0xAA , 0 ,
4 STRING badfall1
0xE2 , 0x98 , 0xA2 , 0 ,
4 STRING badfall2
0xE2 , 0x98 , 0xA3 , 0 ,
4 STRING badfall3
0xE2 , 0x98 , 0xA0 , 0 ,
4 STRING goodf01
0xE2 , 0x98 , 0xAE , 0 ,
4 STRING goodf02
0xE2 , 0x9A , 0x9B , 0 ,
4 STRING goodf03
0xE2 , 0x9A , 0x9A , 0 ,
4 STRING goodf04
0xE2 , 0x9A , 0x98 , 0 ,
24 STRING smallbat
0xE2 , 0x97 , 0x96 ,
0xE2 , 0x96 , 0xA0 ,
0xE2 , 0x96 , 0xA0 ,
0xE2 , 0x96 , 0xA0 ,
0xE2 , 0x97 , 0x97 ,
0 ,
24 STRING widebat
0xE2 , 0x97 , 0x96 ,
0xE2 , 0x96 , 0xA0 ,
0xE2 , 0x96 , 0xA0 ,
0xE2 , 0x96 , 0xA0 ,
0xE2 , 0x96 , 0xA0 ,
0xE2 , 0x96 , 0xA0 ,
0xE2 , 0x97 , 0x97 ,
0 ,
: makesixl
2 PARAMS
240 a C! 159 a 1+ C! 172 a 2+ C! b a 3 + C!
;
0 VARIABLE sixls 256 ALLOT
: makesxls
128 a!
512 0 DO
a sixls I + makesixl
a++
8 +LOOP
;
3 SHIFTSL 8*
: .sixl ( n )
8* sixls + $.
;
// so we can pick one
: .sixls 64 0 DO I .sixl '=' EMIT I . SPACE LOOP ;
: .brick
56 48 48 48 52
5 TIMESDO .sixl
;
: .bricks
9 0 DO
.brick SPACE SPACE
LOOP
;
: .wall
6 10 AT
TCOL.cyan FCOL .bricks
8 10 AT
TCOL.magenta FCOL .bricks
10 10 AT
TCOL.yellow FCOL .bricks
12 10 AT
TCOL.green FCOL .bricks
14 10 AT
TCOL.blue FCOL .bricks
16 10 AT
TCOL.red FCOL .bricks
;
ALIAS x a
ALIAS y b
2 VALUE batminx
80 VALUE batmax
40 VALUE batx
30 VALUE baty
0 VALUE batxdir
TCOL.green VALUE batclr
43 VALUE ballx
29 VALUE bally
FALSE VALUE ballfree
TCOL.red VALUE ballclr
0 VALUE ballxdir
-1 VALUE ballydir
0 VALUE movetime
0 VALUE keypresses
: atbat ( x y c --- )
3 PARAMS
c FCOL
x y AT clrln
x y AT smallbat $.
;
: atball ( x y c --- )
3 PARAMS
c FCOL
ballfree 0= IF x y AT clrln THEN
x y AT ballone $.
;
: batsball
FALSE TO ballfree
batx 2 + TO ballx
baty 1- TO bally
;
: showbat ( )
batclr batx baty atbat ;
: showball ( )
ballclr ballx bally atball ;
: ballmove
bally ballx AT 32 EMIT
ballxdir +TO ballx
ballydir +TO bally
bally 1 < IF
batsball
THEN
showball
;
: batmove
batxdir +TO batx
batx batmax > IF -1 TO batxdir THEN
batx batminx < IF 1 TO batxdir THEN
showbat
ballfree 0= IF
batx 2 + TO ballx
showball
THEN
;
// move bat when keys pressed.
//
: batballxdir ( n -- )
ballfree 0= IF
TO ballxdir
ELSE DROP THEN
;
: batleft
batx batminx > IF
batxdir 1 = IF
0 TO batxdir
0 batballxdir
ELSE
-1 TO batxdir
-1 batballxdir
THEN
THEN
;
: batright
batx batmax < IF
batxdir -1 = IF
0 TO batxdir
0 batballxdir
ELSE
1 TO batxdir
1 batballxdir
THEN
THEN
;
: batkeys
batsball
TICKS TO movetime
NOECHO curoff
showbat showball
BEGIN
KEY? IF
1 +TO keypresses
ballfree 0= keypresses 4 MOD 0= AND IF
0 TO ballxdir
THEN
KEY
DUP 'z' = IF
batleft
THEN
DUP 'x' = IF
batright
THEN
DUP 32 = IF
TRUE TO ballfree
THEN
DUP 'q' = IF
curon DROP
TCOL.reset FCOL
RETERM
EXIT
THEN
THEN // key?
FLUSH
// only update bat and ball at set rate
TICKS movetime - 984000 > IF
.wall
TICKS TO movetime
ballfree IF ballmove THEN
batmove
THEN
1 MS // do not use 100% CPU
AGAIN
;
UNALIAS x
UNALIAS y
: START
PAGE
makesxls
.wall
batkeys
;