rem ---- Sample Program 2 ---- set romsize 4k rem Declare Variables b{0}=0 : rem game over flag l=0 : rem hiscore01 r=0 : rem hiscore02 z=0 : rem hiscore03 dim sc1 = score dim sc2 = score+1 dim sc3 = score+2 dim _Temp_Score01 = i dim _Temp_Score02 = j dim _Temp_Score03 = k dim _High_Score01 = l dim _High_Score02 = r dim _High_Score03 = z __inicio a=0 : rem alien sprite contador rem b game over flag c=50 : rem player0x position d=80 : rem player0y position e=0 : rem counter for firing gun f=0 : rem alien delay movement. g=0 : rem flag para distancia entre player y alien. h=0 : rem contador velocidad scroll. i=0 : rem tempscore01 j=0 : rem tempscore02 k=0 : rem tempscore03 rem l : rem para highscore m=3 : rem vidas jugador n=0 : rem posicion bala segun leftswitch o=0 : rem contador bonus p=0 : rem contador bonus rem q : rem score background color rem r : rem para highscore s=0 : rem disparo activo flag rem t=0 : rem contador for u=20 : rem player1 alien x position v=24 : rem player1 alien y position w=15 : rem numero de aliens x=88 : rem color base fases y=3 : rem fase. influye velocidad aliens. rem z=0 : rem para highscore b{1}=0 : rem disparo alien activo flag. antes asignado z score=0 dim fire=e dim p0y=d dim p0x=c dim p1x=u dim p1y=v dim enemigos=w dim fase=y dim vidas=m dim _Bit0_Alien_Sprite = a dim _Bit1_Alien_Disparo = a _Bit0_Alien_Sprite{0} = 0 _Bit1_Alien_Disparo{1} = 0 missile0x = 10 : rem default missile x position missile0y = 10 : rem default missile y position missile0height = 4 : rem missile height dim mx = missile0x : rem posicionador movimiento disparo x. dim my = missile0y : rem posicionador movimiento disparo y. missile1x = 10 : rem default missile x position missile1y = 10 : rem default missile y position missile1height = 4 : rem missile height dim mex = missile1x : rem posicionador movimiento disparo x. dim mey = missile1y : rem posicionador movimiento disparo y. rem the playfield command draws the X's on the screen. Must use capital X, must be 32x11. playfield: ................................ ................................ ................................ ................................ XXXX.XXXXXXXXX....XXXXXXXXX.XXXX XXXX.XXXXXXXXX....XXXXXXXXX.XXXX ................................ ................................ ................................ ................................ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end rem definir ball ballx = 200 bally = 200 ballheight = 4 : rem * Ball 4 pixels high. CTRLPF = $21 : rem * Ball 4 pixels wide. rem set score background color dim scback = q scback = $2A main rem COLUP0= sets the color of the player 0 sprite. Valid range is 0-254 COLUP0=28 COLUP1=56 rem You need to set a color for the playfield COLUPF=x rem Change the background color with COLUBK COLUBK=00 scorecolor=$0E rem Here is where you define the shape of the player sprite. It's limited to rem 8 pixels wide, but you can make it as tall/long as you want. rem the 'player0' must be indented, the 'end' must NOT be indented. rem player0 nave rem player1 alien player0: %11100111 %01111110 %00111100 %00011000 %00011000 %00000000 %00000000 %00000000 end player1: %00000000 %00000000 %00000000 %00011000 %00011000 %00111100 %01111110 %11100111 end rem Put the player on the screen at X position 50. Valid Range is 1 to 159 player0x=p0x rem Put the player on the screen at Y position 50. Valid Range is 1 to ~90 player0y=p0y if !b{0} then goto __gameover : rem comprueba flag de gameover rem Disparo de la nave if joy0fire && s=0 then mx=p0x+4+n:my=p0y-6:s=1 : rem jugador aprieta boton de disparo. if s=1 then my=my-2 if my<10 || missile0y<10 then goto __clearshot : rem resetear disparo si sale del rango. if collision(playfield,missile0) then score=score+1: goto __clearshot : rem resetear disparo si sale colisiona playfield. if collision(player1,missile0) then score=score+20 : goto __contadorenemigos : rem resetear disparo si sale colisiona playfield. goto __shotupdate __contadorenemigos enemigos=enemigos-1 if enemigos=0 then goto __nextfase else goto __nextalien __nextfase enemigos=1 fase=fase-1 if fase<=1 then fase=1 x=x+20: if x>250 then x=88 goto __reiniciofase __nextalien rem p1y=((rand&7)+1)*8 : rem generamos altura aleatoria del alien rem if p1y<=16 then p1y=23 : rem checkear altura minima del alien rem h=(rand&1) : rem aleatorio para surgir por lado izquierdo o derecho rem if h=0 then p1x=12 : rem g=0 else p1x=138: g=1 p1x=(rand&1) if p1x=0 then p1x=12 else p1x=136 __clearshot rem missile0x=(missile0x-15)/4 missile0x=(missile0x-18)/4 missile0y=((missile0y-1)/8) pfpixel missile0x missile0y off s=0:missile0x=200:missile0y=200 __shotupdate rem Update alien position. player1x=p1x player1y=p1y if p1y>=80 then goto __vidas : rem alien alcanza el suelo. missile0x=mx:missile0y=my : rem actualizar posicion de disparo rem Disparo alien if !b{1} && a=20 && p0x=p1x then mex=p1x+4:mey=p1y+6:b{1}=1 : rem se activa disparo alien. if !b{1} && fase=1 && p0x=p1x then mex=p1x+4:mey=p1y+6:b{1}=1 : rem se activa disparo alien fase avanzada. if b{1} then mey=mey+2 rem if z=1 && fase=1 then mey=mey+2 : rem velocidad disparo fase avanzada. if mey>=88 || missile1y>=88 then mex=200:mey=210:b{1}=0 : rem resetear disparo si sale del rango. if collision(playfield,missile1) then __eliminarbloque else __eliminarbloquecontinuar __eliminarbloque mex=(mex-18)/4: mey=((mey-4)/8) if mey<10 then pfpixel mex mey off mex=200:mey=210:b{1}=0 : rem resetear disparo si sale colisiona playfield. __eliminarbloquecontinuar if collision(player0,missile1) then mex=200: mey=210: b{1}=0 : p0x=20: goto __vidas : rem comprobar si impacta al jugador. missile1x=mex missile1y=mey goto __skipgameover __vidas vidas=vidas-1 a=0 for t=1 to 100 COLUBK=0 a=a+1 if a=1 then player0: %11100111 %01100110 %01001000 %00010101 %00100000 %00010100 %01000000 %00010000 end if a=10 then player0: %11100111 %01100110 %00010000 %01000100 %00000000 %00010000 %00000000 %00100010 end if a>=20 then a=0 drawscreen next a=0 if vidas=0 then goto __gameover else goto __reiniciofase __gameover b{0}=1: rem gameover flag m=3 : rem vidas rem w=15 : rem numero de aliens x=88 : rem color base fases y=3 : rem fase o=0 : rem contador p=60 : rem contador rem check highscore if sc1 > _High_Score01 then goto __New_High_Score if sc1 < _High_Score01 then goto __Skip_High_Score rem First byte equal. Do the next test. if sc2 > _High_Score02 then goto __New_High_Score if sc2 < _High_Score02 then goto __Skip_High_Score rem Second byte equal. Do the next test. if sc3 > _High_Score03 then goto __New_High_Score if sc3 < _High_Score03 then goto __Skip_High_Score rem All bytes equal. Current score is the same as the high score. goto __Skip_High_Score __New_High_Score rem Saves new high score. _High_Score01 = sc1 : _High_Score02 = sc2 : _High_Score03 = sc3 __Skip_High_Score rem Saves the latest score for the high score flip. _Temp_Score01 = sc1 : _Temp_Score02 = sc2 : _Temp_Score03 = sc3 __gameoverloop o=o+1 if o=120 then scorecolor = $00 : sc1=_High_Score01 : sc2=_High_Score02 : sc3=_High_Score03 : goto __Skip_Flip rem If the Swap_Scores bit is off, display the current score. if o=240 then scorecolor = $0E : sc1=_Temp_Score01 : sc2=_Temp_Score02 : sc3=_Temp_Score03 : o=0 : p=p+30 __Skip_Flip rem if o=210 then p=p+30 if p>=250 then p=0 COLUBK=p drawscreen if !joy0fire then goto __gameoverloop else score=0: goto __reiniciofase : rem jugador aprieta boton de disparo. __reiniciofase a=0 : rem contador interno w=15 : rem numero de aliens rem u=20:v=48:w=3 : rem reinicio posicion alien rem g=0:h=0 : rem reinicio direccion alien c=50 : rem posicion jugador s=0:missile0x=200:missile0y=200 : rem desactivar disparo nave mex=200: mey=210: b{1}=0 : rem desactivar disparo alien ballx=200: bally=200: o=0 : p=0: rem reinicio bonus playfield: ................................ ................................ ................................ ................................ XXXX.XXXXXXXXX....XXXXXXXXX.XXXX XXXX.XXXXXXXXX....XXXXXXXXX.XXXX ................................ ................................ ................................ ................................ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end player0: %11100111 %01111110 %00111100 %00011000 %00011000 %00000000 %00000000 %00000000 end rem COLUBK=0 rem COLUP1=0 for t=1 to 100 a=a+1 if a=1 then COLUP0=28 if a=20 then COLUP0=0 if a=40 then a=0 player0x=c COLUP1=0 COLUBK=00 drawscreen next COLUBK=0 goto __nextalien : rem reincia posicion nuevo alien y comienza bucle del juego __skipgameover rem this command instructs the program to write data to the TV screen. drawscreen rem Make the guy move if joy0right then p0x=p0x+1 if joy0left then p0x=p0x-1 if p0x>140 then p0x=140 if p0x<10 then p0x=10 rem Ball bonus o=o+1: if o>=255 then p=p+1:o=0 if p>=5 && ballx=200 then ballx=80:bally=80:o=0:p=0 if p>=1 && ballx=80 then ballx=200:bally=200:o=0:p=0 if collision(player0,ball) then score=score+90:ballx=200:bally=200:o=0 rem Movimiento del alien f=f+1 if f>=fase then f=0 else goto __skipmovement rem Next, I'm going to have the routine that moves the enemy be skipped if t is less than 7. rem The number can be reduced to speed up enemy movement. rem if f<2 then goto __skipmovement : rem ralentiza movimiento enemigo rem if h=0 then goto __alienizquierdo else goto __alienderecho g=0 if p1x>p0x && p1x>8 && s=0 then p1x=p1x-1 if p1x8 && g=0 then p1x=p1x-1: g=0 rem hard mode if s=1 && (p1x-mx<5) && p1x<138 then p1x=p1x+1: g=1 if s=1 && (mx-p1x<8) && p1x>8 && g=0 then p1x=p1x-1 goto __aliendelay __alienizquierdo rem if p1x<60 && g=0 then p1x=p1x+1 else f=0:g=2 if collision(player1,playfield) then f=0:g=2:p1x=p1x-1:goto __bajaralien if g=0 then p1x=p1x+1 if g=2 then g=1 : rem delay en el extremo derecho. if p1x>10 && g=1 then p1x=p1x-1 else f=0:g=0 if p1x<=12 && g=1 then g=2: goto __bajaralien goto __skipmovement __alienderecho if collision(player1,playfield) then f=0:g=0:p1x=p1x+1:goto __bajaralien if p1x<=140 && g=0 then p1x=p1x+1 if g=2 then g=1 : rem delay en el extremo derecho. if g=1 then p1x=p1x-1 if p1x>=138 && g=0 then g=2: goto __bajaralien __aliendelay for t=1 to 100 next goto __skipmovement __bajaralien rem if p1y<80 then p1y=p1y+8 else goto __nextalien rem you have to have a game loop, so tell the program to jump back to the beginning. __skipmovement rem comprobar estado left switch if switchleftb then n=0 else NUSIZ0=$15: n=5 rem mover scroll h=h+1 if h=20 then h=0 if h=0 && !switchrightb then pfscroll left: h=0 goto main rem minikernel fuera del loop para establecer fondo al score (scback) asm minikernel sta WSYNC lda scback sta COLUBK rts end