On SetVector
Quadrant_old = Quadrant
If tracker.LocH < Mouse_H and tracker.LocV < Mouse_V then
side_A = Mouse_V - tracker.locV
side_B = Mouse_H - tracker.locH
side_C = sqrt(power(side_A,2) + power(side_B,2))
Quadrant = "NW"
End If
If tracker.LocH > Mouse_H and tracker.LocV < Mouse_V then
-- North East
side_A = Mouse_V - tracker.locV
side_B = tracker.locH - Mouse_H
side_C = sqrt(power(side_A,2) + power(side_B,2))
Quadrant = "NE"
End If
If tracker.LocH < Mouse_H and tracker.LocV > Mouse_V then
-- South West
side_A = tracker.locV - Mouse_V
side_B = Mouse_H - tracker.locH
side_C = sqrt(power(side_A,2) + power(side_B,2))
Quadrant = "SW"
End If
If tracker.LocH > Mouse_H and tracker.LocV > Mouse_V then
-- South East
side_A = tracker.locV - Mouse_V
side_B = tracker.locH - Mouse_H
side_C = sqrt(power(side_A,2) + power(side_B,2))
Quadrant = "SE"
End If
If tracker.LocH = Mouse_H then
If tracker.LocV > Mouse_V then
-- Up
Quadrant = "UP"
Else If tracker.LocV < Mouse_V then
-- Down
Quadrant = "DOWN"
End if
End if
if tracker.LocV = Mouse_V then
If tracker.LocH > Mouse_H then
-- Left
Quadrant = "LEFT"
Else If tracker.LocH < Mouse_H then
-- Right
Quadrant = "RIGHT"
End If
End If
End SetVector
On TranVector
-- Function to perform any translations along the previously setup Vector
If MouseClicked = True then
-- Get Current Angle of the Vector
Vec_Angle = acos(side_B / side_C)
-- Increment Along the Vector
side_C_translate = side_C_translate + MoveSpeed
-- Get the point along the Incremented Vector in X & Y for repositioning of the Tracker.
trans_A = side_C_translate * sin(Vec_Angle)
trans_B = side_C_translate * cos(Vec_Angle)
-- Check if its already There
If tracker.locH >= Mouse_H and tracker.LocV >= Mouse_V and Quadrant = "NW" then
MouseClicked = False
Set_Standing
exit
Else If tracker.locH <=Mouse_H and tracker.LocV <= Mouse_V and Quadrant = "SE" then
MouseClicked = False
Set_Standing
exit
Else If tracker.LocH <= Mouse_H and tracker.LocV >= Mouse_V and Quadrant = "NE" then
MouseClicked = False
Set_Standing
exit
Else If tracker.LocH >= Mouse_H and tracker.LocV <= Mouse_V and Quadrant = "SW" then
MouseClicked = False
Set_Standing
exit
Else If tracker.locH = Mouse_H and tracker.LocV <= Mouse_V and Quadrant = "Up" then
MouseClicked = False
Set_Standing
exit
Else If tracker.locH = Mouse_H and tracker.LocV >= Mouse_V and Quadrant = "Down" then
MouseClicked = False
Set_Standing
exit
Else If tracker.locH <= Mouse_H and tracker.locV = Mouse_V and Quadrant = "Left" then
MouseClicked = False
Set_Standing
exit
Else If tracker.locH >= Mouse_H and tracker.locV = Mouse_V and Quadrant = "Right" then
MouseClicked = False
Set_Standing
exit
end if
AllowMove = true
-- Check For No Intersections, if False then move the tracker.
-- if AllowMove = True then
gMovedAmt = gMovedAmt + 1
LocH_old = tracker.locH
LocV_old = tracker.locV
Rot_Old = tracker.rotation
If Quadrant = "NW" then
tracker.locH = integer(Original_PosH + trans_B)
tracker.locV = integer(Original_posV + trans_A)
Else If Quadrant = "NE" then
tracker.locH = integer(Original_PosH - trans_B)
tracker.locV = integer(Original_posV + trans_A)
Else If Quadrant = "SW" Then
tracker.locH = integer(Original_PosH + trans_B)
tracker.locV = integer(Original_posV - trans_A)
Else if Quadrant = "SE" then
tracker.locH = integer(Original_PosH - trans_B)
tracker.locV = integer(Original_posV - trans_A)
Else If Quadrant = "UP" then
tracker.locV = tracker.LocV - movespeed
Else If Quadrant = "DOWN" then
tracker.locV = tracker.LocV + movespeed
Else If Quadrant = "LEFT" then
tracker.locH = tracker.LocH - movespeed
Else if Quadrant = "RIGHT" then
tracker.locH = tracker.LocH + movespeed
End if
--End if
updatestage
Repeat with x = 1 to gCheeseList.Count
If sprite(tracker).intersects(sprite(GetAt(gCheeseList,x))) Then
AllowMove = False
End if
End Repeat
If sprite(tracker).intersects(sprite(1)) then
AllowMove = False
End if
If AllowMove = False then
--if sprite(tracker).intersects(sprite(1)) = True then
tracker.LocH = LocH_old
tracker.LocV = LocV_old
tracker.rotation = Rot_Old
set_standing
MouseClicked = False
exit
End if
End If
End TranVector
on Set_Standing
Sprite("character").member = member("step_02")
End Set_Standing
On Rotate_Character
-- The clever stuff!
-- Function to find the 'C' angle - the angle between the characters current orientation and
-- the desired orientation (the latest mouse click)
-- Find the Current Rotation and Mod it so the result is within 0-360
Rots = mod2(tracker.rotation,360)
If Rots < 0 then
Rots = Rots * -1
Rots = mod2((720 - Rots),360)
End If
-- Angle_B is taken from the trackers current orientation, brought within limits,
-- Converted to my own rataional systems limits (0-360 East AntiClockWise) & Converted to Radians.
AngB = mod2((450 - Rots),360) * pi/180
-- Get Angle_A by using the ArcTangent Function. Returns <0>
AngA_X = tracker.LocH - Mouse_H
AngA_Y = tracker.LocV - Mouse_V
AngA = atan(AngA_Y,AngA_X)
-- Make Sure Angle_A > 0 and +/- 360degrees(2pi radians) to bring inline with Angle_B
If AngA >= 0 then
AngA = pi - AngA
Else If AngA < 0 Then
AngA = AngA * -1 + pi
End If
-- Get Angle_C (the amount the guy is going to rotate) from Angle_A and Angle_B
If AngA > AngB then
AngC = AngA - AngB
Else If AngB > AngA then
AngC = AngB - AngA
Else If AngA = AngB then
AngC = 0
End If
-- Setup Rotation Direction so the Guy Only Rotates the shortest way. If its spot on pi rads then go clockwise.
If AngA < AngB then
If AngC > pi then
RotDirection = "CCW"
AngC = 2*pi - AngC
Else If AngC < pi then
RotDirection = "CW"
End If
Else If AngA > AngB then
If AngC > pi then
RotDirection = "CW"
Else If AngC < pi then
RotDirection = "CCW"
End If
Else If AngC = pi then
RotDirection = "CW"
Else If AngC = 0 THen
RotDirection = "0"
end if
-- Make sure Angle_C is the shortest angle.
If AngC > pi then
AngC = 2*pi - AngC
End if
-- If there is no rotation to be done. Exit the function
If AngA = AngB then
Exit
end if
-- Set the Target Rotaion Value.
If RotDirection = "CCW" Then
tracker.Rotation = tracker.Rotation - (AngC * 180/pi) + 180
Else If RotDirection = "CW" Then
tracker.Rotation = tracker.rotation + (AngC * 180/pi) + 180
Else If RotDirection = "0" Then
Exit
End If
End Rotate_Character