Qbasicnews.com

Full Version: the box flickers...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
yes it's me again...
anyways, the following is a simple program which two dots randomly move about and area. absolutely pointless.
well i can't figure out how to refresh the dots without having to clear and re-draw the red box around then. when i do, the box flickers. so here's the code
it's obvious that im still a newbie programmer:
Code:
SCREEN 13
a = 40
B = 40
c = 40
d = 45
DO
LINE (19, 19)-(101, 101), 4, B
frld = 0
DO
frld = frld + 1
LOOP UNTIL frld = 2500
RANDOMIZE TIMER
RN = INT(RND * 4) + 1
CLS
IF RN = 1 THEN a = a - 1
IF RN = 3 THEN a = a + 1
IF RN = 2 THEN B = B + 1
IF RN = 4 THEN B = B - 1
IF a < 20 THEN a = 100
IF a > 100 THEN a = 20
IF B < 20 THEN B = 100
IF B > 100 THEN B = 20
RN2 = INT(RND * 4) + 1
IF RN2 = 1 THEN c = c - 1
IF RN2 = 3 THEN c = c + 1
IF RN2 = 2 THEN d = d + 1
IF RN2 = 4 THEN d = d - 1
IF c < 20 THEN c = 100
IF c > 100 THEN c = 20
IF d < 20 THEN d = 100
IF d > 100 THEN d = 20
PSET (a + 1, B + 1), 9
PSET (a + 1, B), 9
PSET (a, B + 1), 9
PSET (c + 1, d + 1), 7
PSET (c + 1, d), 7
PSET (c, d + 1), 7
PSET (c, d), 7
PSET (a, B), 9
LOOP UNTIL INKEY$ = "q"
any help?
Code:
SCREEN 13
a = 40
B = 40
c = 40
d = 45
oa=a 'old a
ob=b 'b
oc=c 'c
od=d 'd
RANDOMIZE TIMER
DO
LINE (19, 19)-(101, 101), 4, B

frld = 0
DO
frld = frld + 1
LOOP UNTIL frld = 2500

RN = INT(RND * 4) + 1
'CLS      'NEVER EVER USE CLS! EVER!, It's death penalty!
IF RN = 1 THEN a = a - 1
IF RN = 3 THEN a = a + 1
IF RN = 2 THEN B = B + 1
IF RN = 4 THEN B = B - 1
IF a < 20 THEN a = 100
IF a > 100 THEN a = 20
IF B < 20 THEN B = 100
IF B > 100 THEN B = 20
RN2 = INT(RND * 4) + 1
IF RN2 = 1 THEN c = c - 1
IF RN2 = 3 THEN c = c + 1
IF RN2 = 2 THEN d = d + 1
IF RN2 = 4 THEN d = d - 1
IF c < 20 THEN c = 100
IF c > 100 THEN c = 20
IF d < 20 THEN d = 100
IF d > 100 THEN d = 20


PSET (oa + 1, oB + 1), 0   'Erase the old dots, using color 0 (background)
PSET (oa + 1, oB), 0
PSET (oa, oB + 1), 0
PSET (oc + 1, od + 1), 0
PSET (oc + 1, od), 0
PSET (oc, od + 1), 0
PSET (oc, od), 0
PSET (oa, oB), 0

'Set the new "old" variables
oa=a
ob=b
oc=c
od=d

PSET (a + 1, B + 1), 9 'Draw the new stuff
PSET (a + 1, B), 9
PSET (a, B + 1), 9
PSET (c + 1, d + 1), 7
PSET (c + 1, d), 7
PSET (c, d + 1), 7
PSET (c, d), 7
PSET (a, B), 9
LOOP UNTIL INKEY$ = "q"


Untested code, what it does is, before you change the variables, you store them in other variables..

And use the "old" variables to draw background color, erasing the old picture, then use the new vars to draw the new pic.


Also, when you use RANDOMIZE TIMER it reseeds the random generator based on the seed number (in this case TIMER)

So, if you use it as often as you did (i changed it) you would get very repetetive patterns

You only need to use it once.
cool thanks!