Picture Slide

By Roland Waddilove

Originally published in EUG #64

I can remember as a child (before the days of home computers) playing with a little plastic puzzle made up of letters or numbers which could be slid about a frame. The idea was to get the letters or numbers in order, a task which sometimes took hours and was very frustrating.

Everything is automated now, of course, so we can play the same game on our micros. It's not unusual to find this type of puzzle on the BBC or Electron as it's fairly easy to write a program to move letters about on a grid, but this program is different in that instead of using letters or numbers, a grid is drawn over a picture, and the parts of that are slid about.

  A 3D perspective picture is drawn using Mode 2 graphics and all eight colours (the flashing combinations aren't used). A grid is then drawn over the picture and the sections mixed up. You can decide on the level of difficulty, i.e. the degree to which the parts are jumbled (which is also partly random), and then watch it carried out.

Your task is simple. Restore the picture to its original form by sliding the sections back into place. Sounds easy, doesn't it? Try it on level 9!

  The program was written on an Electron and will run on a BBC with OS 1.2 and BASIC 2. Because of the Beeb's higher processing speed, Beeb owners will need to add the following line to slow the program down enough to allow you to use the game keys correctly:

   185 FOR N=0 TO 250:NEXT


Program Notes

There are many interesting routines that could be incorporated quite easily into your own programs, such as the large letters procedure, sideways scroll of the title, and the procedure to scroll messages in from the side, plus the error handling routine.

The program is structured and does not contain any GOTOs or GOSUBs - line numbers are therefore irrelevant and the procedures could be entered in any order. Any picture can be used, so feel free to draw your own: it's all inside a graphics window so you can't go wrong.

 
PROCinitialise   Switch off the cursor and set the colours 8 to 14 to white. The first 20 letters of the alphabet are placed at &A00, to record the order of the sections of the picture. &6980 is the address of the top left hand corner of the section with the flashing cross. Set up the graphics window.
 
PROCdraw_grid(colour)   Draw the grid over the picture. The colour is the same of the cross.
 
PROCdraw_picture   Draw the picture. Replace this with your own if you desire. After drawing the sky the origin is moved to 800,600 where the sun is.
 
PROCbig(x%,y%,word$,colour)   word$ is printed in characters 8 lines normal size at x%,y%. This is worth studying as it can be used to print various sized characters. The dot pattern is read into zero page by calling OSWORD with A=10. A character is designed and printed for each row.
 
PROCswap   The appropriate letters are swapped at &A00, then the two sections of picture are exchanged by calling the machine code routine.
 
PROCassemble   Assemble the two machine coe routines. The first swaps two sections of the picture, the second scrolls the title.
 
PROCslide   Find out which keys are being pressed.
 
PROCscroll(Y%,word$,colour)   Scroll word$ left onto the screen at line Y%.
 
PROCmix_up   Input the level of difficulty and mix up the sections.
 
PROChurrah   Make appropriate sounds. Work out score. Ask if you want to play again.
 
PROCinstructions   Print the large title and call the machine code to scroll the graphics window. Print the instructions.
 
PROCerror   The error handling routine. This can be used in any program. If ESCAPE is pressed you have the choice of ending the program or starting again. If you haven't pressed ESCAPE there must be an error so PROCstop is called.
 
PROCstop   Called if there is an error. The line with the error is printed by defining a function key to list it and placing the code for the key in the input buffer. If the error was "No room" and PAGE is not &E00 (e.g. if you have disc drives), the program is relocated.

Variables

K%, Q%, J%, X%, Y%-Used mainly as loop counters
done-A flag to show whether it has been done
level-The difficulty level
score-The score
address-The address of the top left hand byte of the section of picture with the cross
m%, n%-The co-ordinates of the section with the cross.

A string is placed at &A00. This is checked to see whether the puzzle has been completed.

Roland Waddilove, Acorn User January 1985