Understanding cos & sin

BlitzMax Forums/BlitzMax Beginners Area/Understanding cos & sin

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.

Something like this?
Const Vertical:Int = 0
Const Horizontal:Int = 1


Type TMover
	Field Speed:Float
	Field X# , Y#
	Field Angle:Int = 0
	Field Mode:Int
	
	Function Create:TMover(X , Y , Speed:Float,Mode:Int = Horizontal)
		
		Local M:TMover = New TMover
		
		M.X = X
		M.Y = Y
		M.Speed = Speed
		M.Mode = Mode
		
		Return M
		
	End Function
	
	Method Update()
		Select Mode
			Case Horizontal
				Y:+ (Sin(Angle) * Speed)
				X:+ Speed
			Case Vertical
				X:+ (Cos(Angle) * Speed)
				Y:+ Speed
		End Select
		
		If X > GraphicsWidth() Then X:- GraphicsWidth()
		If X < 0 Then Y:+ GraphicsHeight() 
		If Y > GraphicsHeight() Then Y:- GraphicsHeight()
		If Y < 0 Then Y:+GraphicsHeight()

		
		Angle:+ 1
		If Angle > 359 Then Angle = 0	
		Draw()
	End Method
	
	Method Draw()
		DrawOval X , Y , 15 , 15
	End Method
End Type

Graphics 800 , 600 , 0 , 60

Local M:TMover = TMover.Create(400 , 300 , 0.8 , Vertical)
Local M2:TMover = TMover.Create(400 , 300 , 1.6 , Horizontal)


While Not KeyHit(Key_Escape)
	Cls
	SetColor 0,255,0
	M.Update()
	SetColor 255,0,0
	M2.Update()
	Flip
Wend