Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Maneuvering Objects
 

Maneuvering Objects

How can I tell if objects are blocking my path?
MigrationUser 1  Saturday, June 21, 2003 9:09 PM
Draw a line between your bug and your target.  At each point in the line, calculate the cell that contains the point.  If the cell is different than the previous one, check to see if your bug can be in that cell without overlapping any other organism.  If, when you run into something, it's your target, you're OK.  Otherwise you are going to have to use a more sophisticated path finding algorithm (A* is the most popular choice).

Psuedo code.

ArrayList orgs = Scan();
OrganismState blockedBy = null;
Point oldCell;
Point newCell;

while( blockedBy == null)
{
   // TODO: Get the next point in the line.
   // TODO: Calculate the cell position
   if( newCell != oldCell)
   {
      oldCell = newCell;

      for each( OrganismState org in orgs)
      {
         if( Math.Max( Math.Abs( newCell.X - org.GridX), Math.Abs( newCell.Y - org.GridY)) <= State.CellRadius + org.CellRadius)
         {
            blockedBy = org;
            break;
         }
      }
   }
}

The old animal farm had some line drawing algorithms.  Perhaps Henrik Yllemo's .chm file has one of them (http://www.yllemo.com/terrarium).
MigrationUser 1  Sunday, June 22, 2003 10:42 PM

You can use google to search for other answers

Custom Search

More Threads

• Web service security
• Can not receive animals
• Puzzled
• have any framework support windows-based applicaton ?
• Source code for the Objects should be included
• Write Permission to the Photos Folder
• IssueVision installation problem...
• Just try too...
• Advanced Questions?
• Can't load the Deer.dll to Terrarium game