#1✎ 9JacboyXIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthNight PersonI like the quiet night and sleep late.Express YourselfVideo GamesI like to play video games!HobbiesNow 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✎ 198MZ952Intermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthDrawingI like to draw!HobbiesReadingI like to read books!HobbiesHere'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✎ 9JacboyXIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthNight PersonI like the quiet night and sleep late.Express YourselfVideo GamesI like to play video games!HobbiesOkay, 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✎ 198MZ952Intermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthDrawingI like to draw!HobbiesReadingI 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✎ 9JacboyXIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthNight PersonI like the quiet night and sleep late.Express YourselfVideo GamesI like to play video games!HobbiesThat'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✎ 131raimondzFirst WeekJoined in the very first week of SmileBASIC SourceWebsiteExpert ProgrammerProgramming no longer gives me any trouble. Come to me for help, if you like!Programming StrengthNight PersonI like the quiet night and sleep late.Express YourselfCall SPSETbefore the while and SPOFS during the render method (DEF render)
Posted
#7✎ 562random_godIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthZelda Is Awesome!I love The Legend Of Zelda!Express YourselfVideo GamesI like to play video games!Hobbiesheres 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