The last two posts were a bit hard to understand, but when you understand arrays and pointers we can go on.
At first, we will create one platform:
Code: [i]DJUMP
det(0)
160→PX
200→PY
45→SPEED
// We store all variables for the platform in an array
Alloc(4)→PLATF
160→**{PLATF} // position x (we need two bytes because x can be up to 320)
200→**{PLATF+2} // position y (same goes for y)
det(43,0,0,320,240)
Repeat getKey(15)
det(5,255)
det(36,**{PLATF},**{PLATF+2},40,10) // draw our new platform
det(2,7)
det(36,PX-15,340-PY-40,30,40)
det(10)
max(SPEED,1)-1→SPEED/3+PY-10→PY
If PY<100
70→SPEED
100→PY
End
If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
End
det(1)
We have to change the center and "the coordinate system"Code: det(36,**{PLATF}-20,340-**{PLATF+2},40,10)
Let's insert a few more platforms:Code: [i]DJUMP
det(0)
160→PX
200→PY
45→SPEED
Alloc(40)→PLATF // We create 10 platforms so we need to allocate 40 bytes.
For(Z,0,9)
PLATF+Z*4→ID // Four bytes for each platform...
randInt(25,295)→**{ID} // They shouldn't be all at the same place
130+Z*35→**{ID+2}
End
det(43,0,0,320,240)
Repeat getKey(15)
det(5,255)
det(2,237) // we draw them in another color
For(Z,0,9)
PLATF+Z*4→ID
det(36,**{ID}-20,340-**{ID+2},40,10)
End
det(2,7)
det(36,PX-15,340-PY-40,30,40)
det(10)
max(SPEED,1)-1→SPEED/3+PY-10→PY
If PY<100
70→SPEED
100→PY
End
If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
End
det(1)
Now we have to add the intersection.
We can do this by checking if (PX,PY) is inside the platform.Code: [i]DJUMP
det(0)
Lbl CREATE VARIABLES // we can use labels to structure our source code
160→PX
200→PY
45→SPEED
Alloc(40)→PLATF
For(Z,0,9)
PLATF+Z*4→ID
randInt(25,295)→**{ID}
130+Z*35→**{ID+2}
End
Lbl GAME LOOP
det(43,0,0,320,240)
Repeat getKey(15)
det(5,255)
det(2,237)
For(Z,0,9)
PLATF+Z*4→ID
det(36,**{ID}-20,340-**{ID+2},40,10)
If PX+15>=**{ID}-20 and PX-15<= **{ID}+20 and PY<=**{ID+2} and PY>=**{ID+2}-10 // intersection check
53→SPEED
**{ID+2}→PY
End
End
det(2,7)
det(36,PX-15,340-PY-40,30,40)
det(10)
max(SPEED,1)-1→SPEED/3+PY-10→PY
If PY<100
70→SPEED
100→PY
End
If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
End
det(1)
We don't need the ground bounce anymore...Code: [i]DJUMP
det(0)
Lbl CREATE VARIABLES
160→PX
60→PY // we want to jump into the screen
60→SPEED
Alloc(40)→PLATF
For(Z,0,9)
PLATF+Z*4→ID
randInt(25,295)→**{ID}
130+Z*35→**{ID+2}
End
160→**{PLATF} // the first platform should be in the middle
Lbl GAME LOOP
det(43,0,0,320,240)
Repeat getKey(15) or PY<50 // quits if we are too deep
det(5,255)
det(2,237)
For(Z,0,9)
PLATF+Z*4→ID
det(36,**{ID}-20,340-**{ID+2},40,10)
If PX+15>=**{ID}-20 and PX-15<= **{ID}+20 and PY<=**{ID+2} and PY>=**{ID+2}-10
max(53,SPEED)→SPEED // we only want to speed up
**{ID+2}→PY
End
End
det(2,7)
det(36,PX-15,340-PY-40,30,40)
det(10)
max(SPEED,1)-1→SPEED/3+PY-10→PY
If getKey(2):PX-3→PX:End
If getKey(3):PX+3→PX:End
End
det(1)