This code has been declared by its author to be Public Domain code.Download source code
|Diminish () by BlitzSupport||(Posted 1+ years ago) |
| This code brings a value towards zero by the specified amount, regardless of whether it's less than or greater than zero. Simple, but very useful!|
Function Diminish# (value#, amount#)
If Abs (value) <= Abs (amount) Then Return 0
value = value - (amount * Sgn (value))
speed# = -100 ; 100
speed = Diminish (speed, 0.1)
Cls: Locate 10, 10: Print speed: Flip
Until speed = 0
|alanc5||(Posted 1+ years ago)|
| Could anyone give an example of how this would be used in a game? |
|John Blackledge||(Posted 1+ years ago)|
| Well, out of eight trials I see that only 3 exited with a value of zero.|
The others (despite the last line of code) exit with a value such as -0.02.
Why is that?
Code Archives Forum
|Floyd||(Posted 1+ years ago)|
| It always exits with a zero, but doesn't display properly.|
I think the default behavior of front and back buffers changed some time in the last five years. The example really should be writing to the back buffer and flipping.