Creating simple gravity - in BMax.

BlitzMax Forums/BlitzMax Beginners Area/Creating simple gravity - in BMax.

For those wondering of how to create simple gravity for objects in BMax, please see here:

www.blitzbasic.com/codearcs/codearcs.php?code=1709

Simple - almost too simple.

IPete2.

Yup, if you know things are 2D, you just add or multiply your y movement `adder` by a gravity value then add the total to the y coords.

cool Ipete2

here is one with some X added:

Global  yvelocity:Float = 0
Global  grav:Float = 0.1
Global  ypos:Float =10
Global  xvelocity:Float = 1
Global  xpos:Float

Graphics 1024,768
Global GHEIGHT = GraphicsHeight()
Global GWIDTH = GraphicsWidth()
Global timer:TTimer = CreateTimer(90)
While Not KeyDown(key_ESCAPE)
 
 	yvelocity:+ grav
	ypos:+yvelocity

	If ypos>=GHEIGHT Then 
		ypos = GHEIGHT
		yvelocity=(-yvelocity)*0.95
	EndIf 
	
	If xpos<0 Then xdirection = 1
	If xpos>GWIDTH Then xdirection = 0
	
	If xdirection = 1
		xpos:+xvelocity
		Else
		xpos:-xvelocity
	EndIf
	
DrawOval xpos,ypos,20,20
WaitTimer(timer)
Flip 1
Cls
 
Wend
End


Great stuff bill, thanks for the additions...

IPete2.

no problem. this kind of stuff is fun. I'll try some other stuff now...

any ideas?

this one appears a litle more elastic:

Global  yvelocity:Float = 0
Global  grav:Float = 0.1
Global  ypos:Float =10
Global  xvelocity:Float = 1
Global  xpos:Float

Graphics 1024,768
Global GHEIGHT = GraphicsHeight()
Global GWIDTH = GraphicsWidth()
Global timer:TTimer = CreateTimer(50)
While Not KeyDown(key_ESCAPE)
 
 	yvelocity:+ grav
	ypos:+yvelocity

	If ypos>=GHEIGHT-60 Then 
		ypos = GHEIGHT-60
		yvelocity=(-yvelocity)*0.95
	EndIf 
	
	If xpos<0 Then xdirection = 1
	If xpos>GWIDTH Then xdirection = 0
	
	If xdirection = 1
		xpos:+xvelocity
		Else
		xpos:-xvelocity
	EndIf
	
'SetRotation(45)
SetColor 255,0,0
If ypos>(GHEIGHT-80)
		DrawOval xpos,ypos,60,60-(Abs(yvelocity)/2)
	Else 
		DrawOval xpos,ypos,60-Abs(yvelocity),60+(Abs(yvelocity)*1.5)
EndIf

'DrawText(yvelocity,0,0)
WaitTimer(timer)
Flip 1
Cls
 
Wend
End


Ipete2: First code archive entry hey? Good to see you are getting to grips with BMax.

Well I guess the next thing to do is make it available to any object with a single call - using types...

Thanks Jake, Yeah I was interested n the Physics thread which seems to have died now...

And this is really just to highlight that you don't need complex physics, jusyt "as good as" will do.

IPete2.