So I'm basically trying to code a TI-Basic version of the DVD logo bouncing around the screen, and I'm having some trouble coding the collision detection, and selecting a direction for the logo to go from the start. If anyone could offer some help, I would appreciate it.
I made a program that does this! It was a big hit with my friends and is very fun to watch.
The way I did it was use the variable A to be the left/right speed and the variable B to be the up/down speed. I used X and Y to keep track of the position of the logo. In a loop I added A to X to get the new X position and B to Y to get the new Y position, then displayed the logo at X and Y. If the X value (or the Y value) ever equaled the position of the border, I first said -X -> X, so the speed became negative and it would "bounce" off the wall and travel the other way.
Do you have an example of the collision/speed code I could see? I wouldn't copy it exactly as you wrote it but copy the basic idea of it.
Sure! Here is my program, which uses the home screen (although the same ideas apply to the graph screen). It will run until you press any key.
ClrHome
randInt(2,12→X
randInt(2,7→Y
1-2randInt(0,1→A
1-2randInt(0,1→B
Repeat K
getKey→K
If max(X={1,13
A→A
If max(Y={1,8
B→B
Output(Y,X,"
X+A→X
Y+B→Y
Output(Y,X,"TI84
rand(25
End
ClrHome
It displays "TI84" as the logo, but you could change that to say whatever you want. You might have to change the numbers for the borders to make it look right, though. And the "rand(25" makes the calculator wait half a second in between each movement, which you could mess with to make it run faster or slower.
Thank you I really appreciate it. Just curious, what does the 1-2 before selecting the speed of the logo do?
Also I tried out the code, and every time the logo hits a wall, it just says there's a domain error. Would this be an issue with the code, or is it something else?
Oops, it appears the negative signs didn't copy over correctly. It should say
If max(X={1,13
-A→A
If max(Y={1,8
-B→B
The 1-2 thingy at the beginning will make A and B start as either 1 or -1, so it will start moving in a random direction, either up or down and either left or right!
Just a quick note/optimization, there's no reason to store getKey in K if you don't need the value for anything. Just do Repeat getKey
Oh, of course! Thanks for the optimization! :)
I'm also still getting the same error: domain message, but that's probably just something with my calculator, and not the code.
Also, is there a way to make it so the logo doesn't eventually fill up the whole screen? Like basically once the logo is copied, it deletes the original it was copied from?
Yes, that is what the Output line does right before the X and Y values are changed. Sorry I didn't specify, but there are 4 spaces after the quotes to cover up the 4 characters in the logo.