Author Topic: how to jump?  (Read 24391 times)

0 Members and 2 Guests are viewing this topic.

Offline Cram

  • LV3 Member (Next: 100)
  • ***
  • Posts: 49
  • Rating: +0/-0
    • View Profile
how to jump?
« on: December 20, 2011, 06:10:13 pm »
hi im new in axe and i want to know how to jump like in a mario game?

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: how to jump?
« Reply #1 on: December 20, 2011, 06:12:36 pm »
Simple jumps, or more realistic jumps?
I already have code I used to help 2 people out with jumps. I'll go fetch it.
« Last Edit: December 20, 2011, 06:13:15 pm by epic7 »

Offline Cram

  • LV3 Member (Next: 100)
  • ***
  • Posts: 49
  • Rating: +0/-0
    • View Profile
Re: how to jump?
« Reply #2 on: December 20, 2011, 06:13:56 pm »
well im starting so simple jump will be fine :P

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: how to jump?
« Reply #3 on: December 20, 2011, 06:15:33 pm »
Ok, since I already got a simple more realistic jump code, here it is anyways:

Jumping isnt really that bad.

[FFFFFFFFFFFFFFFF]->Pic1 ;Pic, but just a cube
56*256->Y ;X and Y are inflated by 256 for accuracy
0->X->V->W->A->B->J
Repeat getKey(15)
If getKey(54)
-256->W ;Set Y velocity to -256 to go up
256->V ;Set X velocity
8->B ;Set a downward acceleration to fall
End
If Y/256>57 ;simple collision with the bottom of screen
56*256->Y ;Reset
0->A->B->V->W
End
V+A->V+X->X ;Find X coordinates
W+B->W+Y->Y ;Find Y
Pt-On(X/256,Y/256,Pic1)
DispGraphClrDraw
End

Where X,Y are coordinates
V,W are velocities
A,B are accelerations

Collisions with realistic jumps get tricky once you get involved with collisions.

For a simple linear jump, keep a variable for jumping, lets say J. Then we'll have an X and Y.

Probably other ways to do it, though.

[FFFFFFFFFFFFFFFF]->Pic1
0->X->J
56->Y
Repeat getKey(15) ;loop here
If getKey(54) ;push 2nd to jump.
!If J ;checks if ready
1->J
End
End
If J<16
J++
X++
Y-- ;go up
ElseIf J<31
J++
X++
Y++ ;go down
Else
0->J
End
Pt-On(X,Y,pic1)
DispGraphClrDraw
End

Simple thing I thought up ^
But no collisions. Just go down as far as you went up in that code :P
« Last Edit: December 20, 2011, 06:53:47 pm by epic7 »

Offline Cram

  • LV3 Member (Next: 100)
  • ***
  • Posts: 49
  • Rating: +0/-0
    • View Profile
Re: how to jump?
« Reply #4 on: December 20, 2011, 06:24:11 pm »
wow thx i will check this :) but what is the 56*256? :O

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: how to jump?
« Reply #5 on: December 20, 2011, 06:26:22 pm »
The variables are multiplied by 256 to be measured in 256ths of a pixel to be precise.

Offline Cram

  • LV3 Member (Next: 100)
  • ***
  • Posts: 49
  • Rating: +0/-0
    • View Profile
Re: how to jump?
« Reply #6 on: December 20, 2011, 06:41:46 pm »
nice but you forgot a dispgraph and an end in the last code lol but do you know how to jump and to be able to move left and right with arrow?

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: how to jump?
« Reply #7 on: December 20, 2011, 06:56:36 pm »
Lol, oh yeah. Fixed it (and also added ClrDraw).
I had to do it quick since I was short on time :P

getKey(2)?X--
getKey(3)?X++

I think that is a quick way to move.

Offline saintrunner

  • Custom Spriter: You ask it! I'll Make it!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1787
  • Rating: +115/-11
  • Flogging Molly
    • View Profile
    • Jonny K Music
Re: how to jump?
« Reply #8 on: December 20, 2011, 07:29:56 pm »
If any of the code doesn't make sense you can talk to Parser Padwan, Epic7, or me....(Parser showed me, and correct me if I'm wrong but didn't I show you epic? or did parser show you to?)

Also more realistic jumping isn't that much harder....collisions are whats hard :) I can write up a quick movement engine (Super simple) if you want:)
My Sprites Thread   :Updated often :) for your viewing pleasure

GAMES:

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: how to jump?
« Reply #9 on: December 20, 2011, 07:32:27 pm »
No, I just figured it out :P

Once, you explained it to me when I already knew it since you misinterpreted my question :P

Offline saintrunner

  • Custom Spriter: You ask it! I'll Make it!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1787
  • Rating: +115/-11
  • Flogging Molly
    • View Profile
    • Jonny K Music
Re: how to jump?
« Reply #10 on: December 20, 2011, 07:34:55 pm »
AHH now I remember...lol, now I see, *saintrunner looks closely at epic's code* Yeah Mine is a lot different...I think Shorter too, but yours looks like it's less complex, so Its better for teaching :)

edit YEAH JUMPING!!
« Last Edit: December 20, 2011, 07:41:11 pm by saintrunner »
My Sprites Thread   :Updated often :) for your viewing pleasure

GAMES:

Offline Cram

  • LV3 Member (Next: 100)
  • ***
  • Posts: 49
  • Rating: +0/-0
    • View Profile
Re: how to jump?
« Reply #11 on: December 20, 2011, 11:10:37 pm »
yes if you have a more simpler code, can you teach me? ;D

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: how to jump?
« Reply #12 on: December 20, 2011, 11:17:17 pm »
Here's a pretty simple explanation: http://www.omnimaga.org/index.php?action=articles;sa=view;article=37

Though this tutorial is in TI Basic, it breaks down everything very well and could be (hopefully) understood by a non-programmer as well as a programmer. I suggest giving it a look and seeing if it can help you at all.

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: how to jump?
« Reply #13 on: December 20, 2011, 11:24:06 pm »
Lol I don't understand any of that code example because of my weak Ti-basic skills :P

Offline saintrunner

  • Custom Spriter: You ask it! I'll Make it!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1787
  • Rating: +115/-11
  • Flogging Molly
    • View Profile
    • Jonny K Music
Re: how to jump?
« Reply #14 on: December 20, 2011, 11:35:48 pm »
wel I do it very similar to epic....but here is it explained

[FFFFFFFFFFFFFFFF]->pic1M   //This is our sprite...yes it's a box :)
line(0,0,95,0)
line(0,63,95,63)
line(0,0,0,63)
line(95,0,95,63)   //this will draw a border
45->X
55->Y
0->J      // setting all variables
repeat getkey(15)   //main loop till 'clear' is pressed (getkey(15)=clear button)
if getkey(2) and (X/=0)  //If left button is pressed and it is not hitting the left side (I'll show you later how to do simple collision)    (/= means does not equal)
X-1->X    //move sprite over one pxl to the left
End
if getkey(3) and (X/=87)   //if right is pressed
X+1->X      //move to right
End
if getkey(4) and pxl-test(X,Y+8)    //if he is on the ground and up is pushed
15->J    //change this for your jump height
End
if (J>0)
J-1->J
Y-1->Y   //decreace J and decrease Y (bring him up...notice subtracting from Y makes him go up!)
End
if (pxl-test(X,Y+8)=0) and (J=0)   //if nothing is below him and J is 0
0->J   //just in case you land on a platform
Y+1->Y  //bring you back down
End
Pause 25   //so it's not too fast
pt-change(X,Y,pic1M)   
Disgraph
pt-change(X,Y,pic1M)
End



That should be it....any questions, and you know where to find me :)
My Sprites Thread   :Updated often :) for your viewing pleasure

GAMES: