top of page

LOADING...

SCREECH

Vintage & Modern Tech Blog

Stephen Nichol

< FIVE MINUTE BASIC #6 - Easier Animation of Multiple Graphics


More than one User Defined Graphic (UDG) to animate? Here's a quick routine to move multiple UDG's using just one FOR...NEXT loop.

Note - the letter's A,B, and C (in quotes in this program) may be turned into custom graphics by using the routines in the ZX Spectrum owner's manuals for the various models. For example pages 32 and 33 of the 48k + manual, pages 89 and 90 of the +2 manual etc.

1 REM Five Minute BASIC #6

2 REM Algebraic Animation

3 REM Multiple UDGs animated in the same FOR...NEXT loop

4 REM by Stephen Nichol 2014

10 LET y=11

20 LET x2=26

30 FOR x=1 TO 27 STEP 1

40 PRINT AT y,x;"A"

50 PRINT AT y,x-1;" "

60 PRINT AT y-2,x;"B"

70 PRINT AT y-2,x-1;" "

80 PRINT AT y+3,x2;"C"

90 PRINT AT y+3,x2+1;" "

100 LET x2=x2-1

110 PAUSE 5

120 NEXT x

Explanation/Refresher (if required)

Lines 1 to 4 are REMarks and do not affect the running of the program.

Line 10 sets the value of Y (the up/down value) to 11, which is the middle of the screen.

Line 20 sets the value X2 at the opposite side of the screen (the right side) to the starting position defined at the beginning of the FOR...NEXT loop in line 30.

Line 30 tells the computer to start a loop where x(the left/right value) begins at 1 and runs through to 27 in steps of 1 (so, the computer will count 1,2,3,4 all the way through to 27).

Line 40 PRINTs the first User Defined Graphic (represented by "A") at the y position stated in line 10 and the X position stated in line 30.

Line 50 PRINTs a blank space at the previous location of "A" in order that a trail is not left as it moves (you may want to delete this line temporarily so that you can see what happens if you run the program with line 50 not included).

Lines 60 and 70 do the same as lines 40 and 50 but, by changing 'y' to 'y-2', the User Defined Graphic represented by "B" is printed 2 lines higher up on the screen (REMEMBER: y,x co-ordinates with y running down the screen for low resolution text and graphics. x,y co-ordinates with y running up the screen for high resolution graphics).

A similar method is used in Lines 80 and 90 to print UDG "C" lower down the screen by using 'y+3', however - we use x2 (created in line 20) to place UDG "C" at the opposite side - the right side - of the screen to where it would have been if we used just x.

Line 100 moves UDG "C" one character cell to the left.

On a PAL screen, the ZX Spectrum refreshes 50 times a second. So, by adding pause 5 to the program in line 110 we are pausing for one tenth of a second, just to slow things down a bit so they aren't too fast to appreciate.

Line 120 tells the computer to go back to line 30 until the loop has occured enough times for X to equal 27. Since we are going in steps of 1, the loop will occur (27-1) = 26 times.

33 views

Related Posts

See All
bottom of page