Thanks to Julio Marchi for this space in MSX All
 

Games Course


 

Guide the Balloon

Portuguese


1. Introduction
  The objective is to guide a balloon through a maze, until it touches the black cross located on the right top of the screen.
  "Guie o Balao" was published on a Brazilian magazine called "MSX Micro", number 4. This game is quite simple to understand the code and it is a good stuff for new programmers to study.

Requisites:

- MSX 1


2. Game structure
  The game was developed in Basic for MSX 1, using screen 0 for messages and screen 2 for the game.
  The ballon is drawn using an 8x8 sprite mode 0.
  There are four sub-routines used to draw each screen, which use DRAW instruction to draw the obstacles.
  Main loop uses STICK instruction to read the player's movements. Thus, it uses a bounding box to detect the type of area located under the balloon.
  Two colors guide the decision on the screen: if the balloon lies on a red area, the player looses one life. If the color is black, the player succeeded on crossing the screen. Otherwise, the game still on.


3. Commented code
  General initializations

  Used variables:
  • Q - defines: 0=keyboard, 1=joystick.
  • S - current screen.
  • LI - number of remaining lives.
  • SC - player's score.
  • HI - best score.
10 COLOR1,15,15:KEYOFF:HI=0:PLAY"O2G#F#BO3C#GD#C#F#D#O2BC#C#F#":
Q=0:GOSUB1300:OPEN"GRP:"AS#1:N$="M S X"
20 LI=3:S=1:CLS:SC=0
30 SCREEN 2,0


  The balloon

40 RESTORE:A$="":FORF=0TO7:READD$:A$=A$+CHR$(VAL("&B"+D$)):NEXTF:SPRITE$(0)=A$
50  DATA 00001000
60  DATA 00011100
70  DATA 00111110
80  DATA 00111110
90  DATA 00010100
100 DATA 00010100
110 DATA 00011100
120 DATA 00011100


  Sub-routines for drawing the screens

  The following sub-routine is responsible for drawing the common elements present on the four screens, as well as to manage the other screens sub-routines.
130 ' ** TELA **
140 TIME=0
150 CLS
160 GOSUB1910
170 ONSGOSUB380,530,680,830,1140
180 DRAW"BM230,11C1R10D10L10U10F10L10E10"
190 COLOR15:PRESET(10,3):PRINT#1,"VIDAS=";LI:PRESET(10,180):PRINT#1,"PONTOS=";SC
  The fist thing to do is reset the TIME variable, used to measure the time spent to complete the screen (line 140). The next step is to draw the borders.
1910 LINE(0,0)-(250,10),6,BF
1920 LINE(0,0)-(10,190),6,BF
1930 LINE(250,0)-(240,190),6,BF
1940 LINE(0,190)-(250,180),6,BF
1950 RETURN
  Line 170 establishes the calling order to the sub-routines according to the variable S (current screen).
  Line 180 draws the black target "X" on the right top of the screen, using the DRAW command. The code C1 means color 1 (black).
180 DRAW"BM230,11C1R10D10L10U10F10L10E10"
  Line 190 writes the game data on the screen such as lives (vidas) and score (pontos).


  Screen 1

380 ' ** TELA 1 **
390 A$="E10F10H5G5"
400 LINE(0,100)-(100,108),6,BF:LINE(111,100)-(250,108),6,BF
410 LINE(111,0)-(119,30),6,BF:LINE(111,43)-(119,100),6,BF
420 DRAW"BM84,70C6XA$;"
430 FORT=30TO200STEP20
440 DRAW"BM=T;,165C6XA$;"
450 NEXTT
460 DRAW"BM70,50C6XA$;"
470 DRAW"BM18,68C6XA$;"
480 DRAW"BM18,60C6XA$;"
490 DRAW"BM220,40C6XA$;":DRAW"BM122,50C6XA$;":DRAW"BM142,40C6XA$;"
500 DRAW"BM165,33C6XA$;"
510 X=150:Y=130
520 RETURN
  Line 390 defines A$ as the following obstacle, which will be drawn by the lines 420, 440 and 460-500:



  Interpreting the A$ data, we have the following cursor movements:
10↗, 10↘, 5↖, 5↙
  Each line mentioned before, which makes use of the A$ data, does the following:
BM X,Y - Defines the initial drawing coordinates.
Cn - Defines the color, which is 6 (red).
  Line 510 defines the initial position of the balloon.


  Screen 2

530 ' ** TELA 2 **
540 B$="R10H5G5D10R4U4R2D4R4U10D10L10"
550 FORT=30TO230STEP11
560 DRAW"BM=T;,50C6XB$;"
570 NEXTT
580 FORT=10TO220STEP11
590 DRAW"BM=T;,100XB$;"
600 NEXT
610 FORT=30TO230STEP11
620 DRAW"BM=T;,145XB$;"
630 NEXT
640 X=220:Y=160
650 DRAW"BM109,78XB$;":DRAW"BM130,70XB$;":DRAW"BM160,78XB$;"
660 DRAW"BM109,128XB$;":DRAW"BM130,120XB$;":DRAW"BM160,128XB$;"
670 RETURN
  The same as screen 1, but the obstacle is different and defined on B$:





  Screen 3

680 ' ** TELA 3 **
690 LINE(30,50)-(45,190),6,BF
700 DRAW"BM32,25C6XB$;"
710 LINE(60,0)-(75,147),6,BF
720 DRAW"BM62,165XB$;"
730 LINE(90,50)-(105,190),6,BF
740 DRAW"BM92,25XB$;"
750 LINE(120,0)-(135,147),6,BF
760 DRAW"BM122,165XB$;"
770 LINE(150,50)-(165,190),6,BF
780 DRAW"BM152,25XB$;"
790 LINE(200,0)-(230,100),6,BF
800 LINE(200,112)-(215,190),6,BF
810 X=15:Y=150
820 RETURN
  Draw the same obstacle used on screen 2.


  Screen 4

830 ' ** TELA 4 **
840 LINE(120,0)-(126,60),6,BF
850 X=200:Y=160
860 LINE(120,72)-(126,135),6,BF
870 LINE(120,147)-(126,190),6,BF
880 LINE(0,90)-(70,96),6,BF
890 LINE(80,90)-(250,95),6,BF
900 C$="U10R12U5R3D15L15"
910 DRAW"BM90,62XC$;"
920 DRAW"BM97,35XC$;"
930 DRAW"BM78,82XC$;"
940 DRAW"BM73,57XC$;"
950 DRAW"BM200,140XA$;"
960 DRAW"BM185,130XA$;"
970 DRAW"BM157,140XA$;"
980 DRAW"BM215,135XA$;"
990 DRAW"BM132,151XA$;"
1000 FORT=20TO115STEP11
1010 DRAW"BM=T;,156XB$;"
1020 NEXT
1030 DRAW"BM82,105XB$;"
1040 DRAW"BM60,105XB$;"
1050 DRAW"BM73,132XB$;"
1060 D$="U30R10D30L10U26BR3R3D3L3U3BD5R3D3L3U3BD5R3D3L3U3BD5R3D3L3U3BD5R3D3L3U3"
1070 DRAW"BM220,78XD$;"
1080 DRAW"BM205,46XD$;"
1090 DRAW"BM136,45XD$;"
1100 DRAW"BM136,87XD$;"
1110 DRAW"BM157,67XD$;"
1120 DRAW"BM188,82XD$;"
1130 RETURN
  The hardest screen, has two new obstacles defined on C$ and D$, respectively:

  and  


  Mission succeeded

1140 ' ** FIM DO JOGO **
1145 ' ** VOLTA P/ O INICIO **
1150 SCREEN 0:COLOR1
1160 CLS
1170 PRINT"     PARABENS, BALONISTA ! VOCE"
1180 PRINT
1190 PRINT"     COMPLETOU TODAS AS TELAS !"
1200 PRINT
1210 PRINT"     SEUS PONTOS FORAM :"
1220 PRINT
1230 PRINT"     ";SC
1240 PRINT
1250 PRINT"     PRESS. ESPACO OU TIRO"
1260 PRINT
1270 PRINT"     PARA A PROXIMA JORNADA."
1280 S=1:IFSTRIG(Q)THENSCREEN2,0:GOTO40
1290 GOTO 1280
  If the four screens are completed, a message is print on screen 0. The line 1280 waits for space bar or joystick button 1 to re-start the game.


  Main loop

  This routine is responsible for capturing the player's movements and check the balloon navigation on screen.
200 ' ** LOOP PRINCIPAL **
210 ST=STICK(Q):IFST=0THEN250
220 IFST=1THENY=Y-1:GOTO 260
230 IFST=3THENX=X+1:GOTO 260
240 IFST=7THENX=X-1:GOTO 260
250 Y=Y+1
260 PUTSPRITE0,(X,Y),3
270 IFPOINT(X,Y)=6THENGOTO 330
280 IFPOINT(X,Y)=1THENGOTO 360
290 X%=X+7:Y%=Y+8
300 IFPOINT(X%,Y%)=6THENGOTO 330
310 IFPOINT(X%,Y%)=1THENGOTO 360
320 GOTO210
  Lines 210-250 are responsible for reading commands from keyboard or joystick. Only the up (ST=1), right (ST=3) and left (ST=7) movements are interpreted. In this case, other movements or even no movement leads the program to the line 250, which introduces the ballon a falling movement.
  In order to improve the balloon guidance, we suggest that both diagonal up movements should be treated:
225 IFST=2THENY=Y-1:X=X+1:GOTO 260
245 IFST=8THENY=Y-1:X=X-1:GOTO 260
  Line 260 is responsible for drawing the balloon on screen.
  Lines 270-310 create a bounding box around the balloon in order to verify the screen area that the balloon is overlapping.
  In the next figure, the bounding box is defined by the area delimited by the crosses "+".
+
   1   
  111  
 11111 
 11111 
  1 1  
  1 1  
  111  
  111+
  Despites of defining a rectangle, the routine only checks the colors located exactly under the crosses. This test may be more effective, if we check all the four corners of the rectangle.
  Each test verify if the pixel is red, which means fail and a life lost:
330 LI=LI-1:IFLI<1THEN1710
340 PLAY"O4L5CCCD#DDCCCC":FORT=1TO100:NEXTT
350 GOTO130
  Or black, which means success:
360 IFTIME<3000THENSC=SC+3000-TIME
370 PLAY"O6DB":S=S+1:GOTO 130
  Line 360 reads the TIME variable to check the time spent to complete the screen. This value is used to calculate the score.
  The value 3000 for TIME corresponds to 30 seconds to complete each screen. This time is quite short to complete the screens 2-4, which generally leads to a null score.


  First screen

1300 COLOR1:CLS
1310 PRINT"           GUIE O BALAO":PRINT
1320 PRINT:PRINT:PRINT:PRINT:PRINT
1330 PRINT" "
1340 PRINT
1350 K$="     'D' P/ VER TELAS "
1360 X$="GUIE O BALAO ...........'C' P/ COMECAR.........'J' 
P/ JOYSTICK.........'I' P/ INSTRUCOES."
1370 COLOR1:J$=K$+X$
1380 FORT=1TOLEN(J$)
1390 LOCATE4,15:PRINTTAB(2);MID$(J$,T,18)
1400 LOCATE4,15:FORK=1TO100:NEXT
1410 A$=INKEY$:IFA$=""THENNEXT
1420 IFA$="C"THENRETURN
1430 IFA$="J"THENQ=1
1440 IFA$="I"THEN1470
1450 IFA$="D"THEN1960
1460 GOTO1380
  Lines 1350-1400 create a sliding text on screen, as seen on Brazilian Expert MSX manual [1] example for the command MID$.
  Lines 1410-1450 wait for a key to be pressed. Notice that the lower case letters are not treated here. To solve this bug, type:
1420 IFA$="C"ORA$="c"THENRETURN
1430 IFA$="J"ORA$="j"THENQ=1
1440 IFA$="I"ORA$="i"THEN1470
1450 IFA$="D"ORA$="d"THEN1960


  Instructions

1470 CLS
1480 PRINT"        GUIE O BALAO
1490 PRINT
1500 PRINT"   SEU BALAO ESTA FURADO E VOCE"
1510 PRINT"   PRECISA VIAJAR ATRAVES DE "
1520 PRINT"   QUATRO TELAS DE SUSPENSE"
1530 PRINT"   PARA CONTINUAR NO AR"
1540 PRINT
1550 PRINT"   PARA COMPLETAR A TELA VOCE"
1560 PRINT"   PRECISA POUSAR NA CRUZ"
1570 PRINT"   NEGRA NO TOPO DIREITO"
1580 PRINT"   DA TELA":PRINT
1590 PRINT"   TOCANDO EM QUALQUER COISA"
1600 PRINT"   RESULTA NA PERDA DE UMA "
1610 PRINT"   VIDA":PRINT
1620 PRINT"   CUIDADO ! O BALAO INICIA"
1630 PRINT"   CAINDO QUANDO A TELA"
1640 PRINT"   E' DESENHADA.":PRINT
1650 PRINT"   BOA SORTE!
1660 PRINT
1670 PRINT"   -PRESS. ESPACO-"
1680 A$=INKEY$:IFA$=""THEN1680
1690 IFA$<>" "THEN1680
1700 CLS:GOTO 1380


  Display all four screens

1960 SCREEN2,0:CLS:D=1
1970 ONDGOSUB380,530,680,830
1980 IFD=5THENFORT=1TO1000:NEXT:CLS:SCREEN0:GOTO1380
1990 GOSUB1910:D=D+1:FORT=1TO1000:NEXT:CLS:GOTO1970


  The end of the game

1710 COLOR1:SCREEN0
1720 CLS:PRINT"    VOCE BATEU MAS SEUS PONTOS SAO :"
1730 PRINT:PRINT
1740 PRINT"              ";SC
1750 IFSC>HITHENGOSUB1850
1760 PRINT:PRINT
1770 PRINT"        O RECORDE AGORA E:"
1780 PRINT:PRINT
1790 PRINT"            ";HI
1800 PRINT:PRINT"     POR:- ";N$
1810 PRINT:PRINT"   PRESS. 'C' PARA JOGAR NOVAMENTE"
1820 A$=INKEY$:IFA$=""THEN1820
1830 IFA$="C"ORA$="c"THENGOTO 20
1840 GOTO 1820
1850 PRINT"     UM NOVO RECORDE !":PRINT
1860 PRINT"DIGITE SEU NOME: ":PRINT
1870 LINEINPUTN$
1880 IFLEN(N$)>15THENPRINT:PRINT"MUITO LONGO":GOTO 1860
1890 HI=SC
1900 RETURN


4. MSX 2 Version

  By taking advantage of the MSX 2 graphic resources, I decided to improve the game and fix some bugs.

  Improvements:
  • Graphics from screen 2 to screen 5.
  • Sprites mode 2 for the balloon.
  • Background screen drawing.
  • Accept diagonal up moves.
  • Low letters bug on menu fixed.
  • Stores up to 5 records, which are saved on disk.
  Check out the details on the game's improvements here.


5. Download
  The game: Guie o Balao.
  MSX 2 version: Guie o Balao 2.



  References:

  [1]- Book Linguagem Basic, 5th. Edition, P. Piazzi, Editora Aleph, 1987.


Marcelo Silveira
Systems and Computing Engineer
Expert in Image Processing and Artificial Intelligence
© MarMSX 1999-2025