Jump to content
IGNORED

Demo Scroller Tutorial


Recommended Posts

Demo Scroller Tutorial

 

This tutorial shows how easy it is to write a demo scroller with Virtual World BASIC:

 

How to scroll text and graphics through sprites and through the virtual world, while scrolling the virtual world too!

 

This is scrolling, on top of scrolling, on top of more scrolling and you can do it easily with Virtual World BASIC! Virtual World BASIC extends the hi-res over semigraphics BASIC screen buffer concept into a hi-res over semigraphics virtual world buffer concept, with a camera view:

https://www.youtube.com/watch?v=n86z6pRc99A

 

 

Here are the steps used to write the demo scroller:

 

1. Drawing the large virtual world and the sprites with ASCII art:

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.....
......X......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
........
XX...XX.
XX...XX.
XXXXXXX.
XXXXXXX.
XX...XX.
XX...XX.
........
24
........
..XXX...
.X...X..
.XXXXX..
.X......
.X......
..XXXX..
........
32
........
.XX.....
.XX.....
.XX.....
.XX.....
.XXXXX..
.XXXXX..
........
40
........
.XX.....
.XX.....
.XX.....
.XX.....
.XXXXX..
.XXXXX..
........
48
........
..XXXX..
.XXX.XX.
.XX..XX.
.XX..XX.
.XX.XXX.
..XXXX..
........

2. The Camera is programmed to follow player 1 through the virtual world by comparing the players x,y coordinates to the camera and adjusting the cam to keep the player in view:

 rem ------------------------------------------------
 rem ------pan the camera to follow player 1:
 rem ------------------------------------------------
 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
 rem i = y*12: rem "read i(fastyindex,y)" is faster (12 step lookup table for virtual world y values)
 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 

3. Player 1 is animated and set on fire when close to clearing the screen:

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
 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)

4. Player 2 is animated with a scrolling text phrase from the inline sprite library by loading in a scrolling section of sprite graphics by moving the index on each load (with a delay so it doesn't scroll too fast):

 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:COLUPF=0:MUSICINDEX=90:for i=0 to 91:for j=0 to 19 step 3:vwpixel(i,j,on):next j,i:COLUPF=mazecolors(k):k=k+1
 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.
 return

5. Sprites are bound to virtual world coordinates (not to physical screen coordinates, though those can be adjusted for fine tuning position) and only show up on screen when they are in the camera view:

 rem -- bind Player 1 and Player 2 sprites to the virtual world:
 vwpixel(x,y,bindplayer0)
 vwpixel(u,v,bindplayer1)

6. Tile pixels are addressed with x,y coordinates throughout the virtual world:


 vwpixel(x,y,flip):rem flip virtual world tile pixel

7. A phrase from the inline sprite library is scrolled through the center of the virtual world by loading a section of the sprite library and moving the index. Printing the binary strings from the sprite library directly onto the virtual world just like the print@ command in BASIC prints anywhere on the screen - this is possible because Virtual World BASIC let's you access the binary array of the virtual world as a byte array as well:

 rem --- run playfield central banner routine when scrolling:
 if r>84 then r=16
 for j=0 to 19: rem --- slide sprite library array through virtual world array
 i=r+j
 e=fastyindex(j)+5: rem same as j*12+5, lookup table
 rem e=e+5
 virtualworld(e)=sprites(i):push a slice of sprites array into world array
 next j
 r=r+20

8. Music:
There are three chip tunes defined; the first tune repeats. The second and third tune are heard only when Player 1 catches fire and when the screen is cleared. Hearing the third tune is unlikely because each player takes over one of the two voices to play a note of it's own musical tune whenever the player hits a block.

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

Note: Virtual World BASIC processes musical scores and sound FX through a filter that changes the sound envelope.

 

Not covered in this tutorial:

 

Controls:
Player 1 is controlled by the joystick, player 2 is controlled by the AI or the second joystick.

 

Easter egg:
If Player 2 is in view when Player 1 catches fire, a new phrase is scrolled.

 

Virtual World BASIC was designed for building scrolling demo's and tile mapped games, try it out! :)

Follow the link in my signature to download the source code for this demo and the vwBASIC compiler.

 

 

  • Like 7
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...