public int Clear()
        {
            NavigFieldArray = new NavigationGridCell[xSize, ySize];

            for (int i = 0; i < xSize; i++)
                for (int j = 0; j < ySize; j++)
                {
                    NavigFieldArray[i, j] = new NavigationGridCell();

                    this.NavigFieldArray[i, j].optimalXPredecessor = i;
                    this.NavigFieldArray[i, j].optimalYPredecessor = j;
                }

            this.calcIterationsPassed = 0;
            this.preferredVelocity = 1;
            this.sleepTime = 0;

            return 0;
        }
Beispiel #2
0
        public int Clear()
        {
            NavigFieldArray = new NavigationGridCell[xSize, ySize];

            for (int i = 0; i < xSize; i++)
            {
                for (int j = 0; j < ySize; j++)
                {
                    NavigFieldArray[i, j] = new NavigationGridCell();

                    this.NavigFieldArray[i, j].optimalXPredecessor = i;
                    this.NavigFieldArray[i, j].optimalYPredecessor = j;
                }
            }

            this.calcIterationsPassed = 0;
            this.preferredVelocity    = 1;
            this.sleepTime            = 0;

            return(0);
        }
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(bckgrColor);

            arrow.Begin();
            aim.Begin();

            obstacle.Begin();

            arrow.DrawString(SpriteFont1,
                             "Calc iterations passed:   " + NavigationFieldSpace1.calcIterationsPassed.ToString(), new Vector2(0, 0), Color.Black);



            int xDrawCoord = 25;
            int yDrawCoord = 25;

            int dist = 20;



            for (int i = 0; i < NavigationFieldSpace1.xSize; i++)
            {
                for (int j = 0; j < NavigationFieldSpace1.ySize; j++)
                {
                    GridCell           GridCell1           = NavigationFieldSpace1.FieldArray[i, j];
                    NavigationGridCell NavigationGridCell1 = NavigationFieldSpace1.NavigFieldArray[i, j];

                    if (NavigationGridCell1.isAim)
                    {
                        aimDestination = new Rectangle(xDrawCoord + i * dist, yDrawCoord + j * dist, 10, 10);
                        aim.Draw(aimTexture, aimDestination, aimSource, bckgrColor, 0, new Vector2(50, 50), SpriteEffects.None, 0);

                        continue;
                    }

                    if (NavigationGridCell1.isObstacle)
                    {
                        obstacleDestination = new Rectangle(xDrawCoord + i * dist, yDrawCoord + j * dist, 10, 10);
                        obstacle.Draw(obstacleTexture, obstacleDestination, obstacleSource, bckgrColor, 0, new Vector2(50, 50), SpriteEffects.None, 0);

                        continue;
                    }
                    //var v = (int)Math.Round(20.0 * GridCell1.amplitude / NavigationFieldSpace1.preferredVelocity);
                    arrowDestination = new Rectangle(xDrawCoord + i * dist, yDrawCoord + j * dist, 15 + 0 * (int)Math.Round(15 * NavigationGridCell1.amplitude / NavigationFieldSpace1.preferredVelocity), 10);
                    arrow.Draw(arrowTexture, arrowDestination, arrowSource, bckgrColor, (float)NavigationGridCell1.angle, new Vector2(35, 13), SpriteEffects.None, 0);
                }
            }


            /*
             *  for (int x = 0; x < NavigationFieldSpace1.xSize; x++)
             *      for (int y = 0; y < NavigationFieldSpace1.ySize; y++)
             *      {
             *          arrowDestination = new Rectangle(xDrawCoord + x * dist, yDrawCoord + y * dist,
             *              (int)NavigationFieldSpace1.NavigFieldArray[x, y].amplitude * 10,
             *              (int)NavigationFieldSpace1.NavigFieldArray[x, y].amplitude);
             *          arrow.Draw(arrowTexture, arrowDestination, arrowSource, bckgrColor,
             *              (float)NavigationFieldSpace1.NavigFieldArray[x, y].angle,
             *              new Vector2(132, 13), SpriteEffects.None, 0);
             *
             *          if (!NavigationFieldSpace1.NavigFieldArray[x, y].isObstacle)
             *              arrow.DrawString(SpriteFont1,
             *              NavigationFieldSpace1.NavigFieldArray[x,y].pathCost.ToString(),
             *              //NavigationFieldSpace1.NavigFieldArray[x, y].xPredecessor.ToString() + " " +
             *              //NavigationFieldSpace1.NavigFieldArray[x, y].yPredecessor.ToString(),
             *              new Vector2(xDrawCoord + x * dist + 15, yDrawCoord + y * dist + 15), Color.Black);
             *          else
             *              arrow.DrawString(SpriteFont1, "inf",
             *              new Vector2(xDrawCoord + x * dist + 15, yDrawCoord + y * dist + 15), Color.Black);
             *      }
             */
            arrow.End();
            aim.End();
            obstacle.End();
            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }