Hi
Now download Go After Game with source code
Dim px, py, cx, cy As Double
Dim dst As Double
Dim shpcenterX, shpcenterY As Integer
Dim truedistX, truedistY As Integer
Dim angle As Integer
Dim fkangle As Integer
Dim step As Boolean
Dim colorSh(1 To 6) As Long
Dim i As Integer
Dim m As Double
Const pi = 3.14
Dim dx, dy, steps As Double
Dim xj, yj As Double
Dim xIncrement, yIncrement As Double
Private Function Deg_to_Rad(angle1 As Double) As Double
'Changing from degrees to radians
Deg_to_Rad = angle1 * pi / 180
End Function
Private Function polar_cox(orgx As Double, tht As Double, r As Double) As Double
'Change from polar coordinates defined by angle and radius
'to cartesian coordinates at x-axis
polar_cox = orgx + r * Cos(Deg_to_Rad(tht))
End Function
Private Function polar_coy(orgy As Double, tht As Double, r As Double) As Double
'Change from polar coordinates defined by angle and radius
'to cartesian coordinates at y-axis
polar_coy = orgy + r * Sin(Deg_to_Rad(tht))
End Function
Private Sub Form_Load()
Timer1.Enabled = False
px = Shape1.Left + (Shape1.Width / 2)
py = Shape1.Top + (Shape1.Height / 2)
step = True
i = 1
colorSh(1) = &HFF&
colorSh(2) = &H80FF&
colorSh(3) = &HFFFF&
colorSh(4) = &HC000&
colorSh(5) = &HFF0000
colorSh(6) = &HC000C0
m = 0
xj = (Me.Width / 2) - (Shape1.Width / 2)
yj = (Me.Height / 2) - (Shape1.Height / 2)
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Timer1.Enabled = True
px = Shape1.Left + (Shape1.Width / 2)
py = Shape1.Top + (Shape1.Height / 2)
cx = X
cy = Y
Me.Line (px, py)-(cx, cy)
dst = Sqr((px - cx) ^ 2 + (py - cy) ^ 2)
Me.Circle (px, py), (dst), QBColor(Rnd * 15)
If step = True Then
Me.Cls
Me.Line (px, py)-(cx, cy)
Me.Circle (px, py), (dst), QBColor(Rnd * 15)
step = False
Else
step = True
End If
shpcenterX = Shape1.Left + (Shape1.Width / 2)
shpcenterY = Shape1.Top + (Shape1.Height / 2)
truedistX = X - shpcenterX
truedistY = shpcenterY - Y
angle = Atn(truedistY / truedistX) * (180 / pi)
'calculating measure of angle in degrees from each quadrant
If truedistX < 0 And truedistY < 0 Then
angle = Atn(truedistY / truedistX) * (180 / pi) + 180
ElseIf truedistX < 0 And truedistY > 0 Then
angle = Atn(truedistY / truedistX) * (180 / pi) + 180
ElseIf truedistX > 0 And truedistY < 0 Then
angle = Atn(truedistY / truedistX) * (180 / pi) + 360
End If
fkangle = Abs(angle - 360)
Shape2.Left = polar_cox(px + 0, fkangle + 40, 150) - (Shape2.Width / 2)
Shape2.Top = polar_coy(py + 0, fkangle + 40, 150) - (Shape2.Height / 2)
Shape3.Left = polar_cox(px + 0, fkangle - 40, 150) - (Shape3.Width / 2)
Shape3.Top = polar_coy(py + 0, fkangle - 40, 150) - (Shape3.Height / 2)
Me.Caption = "Angle : " & angle
drawName
End Sub
Private Sub Form_Resize()
' Shape1.Left = (Me.Width / 2) - (Shape1.Width / 2)
' Shape1.Top = (Me.Height / 2) - (Shape1.Height / 2)
End Sub
Private Sub Timer1_Timer()
'Moving Timer (The Timer which moves the shape of that head with its eyes)
dx = cx - px
dy = cy - py
If Abs(dx) > Abs(dy) Then
steps = Abs(dx)
Else
steps = Abs(dy)
End If
xIncrement = dx / steps
yIncrement = dy / steps
xj = xj + (xIncrement * 15)
yj = yj + (yIncrement * 15)
Shape1.Left = xj
Shape1.Top = yj
'Adjusting the eyes to move with the head
px = Shape1.Left + (Shape1.Width / 2)
py = Shape1.Top + (Shape1.Height / 2)
Shape2.Left = polar_cox(px + 0, fkangle + 40, 150) - (Shape2.Width / 2)
Shape2.Top = polar_coy(py + 0, fkangle + 40, 150) - (Shape2.Height / 2)
Shape3.Left = polar_cox(px + 0, fkangle - 40, 150) - (Shape3.Width / 2)
Shape3.Top = polar_coy(py + 0, fkangle - 40, 150) - (Shape3.Height / 2)
End Sub
Private Sub Timer2_Timer()
Shape1.FillColor = colorSh(i)
i = i + 1
If i >= 6 Then i = 1
drawName
End Sub
Private Function drawName()
For m = 10 To Me.Width Step 1000
For k = 10 To Me.Height Step 1000
Me.CurrentX = m
Me.CurrentY = k
Print " Petro "
Next k
Next m
End FunctionPetro