Page 1 of 3

turtle position

Posted: Sun Aug 13, 2023 3:38 pm
by stevepoole
Hi All,
Is there any way of finding out the current turtle x and y positions, (using QPC2) ?

This would be very useful in a program I am developing... on holiday, and without all my docs !

Steve.

Re: turtle position

Posted: Sun Aug 13, 2023 4:31 pm
by tofro
The graphics cursor x and y (so, effectively the turtle position) is (together with the pen up/down state and the current turtle angle) in the SuperBasic channel table (where n is the SuperBASIC channel number):

Code: Select all

(n*CH.LENCH+BV_CHBAS(A6)) (A6)
The format of each table entry is as follows:
$00 long 		the channellD
$04 float		current graphics cursor (x)
$0a float 		current graphics cursor (y)
$10 float 		turtle angle (degrees)
$16 byte 		pen status
Best have a look at the Technical guide, page 55.

Re: turtle position

Posted: Sun Aug 13, 2023 6:09 pm
by dilwyn
As I haven't used the turtle commands much, I had to have a tinker. The safest way I could think of from SBASIC to read these is with PEEK_F:

x = PEEK_F(\$30\$04) : REMark graphics x coordinate
y = PEEK_F(\$30\$0A) : REMark graphics y coordinate
angle = PEEK_F(\$30\$10) : REMark turtle angle in degrees
pen_status = PEEK(\$30\$16) : REMark 0=penup, 1=pendown

The above work simply with channel #0. Add $28*channel_number after the second $ for other channel numbers, e.g.

DEF FN ANGLE_VALUE(#channel)
RET PEEK_F(\$30\$28*channel+$10)
END DEF ANGLE_VALUE

$28 being the length of a given channel definition block (not sure of this is fixed on SBASIC or not).

Corrections\improvements\criticisms welcome as I'm trying to learn something new.

EDIT: the "angle = PEEK_F..." example above had a typo, missed out one of the backslash characters, now amended.

Re: turtle position

Posted: Sun Aug 13, 2023 6:18 pm
by dilwyn
I forgot to mention that since Turbo Toolkit has its own PEEK_F command, which doesn't support the SBASIC extended forms, it may replace the SBASIC definition for the indirected versions (using the $indirection), so it may cause these PEEK_F functions to appear to misbehave with bad parameter errors.

Re: turtle position

Posted: Mon Aug 14, 2023 8:12 am
by stevepoole
Many thanks Dilwyn,

It is odd that Sinclair did not implement such vital instructions at the outset !

Now I have been able to debug my holiday Amusement Park program, Penny_Drop_bas, the prototype being herewith.

Unip, Lrun and watch the demo. To play, use the '4' key to move the penny left, or '6' to move right. Improve your timings....

And that's it ! Please let me know if you have any problems. (Prototype Tested ok under QPC2).

Steve.
Penny_Drop.zip
(1012 Bytes) Downloaded 36 times

Re: turtle position

Posted: Tue Aug 15, 2023 5:05 am
by stevepoole
Hi Folks,

Just rewrote the program so that it should work under any SMSQ/E system, not just QPC2....

Steve.
Penny_Drop2.zip
(1.06 KiB) Downloaded 45 times

Re: turtle position

Posted: Wed Aug 16, 2023 6:43 am
by stevepoole
Hi Again,

Here is the fully commented code, rewritten using more meaningful mnemonics....

Steve.
Penny_Drop3.zip
(1.48 KiB) Downloaded 43 times
P.S: (This is still a prototype. I may make the game more complex soon).

Re: turtle position

Posted: Wed Aug 16, 2023 8:56 am
by Derek_Stewart
Hi Steve,

Penny_Drop3_bas stopped with an Invalid Parameter at Line 1010
QPC2_Penny_Drop3.png
QPC2_Penny_Drop3.png (7.02 KiB) Viewed 835 times

Re: turtle position

Posted: Wed Aug 16, 2023 10:16 am
by tofro
Derek,

that's likely when you have Turbo Toolkit loaded. It masks the SBASIC PEEK_F with an own implementation that lacks some features to the original. Was mentioned by Dilwyn some posts above.

Re: turtle position

Posted: Wed Aug 16, 2023 10:24 am
by stevepoole
Hi Derek,

Just reloaded the Penny_drop3_bas from the forum and it ran ok under QPCv5.02.... (See Screen_shot).

Dilwyn warns that if you have Turbo TK loaded, it has its own PEEK_F which can cause problems ?

By the way, my QPC2 is configured at 512x256, but I doubt if that may be the cause....

Sorry if this is not helpfull !

Steve.
Capture d’écran (74).png