コード例 #1
0
        public override void BuildBoard()
        {
            UpdatePosition();

            for (int i = 0; i < BoardWidth; i++)
            {
                for (int j = 0; j < BoardHeight; j++)
                {
                    //build the ground
                    var groundpiece = new BombermanFloorTile(_Style);
                    groundpiece.RegisterToBoardGameControlItem(this, new Point3D(i, j, 0));

                    BackgroundItems.Add(groundpiece);


                    //build the outer walls and inner grid walls
                    if (i == 0 || i == BoardWidth - 1 || j == 0 || j == BoardHeight - 1 || j % 2 == 0 && i % 2 == 0)
                    {
                        var wallpiece = new IndestructableWall(_Style, true);
                        wallpiece.RegisterToBoardGameControlItem(this, new Point3D(i, j, 0));

                        BackgroundItems.Add(wallpiece);
                    }
                    else
                    {
                        if (_State == BoardGameState.Active) //if a game is active, then build obstacles and such
                        {
                            //don't put obstacles in the player starting positions
                            if (i < 3 && j < 3 || i > BoardWidth - 4 && j < 3 || i < 3 && j > BoardHeight - 4 ||
                                i > BoardWidth - 4 && j > BoardHeight - 4)
                            {
                                continue;
                            }
                            if (j > BoardHeight / 2 - 2 && j < BoardHeight / 2 + 2 && (i < 3 || i > BoardWidth - 4))
                            {
                                continue;
                            }
                            if (i > BoardWidth / 2 - 2 && i < BoardWidth / 2 + 2 &&
                                (j < 3 || j > BoardHeight - 4))
                            {
                                continue;
                            }

                            //obstacles
                            if (Utility.RandomDouble() < BombermanSettings.OBSTACLE_CHANCE)
                            {
                                var wallpiece = new DestructableWall(_Style);
                                wallpiece.RegisterToBoardGameControlItem(this, new Point3D(i, j, 0));

                                BackgroundItems.Add(wallpiece);
                            }
                        }
                    }
                }
            }

            base.BuildBoard();
        }
コード例 #2
0
        public PointDetail GetPoint(int x, int y)
        {
            if (x < MinX)
            {
                throw new Exception($"Cannot get point where {nameof(x)} is less than {nameof(MinX)} {MinX}");
            }
            if (y < MinY)
            {
                throw new Exception($"Cannot get point where {nameof(y)} is less than {nameof(MinY)} {MinY}");
            }
            if (x > MaxX)
            {
                throw new Exception($"Cannot get point where {nameof(x)} is greater than {nameof(MaxX)} {MaxX}");
            }
            if (y > MaxY)
            {
                throw new Exception($"Cannot get point where {nameof(y)} is greater than {nameof(MaxY)} {MaxY}");
            }

            var point = new PointDetail(x, y);

            // find all the path intersections
            foreach (var path in Paths)
            {
                var intersect = point.GetPathIntersect(path);

                if (intersect != null)
                {
                    point.AddPathIntersect(intersect);
                }
            }

            // find all background intersections
            point.AddBackgroundItem(BackgroundItems.Where(i =>
                                                          i.TopLeftX <= x &&
                                                          (i.TopLeftX + i.Width - 1) >= x &&
                                                          i.TopLeftY <= y &&
                                                          (i.TopLeftY + i.Height - 1) >= y));

            // find all points of interest
            point.AddPointOfInterest(PointOfInterests.Where(i =>
                                                            i.X == x &&
                                                            i.Y == y));

            // is this point shrouded?
            point.IsShrouded = ShroudActive && !ShroudRevealedPoints.Contains(point);

            return(point);
        }
コード例 #3
0
        private void BuildLevel(List <string[]> levelData)
        {
            // iterate through lines
            for (int i = 0; i < levelData.Count(); i++)
            {
                switch (levelData[i][0])
                {
                case "00":
                    // mario
                    Mario.Instance.PlayableObjectState = new SmallRightIdleMario(Mario.Instance);
                    Mario.Instance.Position            = new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize);
                    break;

                case "01":
                    // floor tiles
                    StaticObjects.Add(new FloorTile(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), new Vector2(StringToInt(i, 3), StringToInt(i, 4)), levelData[i][5]));
                    break;

                case "02":
                    // blocks
                    Blocks.Add(new Block(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), levelData[i][3], levelData[i][4]));
                    break;

                case "03":
                    // floating coins
                    Coins.Add(new Item(new Vector2((StringToInt(i, 1) * levelCellSize) + (levelCellSize / 4), StringToInt(i, 2) * levelCellSize), "FloatingCoin"));
                    break;

                case "04":
                    // pipes
                    Pipes.Add(new Pipe(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), StringToInt(i, 3), Convert.ToBoolean(levelData[i][4]), levelData[i][5]));
                    break;

                case "05":
                    // enemies
                    Enemies.Add(new Enemy(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize - 10), levelData[i][3]));
                    break;

                case "06":
                    // hills
                    BackgroundItems.Add(new Hill(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), StringToInt(i, 3)));
                    break;

                case "07":
                    // bushes
                    BackgroundItems.Add(new Bush(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), StringToInt(i, 3)));
                    break;

                case "08":
                    // clouds
                    BackgroundItems.Add(new Cloud(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), StringToInt(i, 3)));
                    break;

                case "09":
                    // castle
                    Castle = new Castle(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize));
                    break;

                case "10":
                    // flag pole
                    Flagpoles.Add(new Flagpole(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), levelCellSize));
                    break;

                case "11":
                    // check point
                    Checkpoints.Add(new CheckPoint(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize)));
                    break;

                case "12":
                    // coin room
                    CoinRoomPosition = new Vector2(StringToInt(i, 1) * levelCellSize + (levelCellSize / 8), StringToInt(i, 2) * levelCellSize);
                    break;
                }
            }

            DynamicObjects.Add(Mario.Instance);

            foreach (Block block in Blocks)
            {
                DynamicObjects.Add(block);
                DynamicObjects.Add(block.Item); // Add items in each block too.
            }

            foreach (Item coin in Coins)
            {
                DynamicObjects.Add(coin);
            }

            foreach (Enemy enemy in Enemies)
            {
                // Added such that the Koopa spawns in a correct position before any updates are made, otherwise he spawns in the floor to start.
                if (enemy.EnemyState.ToString() == "SuperMario.EnemyStates.LeftWalkingKoopa" || enemy.EnemyState.ToString() == "SuperMario.EnemyStates.RightWalkingKoopa")
                {
                    enemy.Position = new Vector2(enemy.Position.X, enemy.Position.Y - GameValues.KoopaPositionOffset);
                }
                DynamicObjects.Add(enemy);
            }

            foreach (Pipe pipe in Pipes)
            {
                StaticObjects.Add(pipe);
            }

            foreach (Flagpole flagpole in Flagpoles)
            {
                StaticObjects.Add(flagpole);
            }

            if (Flagpoles.Count > 0)
            {
                Flag.Position = new Vector2(Flagpoles[0].CollisionRectangle.X - GameValues.FlagPositionOffsetVector.X, Flagpoles[0].CollisionRectangle.Y + GameValues.FlagPositionOffsetVector.Y);
            }
        }
コード例 #4
0
 public void AddBackgroundItem(IEnumerable <BackgroundItem> backgroundItems)
 {
     BackgroundItems.AddRange(backgroundItems);
 }
コード例 #5
0
 public void AddBackgroundItem(BackgroundItem backgroundItem)
 {
     BackgroundItems.Add(backgroundItem);
 }