So, I was going to reply with ideas, but then as I was testing ideas on my calc, I accidentally made some pretty decent jumping code :|
So basically, if J=1, it means a jump is in progress, J=0 means no current jump. I use V for velocity and gravity = 1pixel/iteration2.
(X,Y) are the coords for the lower left of the 8x8 sprite. The following code checks for collision detection, too!
Lbl JUMP
Return !If J
If V<<0
-V→B
While B
B-1→B
Y-1→Y
For(A,0,7)
If pxl-Test(A+X,Y-7)
7→A
Y+1→Y
0→B→V
End:End:End:End
If V>>0
V→B
While B
B-1→B
Y+1→Y
For(A,0,7)
If pxl-Test(A+X,Y)
7→A
Y-1→Y
0→J→B→V
End:End:End:End
V+1→V
Return
So if you want [Enter] to be the button for jumping, you could have this in your mainloop:
If J or getKey(9)
!If J
-6→V
1→J
End
JUMP()
End
It checks if a jump is in progress. If not, it initializes the jump with velocity==6pixels/iter. It's negative only because we want it going toward the top of the screen, so we need the Y coordinate to go down.
Further, right before the above code, you might want to check if there is any floor (on pixels) below the sprite. If not, it needs to drop down:
!If J
1→J
0→V
For(A,0,7)
If pxl-Test(X+A,Y+1)
0→J
End:End:End
My entire program looks like this (and you are free to take this code as is, modify it, whatever):
First some setup code. Setup some vars, draw a border around the screen as well as some platforms
.JUMP
FnOn
ClrDraw
1→X
62→Y
0→J
VLine(0)
VLine(95)
HLine(0)
HLine(63)
Line(0,50,24,50)
Line(20,37,44,37)
[3C4281818181423C]→Pic1
Then in the mainloop, we draw the sprite to the screen and check key presses.
Lbl LOOP
Pt-Change(X,Y-7,Pic1)
DispGraph
Pt-Change(X,Y-7,Pic1
Stop
ReturnIf getKey(15)
If getKey(2):LEFT():End
If getKey(3):RIGHT():End
!If J
1→J
0→V
For(A,0,7)
If pxl-Test(X+A,Y+1)
0→J
End:End:End
If J or getKey(9)
!If J
-6→V
1→J
End
JUMP()
End
Goto LOOP
Now for the subroutines, LEFT() and RIGHT(), we need to check for collisions.
Lbl LEFT
0→C
Y→A
For(8)
C+pxl-Test(X-1,A)→C
A-1→A
End
ReturnIf C
X-1→X
Return
Lbl RIGHT
0→C
Y→A
For(8)
C+pxl-Test(X+8,A)→C
A-1→A
End
ReturnIf C
X+1→X
Return
And then the jump code from before (note we don't need to check if J=1 since the only time we call it is when we know J=1)
Lbl JUMP
If V<<0
-V→B
While B
B-1→B
Y-1→Y
For(A,0,7)
If pxl-Test(A+X,Y-7)
7→A
Y+1→Y
0→B→V
End:End:End:End
If V>>0
V→B
While B
B-1→B
Y+1→Y
For(A,0,7)
If pxl-Test(A+X,Y)
7→A
Y-1→Y
0→J→B→V
End:End:End:End
V+1→V
Return
I hope I didn't forget anything!