I'm creating a snake game, and I want to check if a point is already on, so I can let the snake die. I made the snake out of a while loop and point-on method.
You'll want to use pxl-Test(. It requires pixel locations instead of points, so your best bet is to change your code to use Pxl-On instead of Pt-On and the coordinates will match up.
If you don't want to knock out all your hard work thus far by moving to an integer-based coordinate system (which I'm in agreement with CVSoft in that it'd be faster-performing overall), the state of an actual point on any window can be identified with


Code:
:round((Ymax-Y)/ΔY,0→R
:round((X-Xmin)/ΔX,0→C
:If pxl-Test(R,C
:etc.


Edit: lirtosiast pointed out that it should be (X-Xmin)/ΔX, not (Xmax+X)/ΔX, as I had initially and mistakenly based it on Xmin = -Xmax, which isn't always true. The above code is revised to be correct.
Weregoose wrote:

Code:
:round((Ymax-Y)/ΔY,0→R
:round((Xmax+X)/ΔX,0→C
:If pxl-Test(R,C
:etc.


As someone who is utterly confused by this, can you explain what this does? Why go through all that if you just do a pxl-Test in the end?
Weregoose wrote:
If you don't want to knock out all your hard work thus far by moving to an integer-based coordinate system (which I'm in agreement with CVSoft in that it'd be faster-performing overall), the state of an actual point on any window can be identified with


Code:
:round((Ymax-Y)/ΔY,0→R
:round((Xmax+X)/ΔX,0→C
:If pxl-Test(R,C
:etc.


CVSoft wrote:
You'll want to use pxl-Test(. It requires pixel locations instead of points, so your best bet is to change your code to use Pxl-On instead of Pt-On and the coordinates will match up.

comicIDIOT wrote:
Weregoose wrote:

Code:
:round((Ymax-Y)/ΔY,0→R
:round((Xmax+X)/ΔX,0→C
:If pxl-Test(R,C
:etc.


As someone who is utterly confused by this, can you explain what this does? Why go through all that if you just do a pxl-Test in the end?


I changed everything to pxl-on and used pxl-test.
The code weregoose used was a work around for pxl-test, so you can use it with point-on
Thanks everyone!
comicIDIOT wrote:
As someone who is utterly confused by this, can you explain what this does? Why go through all that if you just do a pxl-Test in the end?

While pixel locations are fixed, (X,Y) points are arbitrary because of window offsets (Ymax-Y;X-Xmin) and scale (ΔY;ΔX), so that work needed to be done to determine if a "Pt-" coordinate is drawn.
SO, the X and Y are the coords you'd want to check and R and C are the corrected coordinates? I literally have no idea what that does and your reply doesn't help. Haha.

Like, why are we subtracting Y but adding X? How did/do we get Y and X? Why do we divide by the scale?
R and C here are Row and Column, which are the designated format for pxl- commands, whereas Pt- is dependent on the user-adjustable window into the X-Y plane. TI-83+ BASIC is capable of interfacing with the screen's pixels and Cartesian coordinates simultaneously.

The reason for subtracting Y in one axis and Xmin in the other (note the amendment in the earlier post) is that while both coordinate systems are in direct proportion horizontally, the vertical axis flips when you shift between these methods – pixel values increase downwards, but y-values rise above the x-axis.

On top of that, the "tracks" of the coordinate pairs (Row,Column) and (X,Y) run perpendicularly to one another:

Row follows Y (albeit running in reverse), and Column follows X.

(Vertical,Horizontal), but then (Horizontal,Vertical)!

So not only is it all flipped, but it is rotated – another quirk which must be taken into account when juggling both sets of coordinates...

And *I* divide by scale because I don't want my pixels to turn into rectangles! Rolling Eyes

Anything else?
That does help, thanks! It's been a long time since I've done anything with TI-BASIC and forgot there was a difference between Pt-On and Pxl-Test. Your description and the color coding helped jog my memory a bit.

Much appreciated.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement