I was bored the other day so I started making a small flea game (I remember it from when I played Runescape, it was one of the Jagex games) and I decided I needed a drawing routine to use for drawing walls while the fleas are moving (I will try to have that up tomorrow or the next day)

Here is a version of it that I made for testing, tell me if you see any optimizations or errors (besides the extra parenthesis in the pxl-on, I know =P

The program starts at 0,0 and from there it uses the keynumbers 51-95 to draw in a 5-by-5 square that you move with the arrow keys (put it in your calculator and try it out =D)


I is the x axis
J is the y axis
K is the input


Code:
:DelVar IDelVar KWhile 1
:getKey→K
:If Ans>50 and Ans<100
:Pxl-Change(I5-5+(round((K-1)/10,0)),(J5-5+(fPart(K/10)10-1
:J-(K=24)1→J
:I-(K=25)1→I
:J+(K=26)1→J
:I+(K=34)1→I
:If I=‾1:11→I
:If I=12:DelVar IIf J=0:18→J
:If J=19:1→J
:End
Generated by SourceCoder (http://www.cemetech.net/projects/basicelite/sourcecoder.php)
© 2005 Cemetech (http://www.cemetech.net)
(Don't worry Kerm, I didn't leave it out =D)


Here is my favorite line

Code:
:Pxl-Change(I5-5+(round((K-1)/10,0)),(J5-5+(fPart(K/10)10-1



Code:
(round((K-1)/10,0))
determines the 10's place (so from 5-9 for this)

Code:
(fPart(K/10)10-1)
determines the 1's place (from 1-5 for this)

I am almost 100% sure that it is faster and more optimized than using a bunch of if statements to find the key that was pressed and respond to it.

Code:
:DelVar IDelVar KWhile 1
:getKey→K
:If Ans>50 and Ans<100
:Pxl-Change(I5-5+(round(.1K-.1,0)),(J5-5+(10fPart(.1K)-1 
:J+(ans=26)-(ans=24→J
:I+(K=34)-(K=25→I
:I+2(I=-1)-12(I=12→I
:J+18not(J)-18(J=19→J
:End

One thing: what is the purpose of the ans>50 and ans<100?
So the person has to press a button with a key value of greater than 50 and less than 100 to actually draw anything (so the 5th row of keys to the 9th row of keys).

It draws in 5x5 squares.
You can condense the movement commands into two lines & save a few bytes.


Code:
:J-(K=24)+(K=26->J
:I-(K=25)+(K=24)->I


Seems fairly good, not sure what I would use it for, but very nice!

Wait, nevermind, Kuro already suggested that.

Yeah, that and the if statements at the end can be improved.
Is there a guide somewhere to using those types of commands? I don't quite understand but from what I can it seems that it is just a condensed conditional. Can it subtract and add other numbers than 1?
Of course it can Very Happy

Here is the explanation:

If you have the code


Code:
:a*b
, where * is a a comparison thingie such as =, >, <

the calculator will return 1 if the statement is true, or 0 if the statement is false.

Thus, to change it by more than 1, multiply it by some constant instead, like


Code:
:J+6(K=34)-6(K=25->J


Does this explain it enough? It basically treats it as a Boolean, but instead of true/false, the calc uses 1/0.

EDIT: Whoops, typo int the code
Harq: did you ever take a look at the 1337 guide?
http://www.ticalc.org/archives/files/fileinfo/369/36993.html
oooooh so it pretty much just multiplies the constant by 0 or 1 depending on whether it is true or not

Good to know =D


P.S. Yes I have, but maybe a different one than you are thinking of... (I pretty much used that to learn ti-basic =P)
  
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