Omnimaga
Calculator Community => TI Calculators => TIBASIC => Topic started by: MRide on September 09, 2010, 10:36:39 pm

Hello, I am trying to write a bit of code to simulate a character jumping.
I have done that. Now what I want to do is have a way to reverse gravity when the user presses a button. So the character will "fall" up and land on the ceiling. I have only partially succeeded in this. Hitting the button causes the character to float upward (or downward) until it is three spaces away from the floor/ceiling, and then it skips the next two spaces and lands. I have been staring at my code and for some reason, cannot see the problem. Help, please?
Also, here is my code (part of it came from meishe's jumping code)
ClrHome
7>X:Ans>S //X is actually the Y coord., and S is the initial Y coord. that you jumped from
1>Y:Ans>B //Y is the X coord. ,and B is either positive or negative one, depending on if the gravity is reversed
Delvar ARepeat 0 //A controls whether you move up, down, or not at all
getKey>K
If Ans or A!=0
Text(1,7X,6(Y1),"_ //one space
Y+(K=26)(K=24
Ans15((Ans=16)not(Ans>Y
XBA>X
A2(X=(SB3>A
If X=S
DelVar A
If not(A
X>S
B2(K=31 and B=1)+2(K=31 and B=1>C
If B!=C:Then
1>A
C>B
If B=1
1>S
If B=1
7>S
End
Text(1,7X,6(Y1),"X
A+(K=21 and X=S>A
rand(8
End
I realize this isn't very optimized. That will be fixed.

Mhmm... Raylin might be great help there. He wrote a game involving inverting gravity

Well I haven't gone over all your code but that first If can be just If Ans I believe. Also, is that ClrHome supposed to be a ClrDraw?
Edit:
That first thing was wrong. I thought that "A" was an "Ans." In which case it'd be If Ans or A which I believe can be further optimized.

Hold on...

Well I haven't gone over all your code but that first If can be just If Ans I believe. Also, is that ClrHome supposed to be a ClrDraw?
Yeah, like I said at the bottom of my post, this isn't optimized. I'll go back over it when I get everything working.
Oh, yeah, it is.

Okay. I was going mad.
This is my gravity reversing code.
If K=21:12(F=1→F
Have fun.

That doesn't work (At least, it doesn't do anything different). I already have code that reverses the gravity. What I want to know is why the character skips two spaces.

I haven't narrowed it down yet, but still working on it, but I found something interesting. If you jump and then change the gravity it seems to work fine.

Are you constantly adding the gravity variable to the Yvalue?
If so, does it zero out on contact with the ground?

For the original code:
I essential have two variables that affect gravity. The first is A, Which is 1, 0, or 1. It is always subtracted from the y variable.
The second variable is B it controls whether you are up or down. It is used to change the value of A and whether the y variable is allowed to be three more or less than the starting jump point.
If you use my code in the first post, everything works except the effect I have been describing.

Your problem exists in this line:
A2(X=(SB3>A
When gravity is reversed and you are falling, A and B are both 1. When you hit X=4, this line thinks you have just hit the top of a jump and should start falling, so it subtracts 2, trying to turn A from 1 to 1. However, A is already 1, so A becomes 3, hence the 3line jump. This can be fixed by changing the code to the following, which will simply set A to 1 if it thinks you have hit the top of a jump (even if you haven't and you were just falling):
If X=(SB3
1>A

Ah, I knew it had something to do with that line. Thanks.