Requesting Code Snippets on movement controllers

BlitzMax Forums/BlitzMax Programming/Requesting Code Snippets on movement controllers

Hey guys, I was wondering if you could post a few code snippets for movement paths?

Right now I am using bezier curves to move my aliens, which looks GREAT but.... Well, there are a few things I would like to do.

Like.. move down.. spin.. move back up... move to point A, curve around point B, etc.

Right now its just "follow bezier curve" and that's not working for what I want to do.

Would be nice if some of you Pro's out there would be willing to post a few code snippets on other methods on controlling enemy objects!!!

Thanks :)

Type TMove_Event
	
	Method Update:Byte(Child:TMobject)
	End Method
	
End Type

Type TWayPoint Extends TMove_Event
	Field X:Float
	Field Y:Float
	Field Speed:Float
	Field IsInRangeX:Byte
	Field IsInRangeY:Byte
	
	Function create:TWayPoint(X:Float,Y:Float,S:Float)
		Local W:TWayPoint = New TWayPoint
		W.X = X
		W.Y = Y
		W.Speed = S
		Return W
	End Function
	
	Method Update:Byte(Child:TMobject)
		
		Local CX:Float = Child.X
		Local CY:Float = Child.Y
		
		Local Angle=(ATan2(Y-CY,X-CX)+360) Mod 360 
		
		Local vx:Float = Cos(Angle)*Speed
		Local vy:Float = Sin(Angle)*Speed
		
		Child.X:+Vx
		Child.Y:+Vy
		
		IsInrangeX = CheckRange(CX,X,2)
		IsInrangeY = CheckRange(CY,Y,2)
		
		If  IsInRangeX = True And IsInRangeY = True Then 
			Return True
		Else
			Return False
		End If
		
	End Method
	
End Type

Type TRotateAround Extends TMove_Event
	Field Speed:Float	
	Field Times:Int
	Field CurRot:Int = 0
	Field Angle:Float = 0
	
	Function create:TRotateAround(Speed:Float,Times:Int)
		Local R:TRotateAround = New TRotateAround
		R.Speed = Speed
		R.Times = Times
		
		Return R
	End Function
	
	Method Update:Byte(Child:TMObject)
		Self.angle:+Speed
		If Self.Angle > 359 Then
			Self.Angle = 0
			CurRot:+1
		End If
		
		Child.Angle = Self.Angle
		
		If Times = CurRot Then 
			CurRot = 0
			Return True
		Else
			Return False
		End If
	End Method
	
End Type
		
Type TMovement_Manager
	Field Events:TMove_Event[0]
	Field Current_Event:Int = 0
	Field Child:TMObject
	
	
	Function create:TMovement_Manager(Child:TMObject)
		Local M:TMovement_Manager = New TMovement_Manager
		M.Child = Child
		Return M
	End Function
	
	Method AddEVent(Event:TMove_Event)
		Events = Events[..EVents.length+1]
		Events[Events.Length-1] = Event
	End Method
	
	Method Update()
		
		Local W:Byte
	    W = Events[Current_Event].Update(Child)
		
		If W = True  Then
			Current_Event:+1
			If Current_Event > Events.Length-1 Then Current_Event = 0
		EndIf		
		
	End Method
	
	Method GetWayPoint:Int()
		Return Current_WayPoint
	End Method
End Type

Function CheckRange:Byte(P1:Int,P2:Int,Toleranz:Int)
	If P1+Toleranz > P2 And P1-Toleranz < P2 Then Return True
    Return False
End Function

Type TMObject
	Field x:Float
	Field y:Float
	Field angle:Float
End Type


Type Player Extends TMobject

	Function create:Player()
		Return New Player
	End Function
	
	Method Draw()
		SetRotation Angle
		DrawRect x,y,20,20
		SetRotation 0
	End Method
End Type

Graphics 800,600,0,60

Local P:Player = Player.Create()
P.X = 300
P.Y = 400

Local Way1:TWayPoint = TWayPoint.Create(200,200,2.0)
Local Way2:TWayPoint = TWayPoint.Create(100,400,4.0)
Local Way3:TWayPoint = TWayPoint.Create(600,500,1.0)
Local Way4:TWayPoint = TWayPoint.Create(200,200,5.0)
Local Turn1:TRotateAround = TRotateAround.Create(5.0,10)
Local Turn2:TRotateAround = TRotateAround.Create(10.0,20)


Local Manager:TMovement_Manager = TMoveMent_Manager.Create(P)
Manager.AddEvent(Way1)
Manager.AddEvent(Turn1)
Manager.AddEvent(Way2)
Manager.AddEvent(Way3)
Manager.AddEvent(Turn2)
Manager.AddEvent(Way4)

While Not KeyHit(Key_Escape)

P.Draw()
Manager.Update()

DrawText "X : " + P.X,20,20
DrawText "Y : " + P.Y,20,40
DrawText "WayPoint : " + Manager.GetWayPoint(),20,60
'DrawText "IsinX : " + Manager.IsInRangeX,20,80
'DrawText "IsInY : " + Manager.IsInRangeY,20,100

Flip
Cls
Wend


Its late here, so I haven't comment it, if you have questions to the code just ask.