Yeah. I saw where someone (forgive me for forgetting) was going to do a breakout, and it inspired me to release my hand written code for the fastest basic ball engine i have seen so far. Granted it moves in a predictable pattern, but it is fast enough that I made a pong game based around it that was actually fun to play. It only uses 4 variables and one label.

Code:
``` 1->A 1->B 1->C 1->D Lbl A Clrhome Output(A,B,"*" A+C->A B+D->B If A=8:-1*C->C If A=1:-1*C->C If B=16:-1*D->D If B=1:-1*D->D Goto A```

It is optimized as far as I can get it, and just the engine itself without a for( governor is extremely fast. The pong game mentioned above is more of a wall ball type of thing, I never got around to building an AI that was intelligent enough to provide a challenging game of pong. I also am in the process of creating a geometry program that is relatively simple, but useful to me already in many instances. It draws quadrilaterals and can Zoom standard, in, out, fit to box automatically, and quit to home with a press of a button with no slow downs. It took me a while to figure out how to implement the box function aswell since the ZoomFit wouldn't work since the program wasn't graphing an actual program. My math teacher said that there was no easy way to do this, and I want to show him but I is afraid

Brandon
change the goto loop with a while loop, and you have a good prog there.
Sorry, I don't know how, anyone care to enlighten me?
1->W
While W=1
<code>
End

That pretty much sums it up.
Yeah. I saw where someone (forgive me for forgetting) was going to do a breakout, and it inspired me to release my hand written code for the fastest basic ball engine i have seen so far. Granted it moves in a predictable pattern, but it is fast enough that I made a pong game based around it that was actually fun to play. It only uses 4 variables and one label.

Code:
``` 1->A 1->B 1->C 1->D While 1 Clrhome Output(A,B,"*" A+C->A B+D->B If A=8:-1*C->C If A=1:-1*C->C If B=16:-1*D->D If B=1:-1*D->D End```

With a label, the interpreter goes through and looks from the start to the label, with the while loop, it knows where to start.
This is how I did mine

Code:
``` 1->A 1->B 1->C 1->D While 1 Clrhome Output(A,B,"*" A+C->A B+D->B If A=8:-1*C->C If A=1:-1*C->C If B=16:-1*D->D If B=1:-1*D->D End```
he could always use repeat or a for( loop depending on his plan for exiting the loop
true there also, but he showed for an infinite loop, so while 1 is infinite.
Uh...
Code:
```1->A Ans->B Ans->C Ans->D While 1 ClrHome Output(A,B,"* B+Ans->B A+C->A C-2C(Ans=1 or Ans=8->C D-2D(B=1 or B=16->D End```
For the loop he would still have to have 1 stored to some sort of variable or else he would not have any way to exit the loop.
if he wanted to exit though. The original did not have an exit code in it, so my version did not either.
haveacalc wrote:
Uh...
Code:
```1->A Ans->B Ans->C Ans->D While 1 ClrHome Output(A,B,"* B+Ans->B A+C->A C-2C(Ans=1 or Ans=8->C D-2D(B=1 or B=16->D End```
Using the token Ans is slower than using the numerical constant 1 here.
haveacalc wrote:
Uh...
Code:
```1->A Ans->B Ans->C Ans->D While 1 ClrHome Output(A,B,"* B+Ans->B A+C->A C-2C(Ans=1 or Ans=8->C D-2D(B=1 or B=16->D End```

This code will run through the exact same routine every time; no randomness to the game. It will be kind of boring to keep watching a ball bounce around the screen in an infinite loop without moving the paddle at all (that was the problem with one of my friends versions of paddle on the homescreen).

Also, I'm reasonably sure that the B+Ans->B will be messed up (on any but the second loop, D-2D(B=1 or B=16->D will be written to Ans.

You can make a much better moving ball if you use the graph screen and use trig to make the ball move. However, trig is slow to compute, but not too slow...

Anyone know a way to make the trig stuff calculate faster (i.e. maybe only the first 2 digits)? Would changing the mode to something like Float 2 make it any faster?
If you limit the ball to, say, 0,30,60,90, etc, you can use lists and make it go MUCH faster
b-flat wrote:
haveacalc wrote:
Uh...
Code:
```1->A Ans->B Ans->C Ans->D While 1 ClrHome Output(A,B,"* B+Ans->B A+C->A C-2C(Ans=1 or Ans=8->C D-2D(B=1 or B=16->D End```

This code will run through the exact same routine every time; no randomness to the game. It will be kind of boring to keep watching a ball bounce around the screen in an infinite loop without moving the paddle at all (that was the problem with one of my friends versions of paddle on the homescreen).

I know... I was simply improving upon the code posted by BrandonB (and later rivereye).

b-flat wrote:
Also, I'm reasonably sure that the B+Ans->B will be messed up (on any but the second loop, D-2D(B=1 or B=16->D will be written to Ans.

You're reasonably wrong. I wanted D to be added to B. Everything works fine.
KermMartian wrote:
If you limit the ball to, say, 0,30,60,90, etc, you can use lists and make it go MUCH faster

Code:
``` {0,30,60,90 -> lTAN For(i,1,4 tan(lTAN(i -> lTAN(i End ```

To move the ball:
(A is degrees away from horizontal, D is direction and speed, lPOS is current coordinates on graph screen {x,y})

Code:
``` lTAN(abs(A)/30+1 -> B lPOS(1) + D -> lPOS(1 lPOS(2) + DB -> lPOS(2 ```

Then you could expand lTAN to more values, say every 15 degrees instead of every 30, and probably still be in okay shape. Just remember to change line 1 of the mover.
Yes if you store all your possible trig values to a list and just navigated through that, its around 3x faster then trig funtions.
Ah yes, then it would only have to compute each angle once so you would only be adding/subtracting to 1 variable, which would be much faster.

Also, I don't use degrees and assuming that you want a minimal number of errors I would strongly recommend removing the 90 from that lTAN

I shall try this out in my old paddle game that a friend has been begging me to fix for over a month now.

@haveacalc: you're right; I didn't read through the code very carefully. I was thinking that you wanted to make a game like breakout, where you have the paddle at the bottom and hit the ball around the room, not a game like pong.
Thank you I had not noticed that 0,30 and 60 are not a lot of options, so you could change it to 15-degree increments. And if you wanted to go all the way you could say (pi)/6, (pi)/4, etc. Or just go back to the HOME screen and type 15(degrees) in radian mode and keep the first two decimals, if you're lazy like I am and didn't memorize the unit circle in trig.

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.

»
» 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