Re: Dynamic Sprites
Posted: Sun Aug 15, 2021 12:32 pm
From BASIC, the use of 20ms PAUSE units is probably the best the QL can do. AFAIK, there is only a 20ms timer at best. Plus, if you press a key, the pause is cut short and things speed up.Tinyfpga wrote:Thank you for your short, simple and informative answer. I have been trying to write some "crap" games for the 2021 competition, mostly to learn how to program in SBASIC.
My best, so far, is a bat and ball game in which the animation consists of repeatedly writing characters to the screen. My main problem with this process is that I have use the keyword PAUSE, with a minimum pause of 20msecs, to control the program flow. My animations either run flat out (no pause and too fast), or too slowly (20 msec pause).
Is there a fine grained way of controlling the flow of an SBASIC program? I know this is off-topic but my question seems
too trivial for a new topic.
An alternative would be to use a SUSPEND type extension, e.g. http://www.dilwyn.me.uk/tk/suspend.zip. This 'suspends' BASIC for 20ms ticks, but unlike PAUSE doesn't get cut short by a keypress, so animation can be smoother.
The only other practical way of introducing pauses shorter than 20ms is to use time-wasting loops such as FOR/END FOR loops, but it has two disadvantages.
(1) it puts a load on processing during the pauses (affects multitasking), and
(2) it varies from system to system, so you need a method of working out how long any delays or time-wastes need to be. You could probably do this by waiting for the clock to change to the next second, then run a loop until the clock changes again to see how many loops are needed to fill one second on this particular system, then use this information to introduce suitable PAUSE or SUSPEND statements. Clumsy and extremely approximate.
A possible third way of slowing things down is for the game to be in a loop and you can set a variable to control every how many iterations of the loop are executed as game, and how many as time wasters, by prompting the user to enter a speed factor. I did something like this in the game I submitted to the crap games competition. It is clumsy and fiddly to program, admittedly, but relieves you of timing responsibility by letting the user enter a "percentage" slowdown. In this example, you enter a slow-down factor from 0 to 1000 with 0 being fastest game, 1000 being slowest (on a very fast PC with QPC you may need even higher than 1000 to slow things right down!).
To keep things simpler for the user, you could change the first line to enter a percentage factor and multiply it into the range you want, e.g. INPUT"Enter % slowdown ';speed : LET speed = 10*speed
A little demo routine to illustrate this (untested!)
Code: Select all
CLS : INPUT"Speed (0-fast to 1000-slow) ?";speed
counter=0
REPeat game
IF INKEY$ = CHR$(27) THEN EXIT game :REM ESC to quit
counter = counter+1
IF counter > speed THEN NEXT game :REMark waste some time
counter = 0 : REMark reset time waster
REMark main game code here
PRINT"*"; : REMark just something to show demo speed
END REPeat game