Author Topic: Jumping - reverse gravity  (Read 6893 times)

0 Members and 1 Guest are viewing this topic.

Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
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]
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(Y-1),"_    //one space
Y+(K=26)-(K=24
Ans-15((Ans=16)-not(Ans->Y
X-BA->X
A-2(X=(S-B3->A
If X=S
DelVar A
If not(A
X->S
B-2(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(Y-1),"X
A+(K=21 and X=S->A
rand(8
End

I realize this isn't very optimized.  That will be fixed.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
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

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
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)

Offline Raylin

  • Godslayer
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1392
  • Rating: +83/-25
  • I am a certifiable squirrel ninja.
    • View Profile
    • Ray M. Perry
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 »
Bug me about my book.

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







Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
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 »

Offline Raylin

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

Code: [Select]
If K=21:1-2(F=1→F
Have fun.
Bug me about my book.

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







Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
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.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
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)

Offline Raylin

  • Godslayer
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1392
  • Rating: +83/-25
  • I am a certifiable squirrel ninja.
    • View Profile
    • Ray M. Perry
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?
Bug me about my book.

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







Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
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.

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
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 »

Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
Re: Jumping - reverse gravity
« Reply #11 on: September 09, 2010, 11:34:01 pm »
Ah, I knew it had something to do with that line.  Thanks.