#### Archived

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

# Making lines move in qbasic

This topic is 5916 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How do you make a line go from point a to point b?

##### Share on other sites
Dont forget SCREEN 13,

So:

SCREEN 13
COLOR 4
line (x1,y1)-(y1,y2)

##### Share on other sites
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 on other sites
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 on other sites
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..

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631722
• Total Posts
3001892
×