? Jumping and Gravity (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Jumping and Gravity

  • #1 ✎ 6 JacboyX Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Video Games I like to play video games! Hobbies Now I know for a fact I can use variables to make my character move left and right, but how can I get my character to jump and use a gravity system? Posted
  • #2 ✎ 153 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Here's a simple demo: VAR X,Y'Position XY VAR VX,VY'Velocity for each XY. Unlike acceleration, this is the actual movement speed of the player. VAR AX,AY'Acceleration for each XY. This will be reset every frame. VAR MVSP=0.3'Movement speed. Zero point three pixels per frame of button press. VAR FRCTN=0.9'Think of this as "how much velocity do I want to preserve after the character strikes a wall?" VAR BN'Button variable WHILE 1 BN=BUTTON() PHYSICS COLLISION RENDER VSYNC WEND DEF PHYSICS INC AY,0.5'Simulates gravity IF BN AND 1 THEN INC AY,-MVSP IF BN AND 2 THEN INC AY,MVSP IF BN AND 4 THEN INC AX,-MVSP IF BN AND 8 THEN INC AX,MVSP INC VX,AX INC VY,AY AX=0 AY=0 END DEF COLLISION IF(X<0)OR(X>400)THEN X=MIN(MAX(X,0),400):VX=-VX*FRCTN IF(Y<0)OR(Y>240)THEN Y=MIN(MAX(Y,0),240):VY=-VY*FRCTN END DEF RENDER GCLS GPSET X,Y END Don't shoot me if it doesn't work or doesn't look good. I can't quite test it atm, but this is the generic setup I use when dealing with a game's physics: Physics, collision, then render. Posted Edited by MZ952
  • #3 ✎ 6 JacboyX Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Video Games I like to play video games! Hobbies Okay, now I know where to put the SPSET command, but how can I use the SP commands to make sure the whole thing doesn't call out errors, to drive me insane? Posted
  • #4 ✎ 153 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies
    Okay, now I know where to put the SPSET command, but how can I use the SP commands to make sure the whole thing doesn't call out errors, to drive me insane?
    What kind of errors are you getting? Are you using SPOFS to move the sprite?
    Posted
  • #5 ✎ 6 JacboyX Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Video Games I like to play video games! Hobbies That's how it worked in one of my test programs. I wanted to put that sort of idea in the control mechanic program I did, but the animation looked chunky. Posted
  • #6 ✎ 131 raimondz First Week Joined in the very first week of SmileBASIC Source Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Call SPSETbefore the while and SPOFS during the render method (DEF render) Posted
  • #7 ✎ 400 random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Video Games I like to play video games! Hobbies heres a kind of demo code thing: 'main loop while death==0 spset 0,0 spofs 0,x,y 'movement left right if button(0)==4 then dec x if button(0)==8 then inc x 'gravity inc y,2 'ground stopping fall if y<(number of the ground NO PARENTHESIS!) then y=(number of ground STILL NO PARENTHESIS!) 'jump if button(0)==16 then dec y,10 wait 1 wend but idk if this will work just got it off the top of my head. Posted