2D Vector fun

BlitzMax Forums/BlitzMax Programming/2D Vector fun

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hey guys. I'm messing with vectors for the first time(in game programming).

What can I do to get this ball from sinking when it runs out of energy??


Sorry, my TVect2 object is pretty overdone(lots of code) for my simple needs, figured I get most of the maths of vectors done early, though i'm still missing things like reflect and dot product.
SuperStrict
Type TVect2
	Field x:Float, y:Float
	
	Method Create:TVect2(_x:Float,_y:Float) 
		Local v:TVect2 = New TVect2
		v.x = _x
		v.y = _y
		Return v
	End Method
	
	Method GetX:Float() 
		Return x
	End Method
	
	Method GetY:Float()
		Return y
	End Method
	
	Method SetX(_x:Float) 
		x = _x
	End Method
	
	Method SetY(_y:Float) 
		y = _y
	End Method
	
	Method GetAngle:Float()
		Return ATan2(y,x)
	End Method
	
	Method Rotate(ang:Float)
		Local xprime:Float=Cos(ang)*x - Sin(ang)*y 
		Local yprime:Float=Sin(ang)*x + Cos(ang)*y
		x=xprime
		y=yprime
	End Method
	
	Method Add(_x:Float,_y:Float)
		x:+_x
		y:+_y
	End Method
	
	Method AddVec(Vec:TVect2)
		If Vec=Null Return
		x:+Vec.x
		y:+Vec.y
	End Method

	Method Subtract(_x:Float,_y:Float)
		x:-_x
		y:-_y
	End Method
	
	Method SubtractVec(Vec:TVect2)
		If Vec=Null Return
		x:-Vec.x
		y:-Vec.y
	EndMethod
	
	Method Multiply(_x:Float,_y:Float)
		x:*_x
		y:*_y
	EndMethod

	Method MultiplyVec(Vec:TVect2)
		If Vec=Null Return
		x:*Vec.x
		y:*Vec.y
	EndMethod
	
	Method Divide(_x:Float,_y:Float)
		If _x = 0 Or _y = 0 return
		x:/_x
		y:/_y
	EndMethod

	Method DivideVec(Vec:TVect2)
		If Vec=Null Return
		x:/Vec.x
		y:/Vec.y
	EndMethod
End Type

AppTitle = "Ball Vector example"
Graphics 800 , 600

Local ballx:Float = 400
Local bally:Float = 550
Local ballvector:TVect2 = New TVect2.Create(1 , - 8) 
Local gravity:TVect2 = New TVect2.Create(0 , .1) 
Local bounceloss:TVect2 = New TVect2.Create(0 , 1)

While Not KeyHit(KEY_ESCAPE) 
	Cls
	If bally > 580 ballvector.Rotate(180) ballvector.AddVec(bounceloss)
	ballvector.AddVec(gravity) 
	ballx:+ ballvector.GetX() 
	bally:+ ballvector.GetY()
	
	DrawOval ballx,bally,10,10
	
	
	Flip 1
Wend


Thanks!