Reply
Reply | Flag | Categorize
Xeda Elnara 09 Feb 2013 01:47
Xeda Elnara

Moderator

FA

Guest

I am going through and optimising some of your code and I can tell a bunch of it was well thought out :D
There are a handful of common optimisations that I can suggest:

  • Instead of using ~L+32 (I am assuming ~ is negative), you can use 32-L to save a byte
  • You can drop ending quotes and parentheses
  • To elaborate on what Silver said, DelVar is two bytes, so 0→Q is the same size as DelVar Q. However, DelVar and the other memory functions have a cool trick where you don't need to use a newline for the next command, saving a byte! For example, instead of this:
0→Q
1→P
---or---
DelVar Q
1→P

(both are the same size) You can do this:
DelVar Q1→P

Which is one byte less and essentially does the same thing.
  • Disp has a cool trick like Text( where each additional argument is treated like a new Disp. For example:
Disp "YOU LOSE..."
Disp "YOUR SCORE:"

Can instead be:
Disp "YOU LOSE...","YOUR SCORE:

Pretty neat, right?
  • One random trick optimisation was with this line:
If G=72 and Y-L+32≠1

I changed it in my head to:
If G=72 and Y-L+32-1

Which can be optimised to save two bytes:
If G=72 and Y-L+31

I am weird, so my methods are awkward. If you want to do the more logical version of my solution:
If G=72 and Y-L+32≠1
---use some algebra---
If G=72 and Y-L+32-32≠1-32
If G=72 and Y-L≠~31
---get rid of that negtive sign, it is using an unnecessary byte D: ---
If G=72 and Y-L+L≠~31+L
If G=72 and Y≠L-31

Yay :3 (I am in a math optimisy mood, sorry).
  • Often Repeat is more useful than While (in my opinion) because you don't need to set the variables before the loop. When I started learning TI-BASIC, I actually never learned what While did until I joined this site and saw people using it. I just found Repeat and figured out how it worked and I like it .-.

Here is how I convoluted it:

DelVar CDelVar P"      ;6 spaces here
Menu(Ans+"PONG"+Ans,"TWO PLAYER",2,"PRACTICE",P,"CHALLENGE",C,"QUIT",Q
Lbl C
1→C
2→U
Lbl P
1→P
Lbl 2
DelVar VDelVar WDelVar SDelVar T4→L
32→O
48→N
DelVar EDelVar Q1→D
StoreGDB 0
1→Xmin
95→Xmax
FnOff 
AxesOff
ClrDraw
If C or P
Then
Vertical 1
Vertical 2
End
Horizontal (-)10
Horizontal 10
For(I,1,93,92
For(J,32-L,L+32,1
Pxl-On(J,I
End
End
Repeat Q
getKey→G
If G
Then
If G=72 and Y-L+31
Then
Y-1→Y
Pxl-On(Y-L+32,1
Pxl-Off(Y+L+33,1
Else
If G=92 and Y+L≠29
Then
Y+1→Y
Pxl-On(Y+L+32,1
Pxl-Off(Y-L+31,1
Else
If G=45
Then
ClrHome
Disp "GAME PAUSED","[ENTER]: RESUME","[CLEAR]: QUIT
Repeat 30=abs(Ans-75
getKey
End
If Ans=45
1→Q
Else
If G=74 and T-L+31
Then
T-1→T
Pxl-On(T-L+32,93
Pxl-Off(T+L+33,93
Else
If G=94 and T+L≠29
Then
T+1→T
Pxl-On(T+L+32,93
Pxl-Off(T-L+31,93
End
End
End
End
End
End
N→A
O→B
If N=1 or N=93
Then
If not(C
Then
ClrHome
If N=1
V+1→V
If N=93
W+1→W
Disp "LEFT SCORE:
Output(1,13,V
Disp "RIGHT SCORE:
Output(2,14,W
Pause 
If V>9
Then
Disp "LEFT WINS!
1→Q
End
If W>9
Then
Disp "RIGHT WINS!
1→Q
End
32→O
DelVar E48→N
Else
ClrHome
Disp "YOU LOSE...","YOUR SCORE:
Output(2,13,U
If U>|LPONG(1
U→|LPONG(1
Disp "HIGH SCORE:
Output(3,13,|LPONG(1
Pause 
1→Q
End
End
If pxl-Test(O,N+D
Then
If C and U>2
Then
Vertical U-1
Vertical U
U+1→U
End
~D→D
Else
If pxl-Test(O+1,N+D
Then
~1→E
If N=2 or N=92
Then
~D→D
If C
Then
Vertical U-1
Vertical U
U+1→U
End
End
End
If pxl-Test(O-1,N+D
Then
1→E
If N=2 or N=92
~D→D
End
End
O+E→O
N+D→N
Pxl-Off(B,A
Pxl-On(O,N
End
Lbl Q
RecallGDB 0
ClrHome

I gave it a try and I like how you implemented the two player mode. Also, should the pixel be moving at an angle or just back and forth? If you want, I can put together a simple Pong engine so that you can compare it :D

Attachment:

Habstinat 09 Feb 2013 03:34
Habstinat

Included page "member:habstinat" does not exist (create it now)


Guest

Thank you so so much for your optimizations. I really can't express how much I appreciate it; I'm literally ecstatic right now.

Also, I may have forgotten to mention this, but the ball does move at an angle, but you have to "set it off" first by moving the paddle exactly one pixel away from the ball. This is kind of hard to explain until you do it once. I made it this way on purpose to give skilled players an edge; they'll have the precision to set off trick shots and once a trick shot is off, it can't be undone until the next ball. Haha, if you were playing without knowing that you probably weren't having a lot of fun :P

Attachment:

Make a reply:

To use the style buttons, click on the one you want, then press Ctrl+V.


This is the Redirect module that redirects the browser directly to the "http://snippets.wdfiles.com/local--code/code:url-title-with-slash-redirect/2#http://tibasicdev.wikidot.com/post:142" page.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 License.