hello again, just want to thank Miggy and everyone who helped me out before. i took your suggestions and put some comments in pretty clearly explaing my program and i also updated it a lil
yet i'm having problems with speed...see, the computers at school have QB1.1 and are very slow, and i program here on a PIII 800 with QB4.5. so when i bring them to school to show them off, it runs pretty crappy. SOoo, my question is..is there a way in QB to determine the speed of a system so that i could make the delay in the program speedup/slow down in accordance to the speed of the computer??? this has been bugging me forever. and i know it can be done, because professional programmers must do this all the time for games and similar things, right???
also, there is one other problem...if the points reaches a certain number then there is an OverFlow error. i think this is because of DEFINT A-Z, but i'm not sure. is there a way to work around this??
so if there are any graphics geniuses out there or just anyone who can think of a way to make my program faster/more logical i would greatly appreciate some feedback
THANKS AGAIN ALL! s-)
DECLARE SUB ShotHit ()
DECLARE SUB Shotsetback ()
DECLARE SUB StarField ()
DEFINT A-Z
DIM SHARED xboard, xshot, yshot, shot, x, y, speed, sc, counter2
DIM SHARED bc, points, ppoints, r, collision, loops
DECLARE SUB Fire ()
RANDOMIZE TIMER
SCREEN 12: CLS
counter2 = 62: shot = 0: bc = 1: speed = 5: sc = 1 'Set initial values.
LINE (xboard + 320, 460)-(xboard + 20 + 320, 463), 1, BF 'Draw Initial Board(Paddle)
'***Variable Descriptions
' xboard = x pos of the board
' xshot = x pos of the board's shot (bullet) (used in shot SUB)
' yshot = y pos of the board's shot
' x and y = x and y pos of the missle: r = rate or speed of the missle
' sc = star color: counter = star palette counter
' bc = board color: counter2 = board palette counter
' points = acual calculated points, ppoints = displayed or printed points
' loops = times to loop the explosion
' speed = speed of bullet
'***Flags
' shot = tells that a shot has been fired
' collison = tells that a collision between missle and bullet has happened
' rite = tells that the right key has been pressed and animates board to right
' lehft = opposite of rite
DO
y = INT(RND * 400) + 1 'Gets random y pos and rate for missle
r = INT(RND * 3) + 1
IF r = 1 THEN 'Adds trail color according to speed.
trailcol = 9
ELSEIF r = 2 THEN trailcol = 4
ELSE IF r = 3 THEN trailcol = 14
END IF
SOUND INT(RND * 300) + (r * 100), 1
FOR x = 0 TO 650 STEP r 'Main Loop of Program
LOCATE 1, 10: PRINT "Speed ="; speed
LOCATE 1, 50: COLOR 9: PRINT "Points: "; ppoints 'Prints points and speed.
mcol = INT(RND * 9) + 6 'Random color of missle.(dum i know, i'll change it later, heh)
LINE (x, y)-(x, y), trailcol 'Draw Missle
CIRCLE (x, y), 3, mcol
CIRCLE (x - r, y), 3, 0
StarField 'Calls the sub to draw stars
key$ = INKEY$
IF key$ <> "" THEN GOTO getkey ELSE GOTO skipkey 'Skips if commands is nothing entered
'does this speeed up program? i don't know
getkey:
IF key$ = CHR$(0) + CHR$(77) THEN
rite = 1
ELSEIF key$ = CHR$(0) + CHR$(75) THEN 'gets right or left flag
lehft = 1
ELSEIF key$ = "x" AND shot = 0 THEN 'speed up or slow down bullet
IF speed = 10 THEN speed = speed ELSE speed = speed + 1
ELSEIF key$ = "z" AND shot = 0 THEN
IF speed = 5 THEN speed = speed ELSE speed = speed - 1
ELSEIF key$ = CHR$(27) THEN END
ELSEIF shot = 0 THEN
IF key$ = CHR$(32) THEN 'checks if shot is already fired and if not, then sets shot
SOUND 400, .5 'flag to 1 (or on)
shot = 1
END IF
END IF
skipkey:
IF rite = 1 THEN
LINE (xboard + 320, 460)-(xboard + 20 + 320, 463), 0, BF
xboard = xboard + 3
LINE (xboard + 320, 460)-(xboard + 20 + 320, 463), 1, BF
count = count + 1
IF count = 12 THEN rite = 0: count = 0 'does either left or right board
ELSEIF lehft = 1 THEN 'animation
LINE (xboard + 320, 460)-(xboard + 20 + 320, 463), 0, BF
xboard = xboard - 3
LINE (xboard + 320, 460)-(xboard + 20 + 320, 463), 1, BF
count = count + 1
IF count = 12 THEN lehft = 0: count = 0
END IF
IF shot = 1 THEN Fire 'calls shot sub if flag is on
IF collision = 1 THEN ShotHit 'calls shothit sub if flag is on
IF shot = 0 THEN 'brightens board if shot sub ends and board is dim
IF counter2 < 62 THEN '(my little "reload" effect)
PALETTE 1, 0 * 256 + counter2 * 256 ^ 2 + 0
counter2 = counter2 + 2
END IF
END IF
IF yshot > 440 THEN Shotsetback 'sets necesary variables back if board shot leaves screen
LINE (0, y)-(x, y), trailcol 'redraw missle to avoid erasing
FOR tt = 1 TO 18
FOR t = 1 TO 20000: NEXT t 'THIS IS THE SUCKY PART, lol, this is my delay loop
NEXT tt
NEXT x
LINE (0, y)-(x, y), 0 'erase missle after it leaves screen
LOOP
'LOCATE 1, 50: PRINT "x ="; x
'LOCATE 2, 50: PRINT "r ="; r
'LOCATE 3, 50: PRINT "xboard ="; xboard
'LOCATE 4, 50: PRINT "shot ="; shot 'used for debugging, REMed out for now
'LOCATE 5, 50: PRINT "xshot ="; xshot
'LOCATE 6, 50: PRINT "yshot ="; yshot
'LOCATE 7, 50: PRINT "y ="; y
'LOCATE 8, 50: PRINT "480 - y ="; 480 - y
SUB Fire
IF xshot = 0 THEN
xshot = xboard + 10 + 320 'sets x pos of board to x pos of bullet (middle of board)
END IF
IF counter2 > 30 THEN
PALETTE 1, 0 * 256 + counter2 * 256 ^ 2 + 0 'dims board for "reload" effect hehe
counter2 = counter2 - 1
END IF
LINE (xshot - 5, 430 - yshot)-(xshot, 420 - yshot), 8
LINE (xshot, 420 - yshot)-(xshot + 5, 430 - yshot), 8
LINE (xshot + 5, 430 - yshot)-(xshot - 5, 430 - yshot), 8
PAINT (xshot, 422 - yshot), 15, 8
LINE (xshot - 5, 430 - yshot + speed)-(xshot, 420 - yshot + speed), 0
LINE (xshot, 420 - yshot + speed)-(xshot + 5, 430 - yshot + speed), 0
LINE (xshot + 5, 430 - yshot + speed)-(xshot - 5, 430 - yshot + speed), 0
PAINT (xshot, 422 - yshot + speed), 0, 0
yshot = yshot + speed 'does bullet animation
IF yshot + 40 < (480 - y) AND yshot + 50 > (480 - y) THEN
IF xshot > x - 10 AND xshot < x + 15 THEN 'my collision detection
collision = 1 'this was a pain!, checks if bullet hits missle
END IF
END IF
points = points + 2 'points increase as missle is higher
END SUB
SUB ShotHit
x1 = (RND * 15) - xy#
y1 = (RND * 15) - xy#
FOR r# = 1 TO 8 STEP .1
CIRCLE (x - 5 + x1, y - 5 + y1), r#, col
IF col = 0 THEN
col = 12
ELSEIF col = 12 THEN col = 14 'does explosion animation
ELSEIF col = 14 THEN col = 0
END IF
loops = loops + 1: xy# = xy# + .001
FOR t = 1 TO 1000: NEXT t
NEXT
IF loops > 1000 THEN collision = 0: loops = 0
ppoints = ppoints + ((r / 2) * points) / 2 'calculates points (needs some work)
END SUB
SUB Shotsetback
yshot = 0: shot = 0: xshot = 0: points = 0: collision = 0 'resets varibles
END SUB
SUB StarField STATIC
IF starcount < 100 THEN
xstar = INT(RND * 640)
ystar = INT(RND * 480) 'Draw Stars
chance = INT(RND * 20)
IF chance = 5 THEN
PSET (xstar, ystar), 15
starcount = starcount + 1
END IF
END IF
counter = counter + 1
IF counter <= 31 THEN
PALETTE 15, sc * 256 ^ 2 + sc * 256 + sc
sc = sc + 2
ELSEIF counter > 31 THEN
PALETTE 15, sc * 256 ^ 2 + sc * 256 + sc 'fades star palette
sc = sc - 2
END IF
IF counter = 62 THEN counter = 0: sc = 1
END SUB
yet i'm having problems with speed...see, the computers at school have QB1.1 and are very slow, and i program here on a PIII 800 with QB4.5. so when i bring them to school to show them off, it runs pretty crappy. SOoo, my question is..is there a way in QB to determine the speed of a system so that i could make the delay in the program speedup/slow down in accordance to the speed of the computer??? this has been bugging me forever. and i know it can be done, because professional programmers must do this all the time for games and similar things, right???
also, there is one other problem...if the points reaches a certain number then there is an OverFlow error. i think this is because of DEFINT A-Z, but i'm not sure. is there a way to work around this??
so if there are any graphics geniuses out there or just anyone who can think of a way to make my program faster/more logical i would greatly appreciate some feedback
THANKS AGAIN ALL! s-)
DECLARE SUB ShotHit ()
DECLARE SUB Shotsetback ()
DECLARE SUB StarField ()
DEFINT A-Z
DIM SHARED xboard, xshot, yshot, shot, x, y, speed, sc, counter2
DIM SHARED bc, points, ppoints, r, collision, loops
DECLARE SUB Fire ()
RANDOMIZE TIMER
SCREEN 12: CLS
counter2 = 62: shot = 0: bc = 1: speed = 5: sc = 1 'Set initial values.
LINE (xboard + 320, 460)-(xboard + 20 + 320, 463), 1, BF 'Draw Initial Board(Paddle)
'***Variable Descriptions
' xboard = x pos of the board
' xshot = x pos of the board's shot (bullet) (used in shot SUB)
' yshot = y pos of the board's shot
' x and y = x and y pos of the missle: r = rate or speed of the missle
' sc = star color: counter = star palette counter
' bc = board color: counter2 = board palette counter
' points = acual calculated points, ppoints = displayed or printed points
' loops = times to loop the explosion
' speed = speed of bullet
'***Flags
' shot = tells that a shot has been fired
' collison = tells that a collision between missle and bullet has happened
' rite = tells that the right key has been pressed and animates board to right
' lehft = opposite of rite
DO
y = INT(RND * 400) + 1 'Gets random y pos and rate for missle
r = INT(RND * 3) + 1
IF r = 1 THEN 'Adds trail color according to speed.
trailcol = 9
ELSEIF r = 2 THEN trailcol = 4
ELSE IF r = 3 THEN trailcol = 14
END IF
SOUND INT(RND * 300) + (r * 100), 1
FOR x = 0 TO 650 STEP r 'Main Loop of Program
LOCATE 1, 10: PRINT "Speed ="; speed
LOCATE 1, 50: COLOR 9: PRINT "Points: "; ppoints 'Prints points and speed.
mcol = INT(RND * 9) + 6 'Random color of missle.(dum i know, i'll change it later, heh)
LINE (x, y)-(x, y), trailcol 'Draw Missle
CIRCLE (x, y), 3, mcol
CIRCLE (x - r, y), 3, 0
StarField 'Calls the sub to draw stars
key$ = INKEY$
IF key$ <> "" THEN GOTO getkey ELSE GOTO skipkey 'Skips if commands is nothing entered
'does this speeed up program? i don't know
getkey:
IF key$ = CHR$(0) + CHR$(77) THEN
rite = 1
ELSEIF key$ = CHR$(0) + CHR$(75) THEN 'gets right or left flag
lehft = 1
ELSEIF key$ = "x" AND shot = 0 THEN 'speed up or slow down bullet
IF speed = 10 THEN speed = speed ELSE speed = speed + 1
ELSEIF key$ = "z" AND shot = 0 THEN
IF speed = 5 THEN speed = speed ELSE speed = speed - 1
ELSEIF key$ = CHR$(27) THEN END
ELSEIF shot = 0 THEN
IF key$ = CHR$(32) THEN 'checks if shot is already fired and if not, then sets shot
SOUND 400, .5 'flag to 1 (or on)
shot = 1
END IF
END IF
skipkey:
IF rite = 1 THEN
LINE (xboard + 320, 460)-(xboard + 20 + 320, 463), 0, BF
xboard = xboard + 3
LINE (xboard + 320, 460)-(xboard + 20 + 320, 463), 1, BF
count = count + 1
IF count = 12 THEN rite = 0: count = 0 'does either left or right board
ELSEIF lehft = 1 THEN 'animation
LINE (xboard + 320, 460)-(xboard + 20 + 320, 463), 0, BF
xboard = xboard - 3
LINE (xboard + 320, 460)-(xboard + 20 + 320, 463), 1, BF
count = count + 1
IF count = 12 THEN lehft = 0: count = 0
END IF
IF shot = 1 THEN Fire 'calls shot sub if flag is on
IF collision = 1 THEN ShotHit 'calls shothit sub if flag is on
IF shot = 0 THEN 'brightens board if shot sub ends and board is dim
IF counter2 < 62 THEN '(my little "reload" effect)
PALETTE 1, 0 * 256 + counter2 * 256 ^ 2 + 0
counter2 = counter2 + 2
END IF
END IF
IF yshot > 440 THEN Shotsetback 'sets necesary variables back if board shot leaves screen
LINE (0, y)-(x, y), trailcol 'redraw missle to avoid erasing
FOR tt = 1 TO 18
FOR t = 1 TO 20000: NEXT t 'THIS IS THE SUCKY PART, lol, this is my delay loop
NEXT tt
NEXT x
LINE (0, y)-(x, y), 0 'erase missle after it leaves screen
LOOP
'LOCATE 1, 50: PRINT "x ="; x
'LOCATE 2, 50: PRINT "r ="; r
'LOCATE 3, 50: PRINT "xboard ="; xboard
'LOCATE 4, 50: PRINT "shot ="; shot 'used for debugging, REMed out for now
'LOCATE 5, 50: PRINT "xshot ="; xshot
'LOCATE 6, 50: PRINT "yshot ="; yshot
'LOCATE 7, 50: PRINT "y ="; y
'LOCATE 8, 50: PRINT "480 - y ="; 480 - y
SUB Fire
IF xshot = 0 THEN
xshot = xboard + 10 + 320 'sets x pos of board to x pos of bullet (middle of board)
END IF
IF counter2 > 30 THEN
PALETTE 1, 0 * 256 + counter2 * 256 ^ 2 + 0 'dims board for "reload" effect hehe
counter2 = counter2 - 1
END IF
LINE (xshot - 5, 430 - yshot)-(xshot, 420 - yshot), 8
LINE (xshot, 420 - yshot)-(xshot + 5, 430 - yshot), 8
LINE (xshot + 5, 430 - yshot)-(xshot - 5, 430 - yshot), 8
PAINT (xshot, 422 - yshot), 15, 8
LINE (xshot - 5, 430 - yshot + speed)-(xshot, 420 - yshot + speed), 0
LINE (xshot, 420 - yshot + speed)-(xshot + 5, 430 - yshot + speed), 0
LINE (xshot + 5, 430 - yshot + speed)-(xshot - 5, 430 - yshot + speed), 0
PAINT (xshot, 422 - yshot + speed), 0, 0
yshot = yshot + speed 'does bullet animation
IF yshot + 40 < (480 - y) AND yshot + 50 > (480 - y) THEN
IF xshot > x - 10 AND xshot < x + 15 THEN 'my collision detection
collision = 1 'this was a pain!, checks if bullet hits missle
END IF
END IF
points = points + 2 'points increase as missle is higher
END SUB
SUB ShotHit
x1 = (RND * 15) - xy#
y1 = (RND * 15) - xy#
FOR r# = 1 TO 8 STEP .1
CIRCLE (x - 5 + x1, y - 5 + y1), r#, col
IF col = 0 THEN
col = 12
ELSEIF col = 12 THEN col = 14 'does explosion animation
ELSEIF col = 14 THEN col = 0
END IF
loops = loops + 1: xy# = xy# + .001
FOR t = 1 TO 1000: NEXT t
NEXT
IF loops > 1000 THEN collision = 0: loops = 0
ppoints = ppoints + ((r / 2) * points) / 2 'calculates points (needs some work)
END SUB
SUB Shotsetback
yshot = 0: shot = 0: xshot = 0: points = 0: collision = 0 'resets varibles
END SUB
SUB StarField STATIC
IF starcount < 100 THEN
xstar = INT(RND * 640)
ystar = INT(RND * 480) 'Draw Stars
chance = INT(RND * 20)
IF chance = 5 THEN
PSET (xstar, ystar), 15
starcount = starcount + 1
END IF
END IF
counter = counter + 1
IF counter <= 31 THEN
PALETTE 15, sc * 256 ^ 2 + sc * 256 + sc
sc = sc + 2
ELSEIF counter > 31 THEN
PALETTE 15, sc * 256 ^ 2 + sc * 256 + sc 'fades star palette
sc = sc - 2
END IF
IF counter = 62 THEN counter = 0: sc = 1
END SUB