Code: Select all
asteroidx = asteroidx + 1
Code: Select all
asteroidx = asteroidx + 1
Code: Select all
Delay = Timer
...
...
..
...
IF Timer - Delay > WhatDelayYouWant THEN
asteroidx = asteroidx + 1
Delay = Timer
END IF
IF WhatDelayYouWans = 1 it waits for a second.DWolf wrote:yea that works, But even if I put WhatDelayYouWant down to 1, it now moves too slowly lol. Any ideas?
Code: Select all
CLS
DIM Delay, DelayCheck AS DOUBLE
Delay = .1 ' 0.1 seconds now for value of wanted delay
DelayCheck = TIMER ' this moment timer value
PRINT "Start time"; TIMER
DO
LOOP UNTIL TIMER > (DelayCheck + Delay)
PRINT "Finished waiting for;"; Delay; " seconds."
PRINT "End time"; TIMER
SLEEP
Code: Select all
wait &H3DA
So, just because it's QBASIC we should take the simplest most corrupt way of doing things? You "get real"Quibbler wrote:What!! anybody would think that this was a C++ forum get real this is qbasic.
If you're soooo fussy you could calibrate the delay loop against TIMER first.
There are other ways of getting short delays but they are much more involved like reading the screen refresh or you could even change the clock divider. You can even read the cpu clock (but again this is machine dependent).
Code: Select all
INPUT "Press <ENTER> when you think you have delayd meteors moving enough";variablehere
MeteorX = MeteorX + 1
Code: Select all
'This function gauges the speed of the current machine. The most cpu-intensive part of frame processing in this video program is the loading of the palette and the video frame to the screen. Gauge the speed of the current cpu by repeatedly processing a single frame. Note that other programs running in the background can affect the speed of loading from the test file. For best results, run this test without other programs running in tandem.
SUB getSpeed (file$)
asecs = 0
'More test cycles = more accurate results.
cyclesToTest = 800
'Get the current time.
a$ = TIME$
'Break down the current time into total seconds for the current day to avoid issues with gauging near the top of the hour or top of the minute.
ot = INT(VAL(MID$(a$, 1, 2)) * 360) + INT(VAL(MID$(a$, 4, 2)) * 60) + INT(VAL(MID$(a$, 7, 2)))
'Load in the test frame and its palette for as many cycles as previously indicated.
FOR x = 0 TO cyclesToTest
'Call a function that loads in the palette from the test file.
loadPalette file$
'Load the frame to the screen.
DEF SEG = &HA000
BLOAD file$ + sshExt$, 0
DEF SEG
NEXT
'Check the time again to see how long it took to run the test cycles.
'Get current time.
a$ = TIME$
'Break down time into seconds again.
t = INT(VAL(MID$(a$, 1, 2)) * 360) + INT(VAL(MID$(a$, 4, 2)) * 60) + INT(VAL(MID$(a$, 7, 2)))
'Check the difference to get the total number of seconds it took to run the test.
secs = t - ot
'Calculate this cpu's max frame rate by dividing the cycles tested by the amount of time it took to run the test cycles.
maxFps = INT(cyclesToTest / secs)
'Now find out how many empty FOR/NEXT loops this cpu can run in a second.
'Initialize the seconds variable.
secs = 0
'Test for about 10 million cycles; the higher the number of cycles, the more accurate the results.
cyclesToTest = 9999999
'Get the current time.
a$ = TIME$
'Break down the time into seconds.
ot = INT(VAL(MID$(a$, 1, 2)) * 360) + INT(VAL(MID$(a$, 4, 2)) * 60) + INT(VAL(MID$(a$, 7, 2)))
'Run the test.
FOR x = 0 TO cyclesToTest
NEXT
'Get the current time.
a$ = TIME$
'Break down the time into seconds.
t = INT(VAL(MID$(a$, 1, 2)) * 360) + INT(VAL(MID$(a$, 4, 2)) * 60) + INT(VAL(MID$(a$, 7, 2)))
'Calculate the difference to find the total amount of time it took to run the test (in seconds).
bsecs = t - ot
'If it took the cpu more than a second to run the test, calculate the cycles per second.
IF secs > 0 THEN
'Calculate the number of cycles the cpu has to run to delay one second.
cps = INT(cyclesToTest / secs)
ELSE
'This cpu is crazy fast. Just assume a cycles per second rate of about 10 million.
cps = 9999999
END IF
'Since we want to be able to adjust the frame rate of our video, calculate cycles per frame for this cpu.
'This number can be used to accurately enforce a user-designated frame rate.
cpf = INT(cps / maxFps)
END SUB
Code: Select all
sub delay(dlay!)
stime! = timer
Do
loop until Timer - stime! > dlay!
urr hello? can you read? I said I got it working...nkk_kan wrote:hmmm.. How about this one?
[/code]Code: Select all
sub delay(dlay!) stime! = timer Do loop until Timer - stime! > dlay!
Need more information. Could you display the lines of code that do the following:DWolf wrote:Alright thats sorted now, thanks everyone. One last thing, I've made it so my Spaceship can't move through an asteroid or any "0". Anyway after It moves along ther screen the asteroid leaves behind an invisible trail o "0"'s. I thought I printed over them with nothing, but I can't move my spaceshi[p through anywhere the asteroid has been. Any ideas?
Code: Select all
CLS
'Set spaceship and meteor position
y = 2
x = 1
meteorx = 38
meteory = 2
Delay = TIMER
'Map
COLOR 15
PRINT "0000000000000000000000000000000000000000"
PRINT " "
PRINT " "
PRINT " "
PRINT " "
PRINT "0000000000000000000000000000000000000000"
'Check for spaceship moving
DO
a$ = INKEY$
checky = y
checkx = x
checkmx = meteorx
checkmy = meteory
LOCATE y, x
COLOR 0
PRINT ">"
IF a$ = "w" AND y - 1 > 0 THEN checky = y - 1
IF a$ = "a" AND x - 1 > 0 THEN checkx = x - 1
IF a$ = "s" THEN checky = y + 1
IF a$ = "d" THEN checkx = x + 1
'Print Meteor
LOCATE meteory, meteorx
COLOR 0
PRINT "00"
'Move Meteor
IF TIMER - Delay > .1 THEN
meteorx = meteorx - 1
Delay = TIMER
END IF
IF SCREEN(checky, checkx) <> 48 THEN
y = checky
x = checkx
END IF
'Make sure the spaceship can't leave the area
IF x > 40 THEN x = 40
LOCATE y, x
COLOR 15
PRINT ">"
LOCATE 10, 10
'Resets meteor position
IF meteorx < 1 THEN meteorx = 40
LOCATE meteory, meteorx
COLOR 15
PRINT "00"
LOOP UNTIL a$ = "q"
Code: Select all
'Print Meteor
LOCATE meteory, meteorx
COLOR 0
PRINT "00"
Code: Select all
IF SCREEN(checky, checkx) <> 48 THEN
y = checky
x = checkx
END IF
Code: Select all
LOCATE meteory, meteorx
PRINT " "
Code: Select all
LOCATE meteory, meteorx
PRINT SPACE$(2)
Code: Select all
LOCATE meteory, meteorx
COLOR 0
PRINT "**"
Code: Select all
LOCATE meteory, meteorx
COLOR 0
PRINT ">>"