Code archives/Algorithms/Very Simple Gravity

This code has been declared by its author to be Public Domain code.

Download source code

Very Simple Gravity by IPete22006
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

puki2006
I demand a port to Blitz3D.


wedoe2006
A tiny update, he he

Global  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



Damien Sturdy2006
Puki... looks like this code would work in B3D, too... :P


Pineapple2006
It does! :)

Dabz


puki2006
I don't like ovals.


Rck2006
Hacks, but simple


Code Archives Forum