turtle position
-
- Super Gold Card
- Posts: 722
- Joined: Mon Nov 24, 2014 2:03 pm
turtle position
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.
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
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):
Best have a look at the Technical guide, page 55.
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
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Re: turtle position
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.
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.
Last edited by dilwyn on Mon Aug 14, 2023 9:05 am, edited 1 time in total.
Reason: Corrected missing backslash in one of the examples.
Reason: Corrected missing backslash in one of the examples.
--
All things QL - https://dilwyn.qlforum.co.uk/index.html
All things QL - https://dilwyn.qlforum.co.uk/index.html
Re: turtle position
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.
--
All things QL - https://dilwyn.qlforum.co.uk/index.html
All things QL - https://dilwyn.qlforum.co.uk/index.html
-
- Super Gold Card
- Posts: 722
- Joined: Mon Nov 24, 2014 2:03 pm
Re: turtle position
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.
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.
-
- Super Gold Card
- Posts: 722
- Joined: Mon Nov 24, 2014 2:03 pm
Re: turtle position
Hi Folks,
Just rewrote the program so that it should work under any SMSQ/E system, not just QPC2....
Steve.
Just rewrote the program so that it should work under any SMSQ/E system, not just QPC2....
Steve.
-
- Super Gold Card
- Posts: 722
- Joined: Mon Nov 24, 2014 2:03 pm
Re: turtle position
Hi Again,
Here is the fully commented code, rewritten using more meaningful mnemonics....
Steve. P.S: (This is still a prototype. I may make the game more complex soon).
Here is the fully commented code, rewritten using more meaningful mnemonics....
Steve. P.S: (This is still a prototype. I may make the game more complex soon).
-
- Font of All Knowledge
- Posts: 3997
- Joined: Mon Dec 20, 2010 11:40 am
- Location: Sunny Runcorn, Cheshire, UK
Re: turtle position
Hi Steve,
Penny_Drop3_bas stopped with an Invalid Parameter at Line 1010
Penny_Drop3_bas stopped with an Invalid Parameter at Line 1010
Regards,
Derek
Derek
Re: turtle position
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.
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.
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
-
- Super Gold Card
- Posts: 722
- Joined: Mon Nov 24, 2014 2:03 pm
Re: turtle position
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.
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.