Introduction
Author: Created by: X
Website: www.createdbyx.comThis
tutorial will walk you through creating a number of flies that will
fallow a scent trail, that you draw on the screen using the mouse. It
will be designed to show how easy it is to code AI to achieve simple
pathfinding/fallowing "fly like" behavior.
What you will needFor this tutorial we will be using vb.net 2005 and the .NET framework 2.0. But if you do not have Visual Studio 2005 you can
download it for free
on Microsoft’s website. This tutorial assumes that you are familiar
with the visual studio IDE, as well as the graphics objects under the
System.Drawing namespace.
Getting startedTo
begin you must first create a new windows application, under visual
studio. Second you will need to add a new code file and insert the
fallowing code into it.
- Public Module General
- Public Function RestrictValue(ByVal V As Single, ByVal Min As Single, ByVal Max As Single) As Single
- If V < Min Then V = Min
- If V > Max Then V = Max
- Return V
- End Function
- Public Function RestrictValue(ByVal V As Integer, ByVal Min As Integer, ByVal Max As Integer) As Integer
- If V < Min Then V = Min
- If V > Max Then V = Max
- Return V
- End Function
- Public Sub Displacement(ByVal X As Single, ByVal Y As Single, ByVal Distance As Single, ByVal AngleInRadians As Single, _
- ByRef NewX As Single, ByRef NewY As Single)
- NewX = CSng(X + (System.Math.Cos(AngleInRadians) * Distance))
- NewY = CSng(Y + (System.Math.Sin(AngleInRadians) * Distance))
- End Sub
- Public Function CircleCircle(ByVal Center1X As Single, ByVal Center1Y As Single, ByVal R1 As Single, _
- ByVal Center2X As Single, ByVal Center2Y As Single, ByVal R2 As Single,_
- Optional ByRef Distance As Single = 0) As Boolean
- Distance = CSng(Math.Sqrt((Math.Abs(Center1X - Center2X) ^ 2) + (Math.Abs(Center1Y - Center2Y) ^ 2)))
- Return Distance <= R1 + R2
- End Function
- End Module
The code provided above will be used by the application and provides
simple helper functions. This code will no be covered in this tutorial
as it is not relevant to the overall goal of this tutorial.