DONKEY.BAS, a video game written in 1981, was developed by Microsoft co-founder Bill Gates and early employee Neil Konzen.
We can experience the game here and view the source code of the game (only 130+ lines).
I can guess most of the code means, except for an integer array variable called B%
,
...
1510 DIM B%(300)
1520 FOR I=2 TO 300:B%(I)=-16384+192:NEXT
1530 B%(0)=2:B%(1)=193
...
1760 IF Y AND 3 THEN PUT (140,6),B%
...
It looks like Bill Gates and Neil Konzen filled this array with some magic numbers and drew it as an image at coordinates (140, 6), when the two lowest bits of variable Y
(donkey's y-coordinate) are not both 0. 140 is the x-position of dotted line in the middle of the road, I think.
I'm curious about the code for the B%
variable, what do those magic numbers mean, and why the binary pattern of the first 2 elements (2 and 193) is different from the next 298 elements?
IF Y AND 3 THEN PUT (140,6),B%
seems to make some kind of transformation on the dotted line in the middle of the road, generating animation and making the player feel that the car is moving forward.
[0] = 0000 0000 0000 0010
[1] = 0000 0000 1100 0001
[2] = 1100 0000 1100 0000