Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Cram on December 20, 2011, 06:10:13 pm

Title: how to jump?
Post by: Cram 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?
Title: Re: how to jump?
Post by: epic7 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.
Title: Re: how to jump?
Post by: Cram on December 20, 2011, 06:13:56 pm
well im starting so simple jump will be fine :P
Title: Re: how to jump?
Post by: epic7 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
Title: Re: how to jump?
Post by: Cram on December 20, 2011, 06:24:11 pm
wow thx i will check this :) but what is the 56*256? :O
Title: Re: how to jump?
Post by: epic7 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.
Title: Re: how to jump?
Post by: Cram 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?
Title: Re: how to jump?
Post by: epic7 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.
Title: Re: how to jump?
Post by: saintrunner 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:)
Title: Re: how to jump?
Post by: epic7 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
Title: Re: how to jump?
Post by: saintrunner 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!!
Title: Re: how to jump?
Post by: Cram on December 20, 2011, 11:10:37 pm
yes if you have a more simpler code, can you teach me? ;D
Title: Re: how to jump?
Post by: ztrumpet 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.
Title: Re: how to jump?
Post by: epic7 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
Title: Re: how to jump?
Post by: saintrunner 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 :)
Title: Re: how to jump?
Post by: Cram on December 21, 2011, 12:25:12 am
wow thx a lot i understand how to jump now! :D and i found a little glitch lol one of your line is (0,0,0,64) so if getkey(2) and (X/=0) should be if getkey(2) and (X/=1) :P
Title: Re: how to jump?
Post by: saintrunner on December 21, 2011, 12:28:24 am
oh yeah (its called a bug) and I just wrote that wrong....I usually write that part as a collision (more difficult)
Title: Re: how to jump?
Post by: Cram on December 21, 2011, 12:56:30 pm
ah ok and that is my next question, how can i put more collision? :O
Title: Re: how to jump?
Post by: epic7 on December 21, 2011, 03:25:20 pm
Collision with what type of gravity, and collisions on all sides?
Title: Re: how to jump?
Post by: saintrunner on December 21, 2011, 03:27:57 pm
easiest way is to do it is with pxl-test. just throw in arguments like
if getkey(2) and pxl-test(X,Y+8)=0  //if left is pushed and the pxl at the bottom left hand corner is off (remember X and Y set at zero is the top left hand corner)
Title: Re: how to jump?
Post by: epic7 on December 21, 2011, 03:29:21 pm
I could give grappler's current subroutines. They use pxl-test (which I need to change) but a more complicated way, which I could simplify for simple gravity and post here.
Title: Re: how to jump?
Post by: saintrunner on December 21, 2011, 03:32:23 pm
I think he gets the gravity, it's just replacing the left and right hitting of objects.....but go ahead :) (I'm actually interested in seeing how your doing it, cause you generally optimize better then me)
Title: Re: how to jump?
Post by: epic7 on December 21, 2011, 03:33:31 pm
For pxl-testing?
Title: Re: how to jump?
Post by: saintrunner on December 21, 2011, 03:34:49 pm
sorry I misread you post, go ahead, I think that might help :)
Title: Re: how to jump?
Post by: epic7 on December 21, 2011, 03:37:22 pm
I was going to show my collisions for more realistic gravity, but mine aren't perfectly functioning so.... :P
Title: Re: how to jump?
Post by: saintrunner on December 21, 2011, 03:39:37 pm
Mine are slightly skewed as well, But I'm working on it...as for simple collision and gravity, pxl-test will work for now :)
Title: Re: how to jump?
Post by: epic7 on December 21, 2011, 03:40:42 pm
I need to use virtual pxltesting.
Title: Re: how to jump?
Post by: saintrunner on December 21, 2011, 05:25:12 pm
heres a source code for a simple movement/platformer engine I made a while back :) I hope it helps a little

Code: [Select]
:.JUMP
:[1C141C080C081C22]→Pic0MR
:[3828381030103844]→Pic0ML
:1→D
:0→J
:40→X
:55→Y
:Lbl 1
:Line(0,63,95,63)
:Line(0,0,0,63)
:Line(95,0,95,63)
:Line(0,0,95,0)
:Line(0,50,25,50)
:Line(25,50,25,63)
:Line(70,50,95,50)
:Line(70,50,70,63)
:
:Repeat getKey(15)
:If getKey(2) and (pxl-Test(X,Y+7)≠1)
:X-1→X
:2→D
:End
:If getKey(3) and (pxl-Test(X+7,Y+7)≠1)
:X+1→X
:1→D
:End
:If getKey(4) and (pxl-Test(X+1,Y+8) or pxl-Test(X+8,Y+8) and (S≠1))
:15→J
:End
:If (J>0)
:Y-1→Y
:J-1→J
:End
:If (pxl-Test(X+8,Y+8) or pxl-Test(X+1,Y+8)=0) and (J=0)
:Y+1→Y
:End
:If (D=1)
:Pt-Change(X,Y,Pic0MR)
:Pause 20
:End
:If (D=2)
:Pt-Change(X,Y,Pic0ML)
:Pause 20
:End
:DispGraph
:If (D=1)
:Pt-Change(X,Y,Pic0MR)
:End
:If (D=2)
:Pt-Change(X,Y,Pic0ML)
:End
:End

btw, the D variable is for the direction of the sprite (look at my screenie a couple posts above) you don't need this unless you want your sprite to look like he is looking different directions
Title: Re: how to jump?
Post by: epic7 on December 21, 2011, 05:36:18 pm
Allow me to optimize/shorten a bit :P

Code: [Select]
:.JUMP
:[1C141C080C081C22]→Pic0MR
:[3828381030103844]
:1→D-1->J
:40→X
:55→Y
:Lbl 1
:Line(0,63,95,63)
:Line(0,,,63)
:Line(95,0,95,63)
:Line(0,,95,0)
:Line(0,50,25,50)
:Line(25,50,25,63)
:Line(70,50,95,50)
:Line(70,50,70,63)
:Repeat getKey(15)
:If getKey(2) and (pxl-Test(X,Y+7)≠1)
:X--
:2→D
:End
:If getKey(3) and (pxl-Test(X+7,Y+7)≠1)
:X++
:1→D
:End
:If getKey(4) and (pxl-Test(X+1,Y+8) or pxl-Test(X+8,Y+8) and (S≠1))
:15→J
:End
:If J>0
:Y--
:J--
:End
:If (pxl-Test(X+8,Y+8) or pxl-Test(X+1,Y+8)=0) and (J=0)
:Y++
:End
:For(Z,0,1)
:Pt-Change(X,Y,D*8+Pic0MR
:!If Z
:DispGraph
:Pause 20
:End
:End
:End
Title: Re: how to jump?
Post by: saintrunner on December 21, 2011, 05:41:04 pm
The reason I didn't optimize it was because this is so he can learn how to do it, I know how to do all that.....but thanks...?
Title: Re: how to jump?
Post by: epic7 on December 21, 2011, 05:42:30 pm
Oh, ok. I dont really know too much about optimizing anyways :P
(That would be epic if squidjetx made a second guide :P)
But he should use the D*8+Pic0 thingy, thats always good to use.
Title: Re: how to jump?
Post by: saintrunner on December 21, 2011, 05:44:10 pm
sure :) (you should probably explain that though)

(lol he's not even online so he will have some tutorial when he does get on !)
Title: Re: how to jump?
Post by: leafy on December 21, 2011, 06:04:27 pm
Each monochrome sprite is 8 bytes, so by adding 8 to an initial pointer sprite you end up with the sprite immediately after that initial one.
In your code, if D is 0, it'll draw Pic0. If D is 1, it'll draw Pic0+8, which is the sprite data directly after the first 8 bytes of Pic0. And so on.
This is pretty useful, so you don't have to make cases, because casework is always bad.
Title: Re: how to jump?
Post by: Cram on December 21, 2011, 11:32:39 pm
thank everyone for your help i understand better now! ;D but i added a monster to kill me and i tryed this code but it dosnt work :(
Code: [Select]
[...]
sub(DIE)
if D
return
end
[...]

Lbl DIE
if pxl-test(u-1,v)=1
1->D
return
when i go close to my monster, he just continu to move across me and nothing happen.. what sould i do or what is the problem? :O
Title: Re: how to jump?
Post by: saintrunner on December 21, 2011, 11:48:40 pm
are you moving from the right? your are pxl-testing the top left hand corner (one spot to the left) so is your sprite tall enough to hit that? or are you smaller then the monster? try pxl-test(U-1,V+7)

edit: this should work (and take up less space)

if pxl-test(U-1,V+7)=1
return
end

I don't think you need a subroutine
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 12:01:07 am
are you moving from the right? your are pxl-testing the top left hand corner (one spot to the left) so is your sprite tall enough to hit that? or are you smaller then the monster? try pxl-test(U-1,V+7)
the monster walk left and go across me after that he go right and walk across me again even if i change v by v+7 :S
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 12:02:27 am
can I see a screenie?

and did you try my code, minus a subroutine ^^
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 12:04:58 am
can I see a screenie?

and did you try my code, minus a subroutine ^^
yes i tryed it but dont work lol and how can i do a screenie?
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 12:06:31 am
you need wabbit emu....but lets fix this problem first, then I'll teach you that, Ok so can you post your full code? or is that too long?
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 12:08:14 am
ok but i will skip useless thing like graphism :P
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 12:09:39 am
I just need to see movement and displays
Title: Re: how to jump?
Post by: DJ Omnimaga on December 22, 2011, 12:17:45 am
Also welcome on the forums by the way :D

It will be a good idea to post the code so people can see what you are doing wrong. I personally cannot help, though, since I have barely coded in Axe. Also I suggest to not start straight away with a Mario clone, since it would be a ridiculous amount of work as first ever calc project. A platformer game with less features is fine, though. :)
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 12:19:00 am
lol my first one was a mario clone...with a shotgun....lol Mario is such a common clone...A GOOD ONE though is a lot harder
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 12:23:21 am
Code: [Select]
0→r→d→z→j+43→y+27→x
0→w+27→u
15→v
repeat getkey(15)
if pxl-test(u-1,v+7)=1
return
end
sub(MMO)
if getkey(2) and (pxl-test(x,y+7)≠1)
x-1→x
if z=0
2→z
elseif z=2
0→z
end
elseif getkey(3) and (pxl-test(x+7,v+7)≠1)
x+1→x
if z=0
2→z
elseif z=2
0→z
end
end
if getkey(1) and pxl-test(x+5,y+8)
3→z
elseif getkey(4)
0→z
end
if getkey(54) and (pxl-test(x+2,y+8) or pxl-test(x+6,y+8)
15→j
1→z
end
if(j>0)
j-1→j
y-1→y
end
if(pxl-test(x+6,y+8) or pxl-test(x+2,y+8)=o and (j=0)
0→j
0→z
y+1→y
end
if y=49
return
end
pause 25
pt-change (x,y,z*8+pic0p1
dispgraph
pt-change (x,y,z*8+pic0p1
end

lbl mmo
pt-change(u,v,r*8+pic0M1
if u≥27 and w=0
u+1→u
elseif u≤62 and w=1
u-1→u
end
if u=27
0→w
elseif u=62
1→w
end
pt-change(u,v,r*8+pic-M1
return
i think everything is here
Title: Re: how to jump?
Post by: DJ Omnimaga on December 22, 2011, 12:24:00 am
Oh I meant making a Super Mario Bros 1/2/3/World clone, literally. Some people get their calc and start straight with a full Mario port, then realize the project is beyond their programming experience then quit.
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 12:25:52 am
this is not really a mario clone only a platformer game :P
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 12:28:25 am
put your monster pxl test in he subroutine, in between the two point changes.....and I suggest moving the secon monster point change outside of the routine and after the displaygraph...do that and tell me what happens....ALSO BACK UP YOUR WORK!!!

did it work?
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 12:51:03 am
nah.. lol i dont know if i did the right thing but nothing is working now xD

can you show me what you mean in my code plz?
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 12:56:05 am
hmmm, This should'nt be that difficult....go back to what you had, and just move the pxltest monster thing around... I think  you are just telling it to check for an ON pxl when it is also changing spots...so it doesn't read it

I meant

0→r→d→z→j+43→y+27→x
0→w+27→u
15→v
repeat getkey(15)
sub(MMO)
if pxl-test(u-1,v+7)=1
return
end
if getkey(2) and (pxl-test(x,y+7)≠1)
x-1→x
if z=0
2→z
elseif z=2
0→z
end
elseif getkey(3) and (pxl-test(x+7,v+7)≠1)
x+1→x
if z=0
2→z
elseif z=2
0→z
end
end
if getkey(1) and pxl-test(x+5,y+8)
3→z
elseif getkey(4)
0→z
end
if getkey(54) and (pxl-test(x+2,y+8) or pxl-test(x+6,y+8)
15→j
1→z
end
if(j>0)
j-1→j
y-1→y
end
if(pxl-test(x+6,y+8) or pxl-test(x+2,y+8)=o and (j=0)
0→j
0→z
y+1→y
end
if y=49
return
end
pause 25
pt-change (x,y,z*8+pic0p1
dispgraph
pt-change (x,y,z*8+pic0p1
pt-change(u,v,r*8+pic-M1
end

lbl mmo
pt-change(u,v,r*8+pic0M1
if u≥27 and w=0
u+1→u
elseif u≤62 and w=1
u-1→u
end
if u=27
0→w
elseif u=62
1→w
end
return

edit: and if that doesn't work I got one more idea....lol, you'll learn very quickly that a lot of coding is trial and error :P
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 01:02:19 am
yes that what i did but i had to put the first pt-change in the end of mmo just before return but it still not work.. :(
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 01:03:46 am
try pxl-testing U and V right before the display graph...cuz your trying to see if it is hitting your character...but you need your character to move before it can test that
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 01:05:53 am
yeah that it exactly what i just did and he work now ;D thx for all your time! :)
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 01:07:49 am
:) sure thing! lol and remember to always back up your work! For my seeker game ( check it out if you don't know it, It's a pretty good platformer..not done yet though) I've hit even worse bugs, and have had over 30 ram clears!! lol trial and error my friend, trial and error :)
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 01:09:09 am
ahah yeah we learn from error :P
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 01:12:07 am
unless your a perfect coding guru, who never errors.....I wish I was one lol!

edit: to be honest, I should have know it was needed by the displaygraph! lol, thats like common sense! I think it was the subroutine throwing me off :P
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 01:18:04 am
probably xD well i think i will never do this error again  :banghead:
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 01:23:05 am
Good! Also (as I hinted above *cough cough*) you can always check out my Seeker thread to see how that platformer is going :) When I first made platformers,I got Ideas from other ones, :) PLUS I need more people to test it! which I posted a demo if you have free time! also do you want me to tell you about wabbit emu now?
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 02:03:32 am
im going to sleep now but you can tell me and tomorrow i will look it + test your game :)
Title: Re: how to jump?
Post by: DJ Omnimaga on December 22, 2011, 03:33:11 am
Also since you are into Axe, an advice I must tell you early before you get too far into a project then get a surprise is backing up your progress often. Sometimes in Axe if you do an error, you will get a RAM clear or archive corruption, losing all your work. It's always good to copy your progress on an hard drive and a flash drive from time to time. 

Good luck!
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 10:52:58 am
SEE even DJ does it :) lol and now to wabbit Emu.....basically it is an emulater for your calc, you can download it for windows or mac at http://wabbit.codeplex.com/releases/view/44625 and then follow the install instructions. I'll tell you now you are going to need to get Rom images from your calc which is explained how to in the install window, But have our calc at hand! and if you don't have TI connect...get it (I assume you do) although it is usually stupid and doesn't always transfer files.

Why do I need these?:

with TI Connect, you will be able to transfer files to and from your calc AND THEN

You can simply drag them to an open Emu window to test/get screenie/mess with, with out worrys of stupid RAM clears!....well you still get them but, it matters less.

Screenies:
when you have all this installed and a Emu window open, you can now enter the wonderful world of SCREENIES!! very helpful in shwing off your work and getting help with bugs

Just press backspace.....you'll see a blue thing around the screen, which means it is recording, and the press backspace again to stop. this will safe the screen shot as a .gif file in what ever location you specified during install (I think...you'll figure that out it's easy,just mess around with it a little)

The you can upload screenies here, by clicking Reply, then choose file for attachments, and finally finding your file. EASY!

I also recommend downloading noshell for your Emu because, then you don't have to worry about most of the shells. just download and install from apps (noshell is also good on calc, in my opinion)

find that at http://www.ticalc.org/archives/files/fileinfo/400/40005.html

well thats a simple over view, if you have any questions, you always have me, omni, or youtube :) good luck!
Title: Re: how to jump?
Post by: leafy on December 22, 2011, 12:00:18 pm
You should also make sure to set the recording FPS to 60 in the options menu. It makes for smoother screenshots.
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 12:51:00 pm
thx but can you tell me more about ROM image? how it work?
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 12:58:17 pm
I'm not an expert in that area, but if you follow the install instructions, its all cool. I think, Its just copy of run info from your calc. in the install it will tell you to tell what type of calc you have, then it has you download a file onto your calc and run it. this will create two more files on your calc. you then transfer those two files to the computer and put them in the install window (It tells you how to do that) then click finish....should be all good...check this out for a better explaination

http://youtu.be/fmvp7WY7AeI
Title: Re: how to jump?
Post by: Cram on December 22, 2011, 04:16:42 pm
ok thank for all! :) i will check all that tonight because im going to work now and if i have a problem, i will ask you :D
Title: Re: how to jump?
Post by: saintrunner on December 22, 2011, 04:26:05 pm
sure thing, your welcome