コード例 #1
0
        public static void InitializeMapFromLevel(this AStarMap map, Tile[,] maptiles)
        {
            int yLength = maptiles.GetLength(0);
            int xLength = maptiles.GetLength(1);
            Node[,] aStarNodes;
            aStarNodes = new Node[yLength, xLength];
            for (int y = 0; y < yLength; y++)
            {
                for (int x = 0; x < xLength; x++)
                {
                    Walkable walkable = Walkable.Walkable;
                    switch (maptiles[y, x].TileType)
                    {
                        case TileType.Wall:
                        case TileType.Spike:
                            walkable = Walkable.Blocked;
                            break;

                        case TileType.Platform:
                            walkable = Walkable.Platform;
                            break;
                    }
                    if (walkable == Walkable.Walkable)
                    {
                        if (CheckForUnreachable(maptiles, y, x))
                            walkable = Walkable.NotReachable;

                    }

                    aStarNodes[y, x] = new Node(x, y, Tile.TILE_SIZE, walkable);
                }
            }
            AStarMap.InitializeMap(aStarNodes);
        }
コード例 #2
0
ファイル: Quadtree.cs プロジェクト: pampersrocker/STAR
        public Quadtree(Tile[,] leveltiles, int layers)
        {
            levelBoundingBox = new Rectangle(
                0,
                0,
                leveltiles.GetLength(1) * Tile.TILE_SIZE,
                leveltiles.GetLength(0) * Tile.TILE_SIZE);
            rootNode = new QuadTreeNode(levelBoundingBox, layers, leveltiles);
            current_rects = new List<Rectangle>();
            MaxLayer = layers;

            enemyCollisionTiles = new List<Tile>[Environment.ProcessorCount];
            enemyiterateNodes = new List<QuadTreeNode>[Environment.ProcessorCount];
        }
コード例 #3
0
        /// <summary>
        /// Checks if the specified Tile is Unreachable for the AStar Algorithm.<para>(KI can not reach it by walking or jumping)</para>
        /// </summary>
        /// <param name="maptiles">The Level Tiles</param>
        /// <param name="tileX">x Coordinate of the Specified Tile</param>
        /// <param name="tileY">y Coordinate of the Specified Tile</param>
        /// <returns><para>True if tile is unreachable</para>, <para>Fals if tile is reachable.</para></returns>
        private static bool CheckForUnreachable(Tile[,] maptiles, int tileX, int tileY)
        {
            bool unreachable = true;

            int yOffset;
            int xOffset;
            int mapYMax = maptiles.GetLength(1);
            int mapXMax = maptiles.GetLength(0);
            //Build a Pyramide with height of 3 under the CurrentMaptile to check if it is Unreachable
            for (xOffset = 1; xOffset <= 4 && unreachable && xOffset + tileX < mapXMax; xOffset++)
            {
                for (yOffset = -xOffset; yOffset <= xOffset && unreachable && yOffset + tileY < mapXMax && yOffset + tileY >= 0; yOffset++)
                {
                    unreachable = !maptiles[tileX + xOffset, tileY + yOffset].Standable;
                }
            }
            return unreachable;
        }
コード例 #4
0
ファイル: Tile.cs プロジェクト: pampersrocker/STAR
 public void loadGrass(Tile[,] tiles)
 {
     int max_height = tiles.GetLength(0);
     int max_width = tiles.GetLength(1);
     if (tile_x - 1 >= 0)
     {
         if (tiles[tile_y, tile_x - 1].TileType != TileType.Wall)
         {
             grass[(int)GrassType.Left].rect = new Rectangle(rect.Left, rect.Top, 10, TILE_SIZE);
             grass[(int)GrassType.Left].type = GrassType.Left;
         }
         else
         {
             grass[(int)GrassType.Left].rect = Rectangle.Empty;
             grass[(int)GrassType.Left].type = GrassType.Empty;
         }
     }
     else
     {
         grass[(int)GrassType.Left].rect = new Rectangle(rect.Left, rect.Top, 10, TILE_SIZE);
         grass[(int)GrassType.Left].type = GrassType.Left;
     }
     if (tile_x + 1 < max_width)
     {
         if (tiles[tile_y, tile_x + 1].TileType != TileType.Wall)
         {
             grass[(int)GrassType.Right].rect = new Rectangle(rect.Right - 10, rect.Top, 10, TILE_SIZE);
             grass[(int)GrassType.Right].type = GrassType.Right;
         }
         else
         {
             grass[(int)GrassType.Right].rect = Rectangle.Empty;
             grass[(int)GrassType.Right].type = GrassType.Empty;
         }
     }
     else
     {
         grass[(int)GrassType.Right].rect = new Rectangle(rect.Right - 10, rect.Top, 10, TILE_SIZE);
         grass[(int)GrassType.Right].type = GrassType.Right;
     }
     if (tile_y - 1 >= 0)
     {
         if (tiles[tile_y - 1, tile_x].TileType != TileType.Wall)
         {
             grass[(int)GrassType.Top].rect = new Rectangle(rect.Left - 5, rect.Top - 5, TILE_SIZE + 10, 20);
             grass[(int)GrassType.Top].type = GrassType.Top;
         }
         else
         {
             grass[(int)GrassType.Top].rect = Rectangle.Empty;
             grass[(int)GrassType.Top].type = GrassType.Empty;
         }
     }
     else
     {
         grass[(int)GrassType.Top].rect = new Rectangle(rect.Left - 5, rect.Top - 5, TILE_SIZE + 10, 20);
         grass[(int)GrassType.Top].type = GrassType.Top;
     }
     if (tile_y + 1 < max_height)
     {
         if (tiles[tile_y + 1, tile_x].TileType != TileType.Wall)
         {
             grass[(int)GrassType.Bottom].rect = new Rectangle(rect.Left, rect.Bottom - 10, TILE_SIZE, 10);
             grass[(int)GrassType.Bottom].type = GrassType.Bottom;
         }
         else
         {
             grass[(int)GrassType.Bottom].rect = Rectangle.Empty;
             grass[(int)GrassType.Bottom].type = GrassType.Empty;
         }
     }
     else
     {
         grass[(int)GrassType.Bottom].rect = new Rectangle(rect.Left, rect.Bottom - 10, TILE_SIZE, 10);
         grass[(int)GrassType.Bottom].type = GrassType.Bottom;
     }
 }
コード例 #5
0
ファイル: LevelMDIChild.cs プロジェクト: pampersrocker/STAR
 public void SetLevel(Tile[,] newtiles)
 {
     levelControl1.Level.Tiles = newtiles;
     levelControl1.SetBorders(newtiles.GetLength(1), newtiles.GetLength(0));
     //Focus();
 }
コード例 #6
0
ファイル: Enemy.KI.cs プロジェクト: pampersrocker/STAR
        private void CliffJump(float elapsed,Tile[,] map)
        {
            int xpos = (int)pos.X / Tile.TILE_SIZE;
            int ypos = (int)pos.Y / Tile.TILE_SIZE;
            if (xpos + 1 < map.GetLength(1) && xpos - 1 >= 0 && ypos + 1 < map.GetLength(0))
            {
                if (map[ypos + 1, xpos].Standable)
                    if (rundirection == StandardDirection.Left)
                    {
                        if (map[ypos + 1, xpos - 1].TileColission_Type == TileCollision.Passable)
                            Jump(elapsed, false,4);
                    }
                    else if (map[ypos + 1, xpos + 1].TileColission_Type == TileCollision.Passable && rundirection == StandardDirection.Right)
                        Jump(elapsed, false,4);

            }
        }