Author Topic: Jump code help please  (Read 4088 times)

0 Members and 1 Guest are viewing this topic.

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Jump code help please
« on: July 26, 2012, 09:39:04 pm »
Ok, i don't know yet what game i'm gonna make and don't have my 84+ with me atm, so don't blame me if i make misstakes xD

If i would have

:horizontal 0
:47->x
:61->y
:pxl-on(61,50
:lbl 1
:pxl-on(y,x
:x->a
:y->b
:delvar k
:while k /= 24 and k /= 26 and k /= 21
:getkey-> k
:x+(k=26)-(k=24)->x
:jump code
:end
:pxl-off(b,a
:goto 1

Ok, i know it's not optimized and that the goto's aren't good, and i know collision detect isn't here as well

But how could i insert a jump code here? ( other movement can be tolorated xd just put the movement+jump here, i know how to do the jump and i get the gravity a bit but i keep having troubles with the falling-on-platform-thing-and-not-falling-trough-it ) :P
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Jump code help please
« Reply #1 on: July 27, 2012, 02:33:36 am »
Code: [Select]
:If not(pxl-test(Y+2,X)
:Y+1->Y  // or whatever you want to do for gravity
You should also use this to check if they should be able to jump or not:
Code: [Select]
:If (K=21)pxl-test(Y+2,X
:5->J // something that starts the jump

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: Jump code help please
« Reply #2 on: July 27, 2012, 03:35:00 am »
Ok, thx, i'll try it out, but not now, tonight i think xD
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Jump code help please
« Reply #3 on: July 27, 2012, 10:43:00 am »
Also, I suggest that you make your jumping by 1 unit at a time. When I made a jump game, what I did for jumping was adding the 'force' upward to the position, and lowering the 'force' upward according to gravity, until it was on top of a block. Ex:
Code: [Select]
:Y-C->Y
:If not(pxl-test(Y+2,X
:C-1->C
Unfortunately, that means that it sometimes skips a few pixels and falls through the block... I failed and gave up on it, but now I realize that instead of doing that, you can do this:
Code: [Select]
:Y-(C>0)->Y
:Y+(C<0)->Y
:If not(pxl-test(Y+2,X
:C-1->C
The (C>0) will always be 1 until C is 0 or lower, and it will go up by 1 every time. The (C<0) will always be 1 when C is 0 or lower, and it will go down every time. :)

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: Jump code help please
« Reply #4 on: July 27, 2012, 11:04:23 am »
Euhm, could you maybe set it in a little example? Like prog start, clrdraw, then a little map, the pixel that moves, and then movement and jump? Or is it to much?

Ps: if you'dd do that, please in code like here, i can't transfer progs atm
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Jump code help please
« Reply #5 on: July 27, 2012, 11:27:12 am »
I'm just going to write this from memory, 'cause my calc's backing up and I gotta go soon.
Spoiler For Spoiler:
:47->X:31->Y:0->C
:ClrDraw
:Draw some stuff for it to drop on
:Repeat Y>54
:pxl-on(Y,X
:getKey->K
:If K=21 and pxl-test(Y+2,X
:9->C
:If not(pxl-test(Y+2,X
:C-1->C
:If pxl-test(Y+2,X
:0->C
:pxl-off(Y,X
:X+(K=26)-(K=24->X
:Y-(C>0)->Y
:Y+(C<0)->Y
:End
That's pretty rough, I wrote it in like 5 minutes. Let me know how it works for you.
EDIT: You should probably store pxl-test(Y+2,X) to a variable, cause it is used a bunch of times.
« Last Edit: July 27, 2012, 11:29:28 am by dinosteven »

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: Jump code help please
« Reply #6 on: July 27, 2012, 12:00:24 pm »
Ok, i'll try it later on today, thanks anyway
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Jump code help please
« Reply #7 on: July 27, 2012, 01:36:06 pm »
EDIT: You should probably store pxl-test(Y+2,X) to a variable, cause it is used a bunch of times.
Or use some "Then", "End" and "Else" ;)

:47->X:31->Y:0->C
:ClrDraw
:Draw some stuff for it to drop on
:Repeat Y>54
:pxl-on(Y,X
:getKey->K
:If pxl-test(Y+2,X
:Then
  :0->C
  :If K=21:9->C
:Else
  :C-1->C
:End
:pxl-off(Y,X
:X+(K=26)-(K=24->X
:Y-(C>0)->Y
:Y+(C<0)->Y
:End

Moreover, you made something strange here:
  :If K=21 and pxl-test(Y+2,X
  :9->C
  ...
  :If pxl-test(Y+2,X
  :0->C
So the first If is useless ???
« Last Edit: July 27, 2012, 01:38:11 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: Jump code help please
« Reply #8 on: July 27, 2012, 05:13:24 pm »
Indeed, i guess it could be solved by swithing the places of those 2 if-statements
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Jump code help please
« Reply #9 on: July 28, 2012, 12:19:29 am »
Oops, my mistake!
Code: [Select]
:If pxl-test(Y+2,X
:0->C
Should be
Code: [Select]
:If pxl-test(Y+2,X) and (C<0)
:0->C
It was meant to stop the falling, so that gravity doesn't take effect upon landing.