Tutorials    Freebies    Links    Feedback    Thank me
Agent Store   Agent Games   Legal notice    History
Home

Intro»»Part 1»»Part 2

The procedure

Having added the Agent control to a form (this example uses Genie), create a new module and put this procedure into it:

Public Sub CharMove _
(TheCharacter As IAgentCtlCharacter, _
TheObject As Object, TheForm As Form, _
position As Byte, Optional Speed As Integer = 1000)

Dim X As Double, Y As Double, _
TpPX As Double, TpPY As Double
'sets up the variables to be used in the procedure.

TpPX = Screen.TwipsPerPixelX
'Makes TpPX equal to Screen.TwipsPerPixelX.

TpPY = Screen.TwipsPerPixelY
'Makes TpPY equal to Screen.TwipsPerPixelY.

X = ((TheForm.Left / TpPX) + (TheObject.Left / TpPX))
'Gets where the object is on the X axis.

Y = ((TheForm.Top / TpPY) + (TheObject.Top / TpPY))
'Gets where the object is on the Y axis.

Select Case position
Case 1 'left.
TheCharacter.MoveTo _
X - TheCharacter.Width, Y, Speed
Case 2 'right.
TheCharacter.MoveTo _
X + ((TheObject.Width / TpPX) _
+ (TheCharacter.Width * 0.1)), Y, Speed
Case 3 'top.
TheCharacter.MoveTo _
X, Y - TheCharacter.Height, Speed
Case 4 'bottom.
TheCharacter.MoveTo _
X, Y + ((TheObject.Height / TpPY) _
+ (TheCharacter.Height * 0.2)), Speed
End Select
End Sub

In the next part, I'll show how to use this.

Intro»»Part 1»»Part 2