Code archives/Algorithms/Very Simple Gravity
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This code is posted to provided an insight into putting gravity onto an object in BMax. This is about as simple as it gets. We draw an oval, draw it at "y" and adjust "y" using gravity (pre set to 2) and an acceleration offset ymov (starts at 0 and is adjusted each loop). Try it and watch and adjust the bounce. | |||||
Global ymov = 0 Global grav = 2 Global y =10 Graphics 800,600,2 While Not KeyDown(key_ESCAPE) ymov = ymov+ grav y=y+ymov If y>=355 Then y = 355 ymov=ymov*-1 EndIf DrawOval 320,y,20,20 Flip 1 Cls Wend End |
Comments
| ||
I demand a port to Blitz3D. |
| ||
A tiny update, he heGlobal ymov = 0 Global grav = 2 Global y =10 Graphics 800,600,0,0 While Not KeyDown(key_ESCAPE) ymov = ymov+ grav y=y+ymov If y>=555 Then y = 555 ymov=ymov*-1 EndIf If KeyDown(key_SPACE) Then y=10 ymov=0 EndIf DrawOval 320,y,20,20 Flip 1 Cls Wend End |
| ||
Puki... looks like this code would work in B3D, too... :P |
| ||
It does! :) Dabz |
| ||
I don't like ovals. |
| ||
Hacks, but simple |
Code Archives Forum