CHARN's QBASIC Tutorial, Part 1 (4/27/98)

My (developing) web site is here:

Looking around on the 'net, I see a problem: there are way too many
QBasic programmers who write programs that, in a word, suck. There is a
huge need for people who can program professionally and help others learn
more about the language instead of boring them with their "first program,
but good." =(

Instead of showing people how we just learned the PRINT statement,
QBasic programmers should be developing skills and ideas that will carry
over if they ever try to learn a language like C or something. With that
in mind, here goes my first subject: graphics.

In case you didn't know, a sprite is a little picture that can be
moved around the screen to make neat effects. In QBasic, the best & fastest
way to show sprites is to use the GET and PUT (graphics) statements. The full
description is in the online help file, in case you need something made more
clear or need more information. To use GET & PUT:

First draw your picture on the screen (not part of your finished program)
Then, do something like this:

'this line is out of the online help--how to know what size to dimension the array
Dim PicArray&(4+int(((x2-x1+1)*(bpp)+7)/8)*planes*((y2-y1)+1)/4)
Get (x1,y1)-(x2,y2),PicArray&
where for:
screen 11: bpp=1, planes=1
screen 12: bpp=1, planes=4
screen 13: bpp=8, planes=1

After that, you'll probably want to save the picture to a file for
future reference (after all, it doesn't look good to redraw the picture each
time you run the program). To do this you would use BSAVE & BLOAD.

def seg=varseg(PicArray&(0))
bsave "picname.bsv", varptr(PicArray&(0)),bytes
def seg

Now that you have the file you need, you can load it in your main
program by using BLOAD:

Dim PicArray&(bytes)
def seg=varseg(PicArray&(0))
bload "picname.bsv",varptr(PicArray&(0))
def seg

Then all you need to do is PUT the picture to the screen like this:

PUT (x,y),PicArray&, actionverb

where actionverb is PSET, PRESET, AND, OR, XOR, and the default is XOR and
is the screen mask to use when plotting the picture (i.e. by using XOR twice
in the same place, the background is restored. This can be used for animation).

That's it for Charn's first QB tutorial! I hope I didn't bore you to
death! Send any questions, problems, hatemail or adoration to
(ok, maybe not hatemail)

Just to protect my butt:
I am not responsible for the effect any of this code has on your computer,
your mental health, pet ferret or whatever. It has all been tested on several
computers, but errors have a way of sneaking in where they don't belong.

Have Fun Programming!!! -->>> CHARN