Type in Game: PONG! (or, something close) Today’s type in game for HB Tiny Basic is a PONG! variant.  I cannot take full credit for this one, I found the original on a Japanese educational site devoted to teaching microcontroller programming, using Half-Byte’s Tiny Basic(!) (a variation of it, anyway) and for basic electronics.  The original was written in a variant of HB Tiny Basic and also used a 10k potentiometer for the controller.  I fixed a couple of bugs, got it to work with Nunchuk AND squeezed into a somewhat smaller memory footprint.

The game has a little bit of intelligence, it does a decent job of trying to guess where the ball will go, but, it is not perfect and it is possible to win the game.  There are some nice uses of the language, such as trying to include something like an OR statement when figuring out where the ball is going and takes advantage of an undocumented ‘feature’ of LINE: if you specify ‘2’ as the ‘color’ parameter, it simply inverses the pixels in the line.  This eliminates the need for multiple statements to draw and erase the paddles.  Quite clever.

Gameplay is super simple: the computer ALWAYS serves, the score goes to nine and stops. You are always on the right. You use the thumb stick up and down to control your paddle.

Weird things are likely to happen, it is not perfect and there’s no more room for improvement (challenge?)

Anyway, have fun!

10 CLS:A=0:B=0:W=48:H=32
30 BOX 0,0,W,H,1
40 U=H/2-3:V=U
50 LINE W-5,U,W-5,U+5,2:LINE 4,V,4,V+5,2
60 CURSOR 8,1:? A:IF A=9 STOP
70 CURSOR 3,1:? B:IF B=9 STOP
80 D=1:E=1:IF (U+V)&1 E=-1
90 X=5:Y=V+3:SET X,Y
100 C=50
110 IF C>0 C=C-1:GOTO 240
120 RESET X,Y
130 X=X+D
140 IF X=0 A=A+1:GOTO 60
150 IF X=W B=B+1:GOTO 60
160 IF X=W-6 IF Y>=U IF Y<=U+6 D=-D:TONE 440,100
170 IF X=5 IF Y>=V IF Y<=V+6 D=-D:TONE 440,100
180 Y=Y+E
190 IF Y=1 E=-E
200 IF Y=H-1 E=-E
210 IF X=W-6 IF Y=U IF E=1 E=-1
220 IF X=W-6 IF Y=U+5 IF E=-1 E=1
230 SET X,Y
240 LINE W-5,U,W-5,U+5,2
260 IF U<0 U=0
270 IF U>H-6 U=H-6
280 LINE W-5,U,W-5,U+5,2:LINE 4,V,4,V+5,2
300 IF D=1 GOTO 370
310 IF X>=28 GOTO 370
320 IF X=27 IF A<=B GOTO 370
330 IF E=1 Q=Y+X-4:IF Q>=H Q=32-H
340 IF E=0 Q=Y-X+4:IF Q<0 Q=-Q
350 IF Q<V+3 IF V>1 V=V-1
360 IF Q>V+3 IF V<25 V=V+1
370 LINE 4,V,4,V+5,2
380 RESET X,Y
400 DELAY 20:GOTO 110