 rem -----------------------------------------
 rem *** SCROLLANOID BETA 2 
 rem -----------------------------------------
 rem -- new: Now you can blow stuff up! ------
 rem -----------------------------------------
 rem *** FEATURING THE BALL AS PLAYER 1 0
 rem *** AND THE ATARI LOGO AS PLAYER 2/CPU
 rem -----------------------------------------
 rem *** Hit enough blocks to clear the board
 rem *** The Camera only follows Player 1,
 rem *** and the AI can control player 2
 rem -----------------------------------------
 
 rem -----------------------------------------
 rem ---init section, runs once: -------------
 rem -----------------------------------------
 rem -----------------------------------------
 a=0: rem comment the next line for vwBASIC, Flashback BASIC uses it
 gosub loadvirtualworld 

 data mazecolors $b0,$50,$60,$a0,$02,$40,$22,$c0,$92,$f4,$52,$a2,$d0,$f2,$70,$e2
 data ballwaveform 6,6,4,7,8,1,2,6,6,4,4,7
 data ballmusic 2,4,6,8,10,12,14,16,18,20,9
 data ballmusic2 11,9,12,4,7,0,11,14,18,20,9
 data ballwaveform2 4,4,4,4,4,4,4,6,6,4,4,7
 ballmusic(x)=ballmusic(x)+1

 f=0:t=0:g=3:u=5:x=5:y=5:v=6:w=1:z=2:m=0:r=16:p=2:q=2:h=112:l=0:k=0:n=0:score=0:o=0:var1=0
 var2=0:rem missile init

 rem check: does placing this call beneath data statements cause it to vanish in the init section? a=0:gusub loadvirtualworld: rem Stella fix (rem this line to compile for SuperCharger)

 COLUPF=$3A 

 rem COLUPF=$be
 rem COLUPF=225
 COLUP0=$54
 rem vwpixel(x,y,bindplayer0):vwpixel(u,v,bindplayer1)
 NUSIZ1=%00111111:rem wide player2, wide missile
setuproutine rem ---- can call this
 scrollvirtualworldtoggle=1:rem refresh cam after drawing on virtual world
 rem goto skipit
 for i = 13 to 19 step 2
 for j = 3 to 5
 vwpixel(i,j,on)
 next j,i
 for i= 91 to 13 step -2
 for j = 7 to 12
 vwpixel (i,j,on)
 next j,i
skipit
 j= $3c:for i = 0 to 17: rowcolors(i)=j:j=j+5:next i
 
 rem ------------------------------------------------
 rem end init section (implicit return)--------------
 rem ------------------------------------------------
 rem ------------------------------------------------ 

 rem ------------------------------------------------
 rem ---:the next comment line is used by the compiler
 rem ---gameloop subroutine, runs every frame:    ---
 rem ------------------------------------------------
 rem ------------------------------------------------
 rem vars t-toggle x,y f-frame g - direction (12345678, 1 is up)
 rem varx u,v (p1 xy), r - marquee in center of virtual world index
 rem w, z dir x/y, : p,q dir p1 x/y,   m - musical pixels p0
 rem i,j,e - temp vars for loops, expressions
 rem o - player1 animation l used by player 2 scroll animation, k, n too.
 rem ---------------------------------------------------
 rem TinyBASIC program
 rem ---------------------------------------------------
 rem t is not used elsewhere...
 rem t=1-t:rem this expression toggles var t between 0 and 1 

 rem ---------------------------------------------------
 rem ------- four loads, split every 16 frames
 

 f=f+1
 if f=1 then goto framehandler1 
 if f=2 then goto framehandler2
 if f=3 then goto framehandler3
 if f=4 then f=0: goto framehandler4 

 return:rem never gets here
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------

 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
framehandler1 rem ---------------------------- start framehandler1
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------

 vwpixel(x,y,bindplayer0)
 vwpixel(u,v,bindplayer1)

 rem --- player 1 action/input:
 rem z=0:w=0
 rem COLUP0=$84
 if joy0left=1 then w=1 
 if w=1 and x>0 then x=x-1 
 if joy0right=1 then w=2
 if w=2 and x<91 then x=x+1
 if joy0up=1 then z=1
 if z=1 and y>2 then y=y-1
 if joy0down=1 then z=2
 if z=2 and y<19 then y=y+1
 if x=0 and w=1 then w=2: rem flip direction if at border of virtual world
 if x=91 and w=2 then w=1
 if z=1 and y=2 then z=2
 if z=2 and y=19 then z=1

 if vwpixel(x,y,poll)=0 then return

 if w=1 and z=1 then z=2:goto jmpxif :rem if left and up go down and left
 if w=2 and z=1 then z=2:goto jmpxif:rem if right and up go down and right
 if w=1 and z=2 then z=1:goto jmpxif:rem if left and down go left and up
 if w=2 and z=2 then z=1 : rem if right and down then right and up  
jmpxif

 vwpixel(x,y,flip):rem pixel destroyed, take over one voice; fx with the music:
 AUDC0=ballwaveform(var1):rem ball wave
 AUDF0=ballmusic(var1):rem ball music
 if var1>21 then var1=0 else var1=var1+1
 rem SUSTAINFORFRAMES=12
 score=score+1 
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 return: rem ---------end framehandler1
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------

 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
framehandler2 rem ----------------------------- start framehander2 
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 gosub animateplayer1

  
 rem COLUP1=68:REFP1=0: rem player face forward
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 return : rem -------------end framehandler2
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------

 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
framehandler3 rem ----------------------------- start framehander3
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 


 rem if p=1 then player1x=player1x-5:rem fine adjust to offset
 rem if p=2 then player1x=player1x+5:rem fine adjust to offset
                rem vertical... skipping, too close to virtual world scroll

 rem player2 action/input:
 rem q=0:p=0
 if joy1left=1 then p=1 
 if p=1 and u>0 then u=u-1 
 if joy1right=1 then p=2
 if p=2 and u<91 then u=u+1
 if joy1up=1 then q=1
 if q=1 and v>2 then v=v-1
 if joy1down=1 then q=2
 if q=2 and v<19 then v=v+1
 rem REFP1=0: rem face forward, default incommming

 if u=0 and p=1 then p=2: rem flip direction if at border of virtual world
 if u=91 and p=2 then p=1
 if q=1 and v=2 then q=2
 if q=2 and v=19 then q=1

 if vwpixel(u,v,poll)=0 then return

 if p=1 and q=1 then q=2:goto jmpxif2 :rem if left and up go down and left
 if p=2 and q=1 then q=2:goto jmpxif2:rem if right and up go down and right
 if p=1 and q=2 then q=1:goto jmpxif2:rem if left and down go left and up
 if p=2 and q=2 then q=1 : rem if right and down then right and up  
jmpxif2

 vwpixel(u,v,flip):rem pixel destroyed, take over one voice; fx with the music:
 rem unless both players have simultaneous hits - then both fx
 AUDC1=ballwaveform2(m):rem ball wave
 AUDF1=ballmusic2(m):rem ball music
 if m>21 then m=0 else m=m+1
 rem SUSTAINFORFRAMES=10
 
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 return : rem -------------end framehandler3
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------

 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
framehandler4 rem --------------------------- start frame handler4
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 
 rem COLUP1=50:REFP1=255:rem player face backwards

 rem ------------------------------------------------
 rem ------pan the camera to follow player 1:
 rem ------------------------------------------------
 
 rem if joy0fire=1 then goto skipmovecamera
 if x-BITIndex > 12 and BITIndex < 72 then BITIndex=BITIndex+1:scrollvirtualworldtoggle=1
 if x < BITIndex+10 and BITIndex>0 then BITIndex=BITIndex-1:scrollvirtualworldtoggle=1
 rem -----pan camera vertically (BYTErowoffset) if player is near the edge of the playfield CAM
 i = y*12: rem "read i(fastyindex,y)" is faster (12 step lookup table for virtual world y values)
 rem table not available anymore i=fastyindex(y): rem index the y*12 lookup table
 if BYTErowoffset<120 and BYTErowoffset+36<i then BYTErowoffset=BYTErowoffset+12:scrollvirtualworldtoggle=1
 if i>36 then i=i-36
 if BYTErowoffset>i then BYTErowoffset=BYTErowoffset-12:scrollvirtualworldtoggle=1	
skipmovecamera 
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 rem ----------end framehandler4 
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 return

 rem----------------------subroutines:
 rem-----------------------------------------------------------
animateplayer1 rem --- flip sprite in four directions

 
 if o=0 then REFP0=0:loadplayer0(0):COLUP0=255: rem face forward, default incommming
 
 if o=1 then REFP0=255:COLUP0=$64:rem player face backwards
 rem COLUP0=$64
  
 rem COLUP0=$44
 if o=2 then loadplayer0upsidedown(0):COLUP0=$44:rem player upsidedown
 if o=3 then REFP0=0:COLUP0=$ef:rem player face forward
 o=o+1
 if o=4 then o=0
 if score<210 then COLUP0=$64: rem --- only show player 1 on fire beyond 210 (indicates close to clearing board)
 rem return 
 rem -------------------------------------------------------------
 rem ------------------------------------------------
 rem end game loop (implicit return)-----------------
 rem ------------------------------------------------
 rem -------------------------------------------------------------


 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 rem ---:the next comment line is used by the compiler
 rem ---gameloop2 subroutine, runs every frame:    --
 rem ------------------------------------------------
 rem -------------------------------------------------------------


 rem --------handle missle init 
 rem COLUBK=0
 if joy0fire=1 and var2=0 and score <210 then var2=10:bx=x:by=y:px=w:SUSTAINFORFRAMES=20:AUDC0=4:AUDF0=6:rem init missile graphic


 rem -- multicolored defender style missile can destroy blocks in front of you
 rem -- todo: freeze Atari opponent for a duration if hit and flash screen - done
 rem -- todo: Atari opponent fires back at you :)
 
 if var2=0 then missile1x=0:missile1y=0:goto skipmissile1
 if px=2 and bx<91 then bx=bx+1
 if px=1 and bx>0 then bx=bx-1
 vwpixel(bx,by,bindmissile1):missile1y=missile1y-4
 rem -- screen turns red if Atari logo is hit, logo vanishes and reinitializes
 rem -- removed red screen 

 if u=bx and v=by then var2=0:u=1:v=5:score=score+10:AUDC0=5:SUSTAINFORFRAMES=80:goto skipmissile1
 var2=var2-1
 rem -- blocks blow up if they are hit
 if vwpixel(bx,by,poll)=0 then goto skipmissile1 
 vwpixel(bx,by,flip):var2=0:AUDC0=7:rem COLUBK=64
 score=score+1: rem -- blowing up blocks increases score only until player catches fire 
skipmissile1

 

 rem vars: h - sliding index for player 2 sprite message

 if l<>4 and l<>8 and l<>12 and l<>16 then goto scrollplayerdelay
 loadplayer1(h)
 h=h+1
 if h>184 then h=112
scrollplayerdelay
 rem i=i+1:mazecolours(l)=i
 l=l+1
 if l>16 then l=0:COLUP1=mazecolors(n):n=n+1
 if n>16 then n=0
 rem play 2nd or 3rd (60/90 MUSICINDEX) and clear board if enough blocks are destroyed:
 if score=255 then score=0:COLUBK=0:MUSICINDEX=90:for i=0 to 91:for j=2 to 19 step 3:vwpixel(i,j,on):next j,i:COLUPF=mazecolors(k):j=k:k=k+1: rem for i = 0 to 17: rowcolors(i)=j:j=j+5:next i
 if k>16 then k=0

 if score=210 then score=211:h=0:MUSICINDEX=60: rem --- display bonus message in player 2, play reward song, earn extra point. 
  


 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 rem end gameloop2 (implicit return)----------------- 
 rem ------------------------------------------------
 rem -------------------------------------------------------------



 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 rem ---:the next comment line is used by the compiler
 rem ---KITCHENSINK subroutine, runs when scrollvirtualworldtoggle=1
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 rem run playfield central banner routine when scrolling:
 if score>200 then goto extraphrase
 if r>96 then r=0
extraphrase
 for j=2 to 19: rem --- slide sprite library array through virtual world array
 i=r+j
 e=fastyindex2(j)+5: rem same as j*12+5, lookup table
 rem e=e+5
 
 rem virtualworld(e)=sprites(i):push a slice of sprites array into world array
 rem fix - Flashback BASIC cannot see spritelibrary data but can load it into sprites:
 loadplayer1upsidedown(i):virtualworld(e)=player1(0)
 next j
 r=r+1 :rem 20

 data fastyindex2 0,12,24,36,48,60,72,84,96,108,120,132,144,156,168,180,192,204,216,228


 rem -------------------------------------------------------------
 rem -------------------------------------------------------------
 rem end KITCHENSINK (implicit return)----------------------------
 rem -------------------------------------------------------------
 rem -------------------------------------------------------------

 
virtualworld
......................................X...X..X.........X..XXXX.....XXXXXX......XXXXXXXXXXXXX
.X.......XXXXX........................X...X..X.........X..X..X....X......X.....X..........XX
..XX.........X........................X...X...X...X...X...XXXXX..X..X..X..X....X...XXXXXXXXX
....X........X.........................X.X.....X.X.X.X....X....X.X........X....X............
.....X.......X..........................X.......X...X.....XXXXXX.X.X....X.X....XXXXXXXXXX...
......X......X..........XXXXXXXXXX...............................X..XXXX..X.............X...
.......X......X..................X................................X......X..............X...
........X.....X..................X.................................XXXXXX...............X...
.........X.....X.............X...X.......XXXXXXXXXXXXXXX........................XXXXXXXXX...
..........X...X..............X...X.....................X....................................
...........X.X...............X...X.....................X............................XXXXXXXX
............X................X...XXXXXXXXX....XXX......XXXXXXXXXXXXXXXXXXXXXXXXX..XXX......X
X............................X..................XX................................X........X
.X.......XXXXX...............XXXXXXXXXXXXX.......XXX..............................X...XXXXXX
..XX.........X.....................................XXXXXXXXXXXXXXXXXXXXXXXXXXX........X.....
....X........X..............................................................XXxxxxx...X.....
.....X.......X.........................................XXXXXXXXXXXXXXXXXXXX.XXxx.xx...X.....
.............................................................................................XXXXXXXXXXXXXXXXXXXX...X.....
.......X......X................................................XXXX...................X.....
X.......X.....XXXX.........................XXXXXXXXXXXXXXXXXXXXXXXX...................XXXXXX

sprites
0
..XXX...
..XXX...
XXXXX.X.
..XX.XX.
XXXX.X..
X.XXX...
XX.XXX..
.XX.XXXX
8
.X.X.X..
..XXXX..
X..XX...
XXXXXX..
...XX.XX
...XX...
X.X..X.X
.X....X.
16
........
XXXXXXX.
XXX.....
XXXXXXX.
XXXXXXX.
...XXXX.
XXXXXXX.
........
24
........
XXXXXXXX
XXXXXXXX
XXX.....
XXXX....
XXXXXXXX
XXXXXXXX
........
32
........
XXXXXXX.
XXX...XX
XXX...XX
XXXXXX..
XXX..XXX
XXX...XX
XXX...XX
40
........
XXXXXXXX
XXXXXXXX
XXX..XXX
XXX...XX
XXXXXXXX
XXXXXXXX
........
48
........
XXX.....
XXX.....
XXX.....
XXXXXXXX
XXXXXXXX
........
........
56
........
XXX.....
XXX.....
XXX.....
XXXXXXXX
XXXXXXXX
........
........
64
........
..XXXX..
.XXXXXX.
XXX..XXX
XXX...XX
XXXXXXXX
XXXXXXXX
XXX...XX
72
........
XXX...XX
XXX...XX
XXXXX.XX
XX.XXXXX
XX...XXX
XX...XXX
........
80
........
XXXXXXXX
XX....XX
XX....XX
XXX...XX
XXX...XX
XXXXXXXX
........
88
XXXXXXXX
XXXXXXXX
..XXXX..
..XXXX..
..XXXX..
XXXXXXXX
XXXXXXXX
........
96
........
XXXXXXX.
XXX.XXXX
XXX..XXX
XXX..XXX
XXX.XXXX
XXXXXXX.
........
104
........
........
........
..XXX...
..XXX...
........
........
........
112
XXXXXX..
X...XX..
XXXXXX..
XX...X..
XX...X..
XX...X..
XX...X..
........

120
........
........
XXXXX...
..X.....
..X.....
..XX....
..XX....
..XX....
........
128
........
XXXXXX..
X...XX..
XXXXXX..
XX...X..
XX...X..
XX...X..
........
136
........
XXXXXX..
X...XX..
XXXXXXX.
XX....X.
XX....X.
XX....X.
........
144
........
........
..X.....
..X.....
..XX....
..XX....
..XX....
..XX....
........

152
........
........
.xxxxx..
.x...x..
.....x..
..xxxx..
.xx.....
.xx.....
.xxxxx..
160
........
........
.xxxxx..
.x......
.x......
.xxxxx..
.x...x..
.xx..x..
.xxxxx..
168
........
.xxxxxx.
.xx...x.
.xx...x.
.xx...x
.xx...x.
.xxx..x.
.xxxxxx.
........
176
........
.xxxxxx.
.xx...x.
.xx...x.
.xx...x
.xx...x.
.xxx..x.
.xxxxxx.
........
184
........
........
........
........
........
........
........
........


chiptunes
7, 30, 0, 0, 8
7, 24, 0, 0, 8
7, 20, 0, 0, 8
12, 9, 12, 7, 22
12, 14, 12, 11, 22
6, 30, 0, 0, 20
6, 24, 6, 30, 10
6, 22, 6, 30, 10
6, 21, 6, 30, 20
12, 26, 12, 19, 20
0, 0, 0, 0, 254
0,0,0,0,0

6, 5, 4, 12, 20
6, 17, 4, 19, 20
6, 5, 4, 12, 20
6, 17, 4, 15, 35
0, 0, 0, 0, 255
29,23,5,10,0

7, 30, 0, 0, 68
7, 24, 0, 0, 8
7, 20, 0, 0, 8
7, 24, 0, 0, 7
30, 0, 0, 8, 17
24, 0, 0, 8, 7
20, 0, 0, 8, 17
24, 0, 0, 8, 7
22, 0, 0, 8, 20
6, 0, 4, 0, 255
27, 0, 0, 8, 15
24, 0, 0, 8, 17
24,24,24,24,0
                                                               