### Author Topic: Jumping - reverse gravity  (Read 4706 times)

0 Members and 1 Guest are viewing this topic.

#### MRide

• Posts: 711
• Rating: +14/-0
• You can't see this.
##### Jumping - reverse gravity
« 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)

Code: [Select]
ClrHome7->X:Ans->S    //X is actually the Y coord., and S is the initial Y coord. that you jumped from1->Y:Ans->B   //Y is the X coord. ,and B is either positive or negative one, depending on if the gravity is reversedDelvar ARepeat 0  //A controls whether you move up, down, or not at allgetKey->KIf Ans or A!=0Text(-1,7X,6(Y-1),"_    //one spaceY+(K=26)-(K=24Ans-15((Ans=16)-not(Ans->YX-BA->XA-2(X=(S-B3->AIf X=SDelVar AIf not(AX->SB-2(K=31 and B=1)+2(K=31 and B=-1->CIf B!=C:Then-1->AC->BIf B=-11->SIf B=17->SEndText(-1,7X,6(Y-1),"XA+(K=21 and X=S->Arand(8End
I realize this isn't very optimized.  That will be fixed.

#### DJ Omnimaga

• Clacualters are teh gr33t
• CoT Emeritus
• LV15 Omnimagician (Next: --)
• Posts: 55928
• Rating: +3152/-232
• CodeWalrus founder & retired Omnimaga founder
##### Re: Jumping - reverse gravity
« Reply #1 on: September 09, 2010, 10:37:33 pm »
Mhmm... Raylin might be great help there. He wrote a game involving inverting gravity

#### meishe91

• Super Ninja
• LV11 Super Veteran (Next: 3000)
• Posts: 2946
• Rating: +115/-11
##### Re: Jumping - reverse gravity
« Reply #2 on: September 09, 2010, 10:43:05 pm »
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.
« Last Edit: September 09, 2010, 10:47:45 pm by meishe91 »
Spoiler For Spoiler:

For the 51st time, that is not my card! (Magic Joke)

#### Raylin

• Godslayer
• LV10 31337 u53r (Next: 2000)
• Posts: 1392
• Rating: +83/-25
• I am a certifiable squirrel ninja.
##### Re: Jumping - reverse gravity
« Reply #3 on: September 09, 2010, 10:43:11 pm »
Hold on...
« Last Edit: September 09, 2010, 10:46:40 pm by Raylin »

Sarah: TI-83 Plus Silver Edition [OS 1.19]
Cassie: TI-86 [OS 1.XX]
Elizabeth: TI-81 [OS 1.XX]
Jehuty: TI-83 Plus Silver Edition [OS 1.19]
Tesla: CASIO Prizm

#### MRide

• Posts: 711
• Rating: +14/-0
• You can't see this.
##### Re: Jumping - reverse gravity
« Reply #4 on: September 09, 2010, 10:44:14 pm »
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.
« Last Edit: September 09, 2010, 10:48:12 pm by MRide »

#### Raylin

• Godslayer
• LV10 31337 u53r (Next: 2000)
• Posts: 1392
• Rating: +83/-25
• I am a certifiable squirrel ninja.
##### Re: Jumping - reverse gravity
« Reply #5 on: September 09, 2010, 10:52:51 pm »
This is my gravity reversing code.

Code: [Select]
If K=21:1-2(F=1→F
Have fun.

Sarah: TI-83 Plus Silver Edition [OS 1.19]
Cassie: TI-86 [OS 1.XX]
Elizabeth: TI-81 [OS 1.XX]
Jehuty: TI-83 Plus Silver Edition [OS 1.19]
Tesla: CASIO Prizm

#### MRide

• Posts: 711
• Rating: +14/-0
• You can't see this.
##### Re: Jumping - reverse gravity
« Reply #6 on: September 09, 2010, 11:05:14 pm »
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.

#### meishe91

• Super Ninja
• LV11 Super Veteran (Next: 3000)
• Posts: 2946
• Rating: +115/-11
##### Re: Jumping - reverse gravity
« Reply #7 on: September 09, 2010, 11:12:30 pm »
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.
Spoiler For Spoiler:

For the 51st time, that is not my card! (Magic Joke)

#### Raylin

• Godslayer
• LV10 31337 u53r (Next: 2000)
• Posts: 1392
• Rating: +83/-25
• I am a certifiable squirrel ninja.
##### Re: Jumping - reverse gravity
« Reply #8 on: September 09, 2010, 11:14:18 pm »
Are you constantly adding the gravity variable to the Y-value?
If so, does it zero out on contact with the ground?

Sarah: TI-83 Plus Silver Edition [OS 1.19]
Cassie: TI-86 [OS 1.XX]
Elizabeth: TI-81 [OS 1.XX]
Jehuty: TI-83 Plus Silver Edition [OS 1.19]
Tesla: CASIO Prizm

#### MRide

• Posts: 711
• Rating: +14/-0
• You can't see this.
##### Re: Jumping - reverse gravity
« Reply #9 on: September 09, 2010, 11:27:11 pm »
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.

#### Runer112

• Moderator
• LV11 Super Veteran (Next: 3000)
• Posts: 2289
• Rating: +639/-31
##### Re: Jumping - reverse gravity
« Reply #10 on: September 09, 2010, 11:28:23 pm »
Your problem exists in this line:
Code: [Select]
A-2(X=(S-B3->AWhen 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 3-line 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):
Code: [Select]
If X=(S-B3-1->A
« Last Edit: September 09, 2010, 11:29:31 pm by Runer112 »