Thanks to Julio Marchi for this space in MSX All
 

Games Course


 
Guide the Balloon - MSX 2

Portuguese


Changes description
  General initializations

10 MAXFILES=2:OPEN"GRP:"AS#1:N$="M S X":KEYOFF:GOSUB2100
15 SCREEN0:WIDTH40:COLOR1,15,15:PLAY"V15O2G#F#BO3C#GD#C#F#D#O2BC#C#F#":Q=0:GOSUB1300
20 LI=5:S=1:CLS:SC=0:DR=0
30 SCREEN 5,0
  The declaration "MAXFILES=2" is necessary for the OPEN #2 command to open the game records file, once the #1 is already used by the graphic mode writing.
  The line 10 is executed once. From here, we call the sub-routine that reads the five game records from a file and store the data in two arrays.
2100 ' Le recordes do arquivo
2110 OPEN"balao.dat"FOR INPUT AS #2
2120 DIM HI(5) : DIM NO$(5)
2130 FOR I=1 TO 5
2140 INPUT #2, NO$(I)
2150 INPUT #2, A$: HI(I)=VAL(A$)
2160 NEXT
2170 CLOSE 2
  Line 15 was introduced to allow the game return to the main menu after game over.
  The variable DR is used as a flag to indicate if the current screen has already been drawn on page 1.
  The MSX screen mode is changed to 5, which introduces remarkable changes from screen 2.


  The balloon

40 RESTORE:A$="":FORF=0TO7:READD$:A$=A$+CHR$(VAL("&B"+D$)):NEXTF:SPRITE$(0)=A$
45 COLOR SPRITE$(0)=CHR$(4)+CHR$(5)+CHR$(4)+CHR$(5)+CHR$(14)+CHR$(14)+CHR$(4)+CHR$(4)
50  DATA 00011000
60  DATA 00111100
70  DATA 01111110
80  DATA 01111110
90  DATA 00100100
100 DATA 00100100
110 DATA 00111100
120 DATA 00111100
  Line 45 creates a color pattern for each sprite line (sprites mode 2). The CHR$(n) value indicates the color of the line.
  The balloon was enlarged.


  Sub-routines for drawing the screens

130 ' ** TELA **
140 TIME=0:CLS
144 PUT SPRITE0,(256,212)
145 IF DR=1 THEN 185 ELSE IF S=5 THEN 170
146 CLS:LINE(95,85)-(153,103),4,BF:LINE(95,85)-(153,103),6,B
147 COLOR15,4:PRESET(100,90):PRINT#1,USING"Tela #";S:COLOR1,15
150 SET PAGE 0,1:CLS
160 GOSUB1910
170 ONSGOSUB380,530,680,830,1140
180 DRAW"BM230,11C1R10D10L10U10F10L10E10"
185 SET PAGE 0,0:GOSUB 2000
190 COLOR15,6:PSET(10,2):PRINT#1,"VIDAS=";LI:PSET(10,182):
PRINT#1,"PONTOS=";SC:COLOR,15:DR=1:GOSUB 2050
  Line 144 hides the balloon while the screen is drawn.
  If the current screen has already been created, only copies it from page 1 to 0 (jumps to the line 185). Else, clear page 0 and writes a message "Tela n" while the screen is being drawing in background, on page 1.
  The command SET PAGE 0,1 sets the visible page to 0 and the use page to 1 (where all the actions are directed to).
  Once the screen drawing is over, the page copy sub-routine is called (GOSUB 2000).
2000 ' Animacao de entrada da tela
2010 FOR Y1=0 TO 7:FOR Y2=0 TO 211 STEP 8
2020 COPY(0,Y1+Y2)-(255,Y1+Y2),1 TO (0,Y1+Y2),0
2030 NEXT Y2,Y1
2040 RETURN


  General changes on screen sub-routines

  The scenario background color was changed to blue on all screens.
  First, the interest area is delimited. Then, we paint the screen with blue 7, restricted to the red 6 color.
LINE(10,10)-(240,180),6,B:PAINT(15,175),7,6
  On screen 1, we close the obstacle polygon. This allow us to paint the object inside.
  Besides painting each obstacle from inside, we painted the area that the obstacles will be drawn with a filled rectangle using the desired color. So, when painting the screen with blue color, the closed polygons will not be affected, but only the scenario.

 
  The initial balloon coordinates where removed from the screens sub-routines and placed on a new sub-routine together.
2050 ' Define coordenadas iniciais do balao
2060 IF S=1 THEN X=150:Y=130:RETURN
2070 IF S=2 THEN X=220:Y=160:RETURN
2080 IF S=3 THEN X=15:Y=150:RETURN
2090 IF S=4 THEN X=200:Y=160:RETURN
2095 RETURN


  Main loop

200 ' ** LOOP PRINCIPAL **
210 ST=STICK(Q):IFST=0THEN250
220 IFST=1THENY=Y-1:GOTO 260
225 IFST=2THENY=Y-1:X=X+1:GOTO 260
230 IFST=3THENX=X+1:GOTO 260
240 IFST=7THENX=X-1:GOTO 260
245 IFST=8THENY=Y-1:X=X-1:GOTO 260
250 Y=Y+1
260 PUTSPRITE0,(X,Y)
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
  Two new movements were introduced: up-right and up-left.

  Fail sub-routine:
330 LI=LI-1
340 PLAY"O4L5CCCD#DDCCCC"
344 FOR F=1 TO 5
345 FOR C=1 TO 7 STEP .5:COLOR=(7,C,0,0):NEXT C
346 FOR C=7 TO 1 STEP -.5:COLOR=(7,C,0,0):NEXT C,F
350 COLOR=NEW:IF LI<1 THEN 1710 ELSE 130
  When the balloon hits, the blue background is replaced by a palette effect, which ranges from dark-red to light-red and vice-versa.

  Success sub-routine:
360 IFTIME<7200THENSC=SC+INT((7200-TIME)/5)
370 PLAY"O6DB":S=S+1:DR=0:GOTO130
  Now the score is based on a time of 2 minutes instead of 30 seconds.


  First screen

1300 COLOR1:CLS
1310 PRINT"GUIE O BALAO - MSX 2":PRINT
1320 PRINT"Pressione:":PRINT
1330 PRINT"D - para ver telas do jogo"
1340 PRINT"C - para comecar"
1350 PRINT"J - para joystick"
1360 PRINT"I - para instrucoes"
1370 PRINT"R - para ver os recordes"
1410 A$=INKEY$:IFA$=""THEN1410
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
1455 IFA$="R"ORA$="r"THENGOSUB2210:GOTO1300
1460 GOTO1410
  Changes: all options on screen, accepts low case letters and ranking option (letter D).

  Writing the best 5 scores sub-routine :
2200 ' Imprime recordes
2210 SCREEN 0:COLOR1,15,15
2220 PRINT"Recordes:":PRINT
2230 FOR I=1 TO 5
2240 PRINT I;"- ";NO$(I);
2250 LOCATE 15 : PRINT HI(I)
2260 NEXT
2270 PRINT:PRINT"Tecle algo ...":A$=INPUT$(1)
2280 RETURN


  Instructions

1470 CLS
1480 PRINT"        GUIE O BALAO"
1490 PRINT
1500 PRINT"  Seu balao esta furado e voce precisa"
1510 PRINT"viajar atraves de quatro telas de"
1520 PRINT"suspense para continuar no ar."
1530 PRINT
1540 PRINT"  Para completar a tela, voce precisa
1550 PRINT"pousar na cruz negra no topo direito"
1560 PRINT"da tela."
1570 PRINT
1580 PRINT"  Tocando em qualquer coisa, resulta
1590 PRINT"na perda de uma vida."
1600 PRINT
1610 PRINT"  Cuidado! O balao inicia caindo quando
1620 PRINT"a tela acaba de ser desenhada."
1630 PRINT"
1640 PRINT"  Utilize as setas para guiar o balao.":PRINT
1650 PRINT"                           Boa Sorte!
1660 PRINT
1670 PRINT"   -PRESSIONE ESPACO-"
1680 A$=INKEY$:IFA$=""THEN1680
1690 IFA$<>" "THEN1680
1700 CLS:GOTO 1300


  Display all four screens

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


  The end of the game

1705 ' Rotina de fim de jogo (game over)
1710 COLOR1:SCREEN5
1720 CLS:PRESET(85,10):PRINT#1,"Fim de Jogo":LINE(85,20)-(168,20),6:
1730 PRESET(10,40):PRINT#1,"Seus pontos:";SC
1750 IF SC<=HI(5) THEN 1780
1760 PRESET(10,50):PRINT#1,"Novo Recorde !!"
1770 PRESET(10,70):PRINT#1,"Digite seu nome:":GOSUB 1845
1780 PRESET(10,100):PRINT#1,"Tecle algo para prosseguir ..."
1820 A$=INPUT$(1)
1830 GOTO 15
1840 ' Le nome do teclado
1845 COLOR1,15:NM$=""
1850 A$=INPUT$(1)
1855 A=ASC(A$):IF (A<65 OR A>90) AND (A<97 OR A>122) AND
(A<>32 AND A<>8 AND A<>13) THEN 1850
1860 C=LEN(NM$)
1865 IF A=13 AND C>1 THEN GOSUB2300:RETURN
1870 IF A=8 AND C>0 THEN NM$=LEFT$(NM$,LEN(NM$)-1):
LINE(146+8*(C-1),70)-(146+8*C,80),15,BF
1875 IF A>13 AND C<11 THEN NM$=NM$+A$
1880 PRESET(146,70):PRINT#1,NM$
1890 GOTO 1850
  This sub-routine was converted to screen 5, adding a new sub-routine to capture the player's name, if the player scores better than one of the top 5 records.
  It is expected from the keyboard: letters, space, backspace or enter.
  After filling the name, a sub-routine is called to place the current score on the records list (GOSUB 2300).

  Insert on records list sub-routine:
2300 ' Adiciona novo recorde e grava
2310 I=1
2320 IF SC<=HI(I) AND I<6 THEN I=I+1 : GOTO 2320
2330 IF I=6 THEN RETURN
2340 FOR F=4 TO I STEP -1
2350 NO$(F+1) = NO$(F) : HI(F+1)=HI(F)
2360 NEXT F
2370 NO$(I)=NM$ : HI(I)=SC
2380 OPEN"balao.dat"FOR OUTPUT AS#2
2390 FOR I=1 TO 5 : PRINT#2, NO$(I)+","+STR$(HI(I)) : NEXT
2395 CLOSE2:RETURN
  Instead of only one record, now there are five. To get here, the player must score at least more than the 5th place on the records list.
  Once the list is modified, the file is updated.


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