Пример #1
0
            public Wing(Vector2 parentPos, WingSide wingSide, int range, List <Rectangle> parentBoundingBoxes)
            {
                this.parentPos    = new Vector2(parentPos.X, parentPos.Y);
                centerOfExplosion = new Vector2(parentPos.X + Game1.textureManager.explosionCenter.First().Width / 2, parentPos.Y + Game1.textureManager.explosionCenter.First().Height / 2);
                this.wingSide     = wingSide;
                this.range        = range;

                if (wingSide == WingSide.Right)
                {
                    for (int i = 1; i <= range; i++)
                    {
                        if (GridManager.checkIfBlockExist(new Vector2(this.centerOfExplosion.X + i * 32, this.centerOfExplosion.Y), "Block Wall Explosion"))
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X + i * 32, parentPos.Y), "ExplosionRightEnd"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X + i * 32, (int)parentPos.Y, 32, 32));
                            break;
                        }
                        else if (GridManager.checkIfBlockExist(new Vector2(this.centerOfExplosion.X + i * 32, this.centerOfExplosion.Y), "Dirt"))
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X + i * 32, parentPos.Y), "ExplosionRightEnd"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X + i * 32, (int)parentPos.Y, 32, 32));
                            Vector2 blockPos = GridManager.GetOnGridPosition(this.centerOfExplosion.X + i * 32, this.centerOfExplosion.Y);
                            if (Map.blocks[(int)blockPos.X, (int)blockPos.Y].label.Equals("Dirt"))
                            {
                                Dirt tempDirt = (Dirt)Map.blocks[(int)blockPos.X, (int)blockPos.Y];
                                tempDirt.startDestroyAnimation = true;
                            }
                            break;
                        }
                        if (i == range)
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X + i * 32, parentPos.Y), "ExplosionRightEnd"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X + i * 32, (int)parentPos.Y, 32, 32));
                        }
                        else
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X + i * 32, parentPos.Y), "ExplosionHorizontalCenter"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X + i * 32, (int)parentPos.Y, 32, 32));
                        }
                    }
                }
                else if (wingSide == WingSide.Left)
                {
                    for (int i = 1; i <= range; i++)
                    {
                        if (GridManager.checkIfBlockExist(new Vector2(this.centerOfExplosion.X - i * 32, this.centerOfExplosion.Y), "Block Wall Explosion"))
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X - i * 32, parentPos.Y), "ExplosionLeftEnd"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X - i * 32, (int)parentPos.Y, 32, 32));
                            break;
                        }
                        else if (GridManager.checkIfBlockExist(new Vector2(this.centerOfExplosion.X - i * 32, this.centerOfExplosion.Y), "Dirt"))
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X - i * 32, parentPos.Y), "ExplosionLeftEnd"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X - i * 32, (int)parentPos.Y, 32, 32));
                            Vector2 blockPos = GridManager.GetOnGridPosition(this.centerOfExplosion.X - i * 32, this.centerOfExplosion.Y);
                            if (Map.blocks[(int)blockPos.X, (int)blockPos.Y].label.Equals("Dirt"))
                            {
                                Dirt tempDirt = (Dirt)Map.blocks[(int)blockPos.X, (int)blockPos.Y];
                                tempDirt.startDestroyAnimation = true;
                            }
                            break;
                        }
                        if (i == range)
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X - i * 32, parentPos.Y), "ExplosionLeftEnd"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X - i * 32, (int)parentPos.Y, 32, 32));
                        }
                        else
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X - i * 32, parentPos.Y), "ExplosionHorizontalCenter"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X - i * 32, (int)parentPos.Y, 32, 32));
                        }
                    }
                }
                else if (wingSide == WingSide.Top)
                {
                    for (int i = 1; i <= range; i++)
                    {
                        if (GridManager.checkIfBlockExist(new Vector2(this.centerOfExplosion.X, this.centerOfExplosion.Y - i * 32), "Block Wall Explosion"))
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X, parentPos.Y - i * 32), "ExplosionTopEnd"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X, (int)parentPos.Y - i * 32, 32, 32));
                            break;
                        }
                        else if (GridManager.checkIfBlockExist(new Vector2(this.centerOfExplosion.X, this.centerOfExplosion.Y - i * 32), "Dirt"))
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X, parentPos.Y - i * 32), "ExplosionTopEnd"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X, (int)parentPos.Y - i * 32, 32, 32));
                            Vector2 blockPos = GridManager.GetOnGridPosition(this.centerOfExplosion.X, this.centerOfExplosion.Y - i * 32);
                            if (Map.blocks[(int)blockPos.X, (int)blockPos.Y].label.Equals("Dirt"))
                            {
                                Dirt tempDirt = (Dirt)Map.blocks[(int)blockPos.X, (int)blockPos.Y];
                                tempDirt.startDestroyAnimation = true;
                            }
                            break;
                        }
                        if (i == range)
                        {
                            wingParts.Add(new WingPart(new Vector2(this.parentPos.X, this.parentPos.Y - i * 32), "ExplosionTopEnd"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X, (int)parentPos.Y - i * 32, 32, 32));
                        }
                        else
                        {
                            wingParts.Add(new WingPart(new Vector2(this.parentPos.X, this.parentPos.Y - i * 32), "ExplosionVerticalCenter"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X, (int)parentPos.Y - i * 32, 32, 32));
                        }
                    }
                }
                else if (wingSide == WingSide.Bottom)
                {
                    for (int i = 1; i <= range; i++)
                    {
                        if (GridManager.checkIfBlockExist(new Vector2(this.centerOfExplosion.X, this.centerOfExplosion.Y + i * 32), "Block Wall Explosion"))
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X, parentPos.Y + i * 32), "ExplosionBottomEnd"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X, (int)parentPos.Y + i * 32, 32, 32));
                            break;
                        }
                        else if (GridManager.checkIfBlockExist(new Vector2(this.centerOfExplosion.X, this.centerOfExplosion.Y + i * 32), "Dirt"))
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X, parentPos.Y + i * 32), "ExplosionBottomEnd"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X, (int)parentPos.Y + i * 32, 32, 32));
                            Vector2 blockPos = GridManager.GetOnGridPosition(this.centerOfExplosion.X, this.centerOfExplosion.Y + i * 32);
                            if (Map.blocks[(int)blockPos.X, (int)blockPos.Y].label.Equals("Dirt"))
                            {
                                Dirt tempDirt = (Dirt)Map.blocks[(int)blockPos.X, (int)blockPos.Y];
                                tempDirt.startDestroyAnimation = true;
                            }
                            break;
                        }
                        if (i == range)
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X, parentPos.Y + i * 32), "ExplosionBottomEnd"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X, (int)parentPos.Y + i * 32, 32, 32));
                        }
                        else
                        {
                            wingParts.Add(new WingPart(new Vector2(parentPos.X, parentPos.Y + i * 32), "ExplosionVerticalCenter"));
                            parentBoundingBoxes.Add(new Rectangle((int)parentPos.X, (int)parentPos.Y + i * 32, 32, 32));
                        }
                    }
                }
            }
Пример #2
0
        private void generateMap()
        {
            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    if (x == 0 || x == cols - 1 || y == 0 || y == rows - 1)
                    {
                        blocks[x, y] = new Wall(new Vector2(Map.mapPosition.X + x * blockSize, Map.mapPosition.Y + y * blockSize), new Vector2(x, y));
                    }
                    else if (x % 2 == 0 && y % 2 == 0)
                    {
                        blocks[x, y] = new Block(new Vector2(Map.mapPosition.X + x * blockSize, Map.mapPosition.Y + y * blockSize));
                    }
                    else
                    {
                        blocks[x, y] = new Grass(new Vector2(Map.mapPosition.X + x * blockSize, Map.mapPosition.Y + y * blockSize));

                        Vector2 tempVector   = new Vector2(x, y);
                        Boolean onSpawnPoint = false;
                        if (random.Next(0, 100) > DIRT_SPAWN_CHANCE && !(tempVector.Equals(spawnPoints[0]) || tempVector.Equals(spawnPoints[1]) || tempVector.Equals(spawnPoints[2]) || tempVector.Equals(spawnPoints[3])))
                        {
                            for (int i = 0; i < spawnPoints.Length; i++)
                            {
                                if (tempVector.Equals(spawnPoints[i]) ||
                                    tempVector.Equals(new Vector2(spawnPoints[i].X, spawnPoints[i].Y - 1)) ||
                                    tempVector.Equals(new Vector2(spawnPoints[i].X, spawnPoints[i].Y + 1)) ||
                                    tempVector.Equals(new Vector2(spawnPoints[i].X - 1, spawnPoints[i].Y)) ||
                                    tempVector.Equals(new Vector2(spawnPoints[i].X + 1, spawnPoints[i].Y)))
                                {
                                    onSpawnPoint = true;
                                }
                            }
                            if (!onSpawnPoint)
                            {
                                blocks[x, y] = new Dirt(new Vector2(Map.mapPosition.X + x * blockSize, Map.mapPosition.Y + y * blockSize));
                            }
                        }
                        else
                        {
                            if (random.Next(0, 100) < 10)
                            {
                                tempVector = new Vector2(Map.mapPosition.X + x * blockSize, Map.mapPosition.Y + y * blockSize);
                                tempVector = GridManager.GetOnGridPosition(tempVector.X, tempVector.Y);
                                for (int i = 0; i < spawnPoints.Length; i++)
                                {
                                    if (tempVector.Equals(spawnPoints[i]) ||
                                        tempVector.Equals(new Vector2(spawnPoints[i].X, spawnPoints[i].Y - 1)) ||
                                        tempVector.Equals(new Vector2(spawnPoints[i].X, spawnPoints[i].Y + 1)) ||
                                        tempVector.Equals(new Vector2(spawnPoints[i].X - 1, spawnPoints[i].Y)) ||
                                        tempVector.Equals(new Vector2(spawnPoints[i].X + 1, spawnPoints[i].Y)))
                                    {
                                        onSpawnPoint = true;
                                    }
                                }
                                if (!onSpawnPoint)
                                {
                                    Map.mapObjects.Add(new Enemy(new Vector2(Map.mapPosition.X + x * blockSize, Map.mapPosition.Y + y * blockSize)));
                                }
                            }
                        }
                    }
                }
            }
        }