Archived

This topic is now archived and is closed to further replies.

The_Tempest

Making lines move in qbasic

Recommended Posts

The_Tempest    122
ya but how do u make line(1,2)-(4,5) move to another place on the screen. Ex: a laser in a space invaders game.

BTW, my compiler cant handle screen 13 for some reason, it always gives me a illegal function error or something. It handles screen 1-12 though...

Share this post


Link to post
Share on other sites
taratr98    122
Boy, its been a long time since I coded in QBasic (high school - which was 5 years ago). But when I coded in QBasic, I was the king of lasers .

The easiest way to do it is to draw your colored line to the screen, draw its new position, and draw a black line (COLOR 0) over the showing portion of the old position. (So that it appears to be moving across the screen.)

For example, I draw a red line from (10,10) to (20, 10). Then I want to move it over 5 pixels. So I draw a new red line at (15, 10) to (25, 10). Then I draw a black line from (10,10) to (15, 10) to erase the line's "old" position.

You'll need a for-loop to make it appear to 'animate'. Such as the following:

--
X=10
Y=10

FOR A=0 TO 300 STEP 5
COLOR 4
line (X+A,Y)-(X+10+A,Y)
COLOR 0
line (X+A-5, Y)-(X+A, Y)
NEXT
--

...or something like that. I don't have qbasic around here, so I can't test it out for ya. But the concept, at least, is solid. There may be a much better way to code it. I'm a little sick today and the Dayquil is making me a little woozy. (Which is probably the reason I even bothered to answer this!)

Oh, and that may happen far too quickly on a pentium-class computer. So you'll have to include some way to make it slow down a bit. You could run an empty for loop for a while, to make the computer think for a bit - remember, you only want to see this change position, at most, about 20 times a second. But an empty for-loop will make it run differently on different speed computers. (I remember the first time I ran one of my 286 games on my brand-spanking-new 486DX/33. WHOA!) So you need to use some kind of real-time calculation. (Like, run your drawing loop every 1/20th of a second or so.) There is SOME way to do this in QBasic... but I can't remember how.

-ATR-



[edited by - taratr98 on May 6, 2002 11:57:16 AM]

Share this post


Link to post
Share on other sites
The_Tempest    122
ur thinking of a delay (seconds). BTW Im just learning qbasic, after this ima try to learn c++ (the reason i didnt start with c++ is cause i dont understand pretty much any of it ). Thnx for the help, i think i understand..

Share this post


Link to post
Share on other sites