0 Members and 4 Guests are viewing this topic.
Make a loop that constantly adds a velocity variable to the y-position variable, and if the object is not at rest, subtracts some value from the velocity variable every iteration. To jump, set the velocity variable to a positive value.A basic example (also attached):Code: [Select].GRAVTESTClrDraw[FF818181818181FF]→Pic156→Y0→VRepeat getKey(15)!If Y-560→VIf getKey(54)7→VEndElseV-1→VEndPt-Change(44,Y-V→Y,Pic1)DispGraphPt-Change(44,Y,Pic1)Pause 32End Pseudocode:Code: [Select]HeaderClear screenObject spriteInitialize y positionInitialize y velocityUntil user presses clear If object is at rest (bottom of screen) Set velocity to zero If user presses 2nd (jump) Set velocity to a positive value End Else, object is not at rest Decrease velocity End Update y position and draw sprite Update screen Clear sprite DelayEnd
.GRAVTESTClrDraw[FF818181818181FF]→Pic156→Y0→VRepeat getKey(15)!If Y-560→VIf getKey(54)7→VEndElseV-1→VEndPt-Change(44,Y-V→Y,Pic1)DispGraphPt-Change(44,Y,Pic1)Pause 32End
HeaderClear screenObject spriteInitialize y positionInitialize y velocityUntil user presses clear If object is at rest (bottom of screen) Set velocity to zero If user presses 2nd (jump) Set velocity to a positive value End Else, object is not at rest Decrease velocity End Update y position and draw sprite Update screen Clear sprite DelayEnd
Looks great man, is that UFO shooting or where those doodlers bullets?
ok ive tried a version of the code above to make pretty good gravity...but the problem is that since doodler jumps down more that 4 pixels per frame sometimes, he skips through the platforms and does not hit them! can someone please help me avoid this?what are other ways off simulating gravity??
xPos = doodler's x positionyPos = doodler's foot positionxPlat = platform's x positionyPlat = platform's y positionheight = platform's heightwidth = platform's width.if(xPlat <= xPos and (xPlat + width >= xPos) and (yPlat <= yPos) and (yPlat + height >= yPos)//doodler's foot is in a platform, so jump up.