Strict
Import common

Class RunningMovement
Private
	Field positions: Point2D[]
	Field dir: Int
	Field curFrame: Int
	Field totalFrames: Int
Public
	
	Method New (movementWidth: Int, decayRate: Float, steps: Int)
		totalFrames = steps
		
		'Compute Positions
		Local xStep: Float = Float(movementWidth) / Float(steps - 1)
		Local xCenter: Int = movementWidth/2
		Local a: Float = -Abs(decayRate)
		Local b: Float = -xCenter*2*a
		Local x: Int, y: Int

		positions = New Point2D[steps]
		For Local st: Int = 0 Until steps
			x = st*xStep
			y = a*x*x + b*x
			positions[st] = New Point2D(x- xCenter, y)
		Next
		
		Reset()
	End
	
	Method Reset: Void()
		dir = -1
		curFrame = totalFrames/2
	End

	Method GetPosition: Point2D()
		Return positions[curFrame]
	End
	
	Method IsEndPoint: Bool()
		If curFrame = totalFrames/2 Then Return True
		Return False
	End
	
	Method Update: Void()
		If dir >= 0 Then 
			curFrame = curFrame + 1
			If curFrame >= totalFrames Then
				curFrame = totalFrames - 1
				dir = -1
			Endif
		Else
			curFrame = curFrame - 1
			If curFrame < 0 Then
				curFrame = 0
				dir = 1
			Endif
		Endif
	End
End
