public static void AddEnemy(Vector2 squareLocation)
        {
            int startX = (int)squareLocation.X;
            int startY = (int)squareLocation.Y;

            Rectangle squareRect =
                TileMap.SquareWorldRectangle(startX, startY);

            Enemy newEnemy = new Enemy(
                new Vector2(squareRect.X, squareRect.Y),
                enemyTexture,
                enemyInitialFrame);

            newEnemy.currentTargetSquare = squareLocation;
            Enemies.Add(newEnemy);
        }
Beispiel #2
0
        public static void AddComputerTerminal()
        {
            int startX = rand.Next(2, TileMap.MapWidth - 2);
            int startY = rand.Next(0, TileMap.MapHeight - 2);

            Vector2 tileLocation = new Vector2(startX, startY);

            if ((TerminalInSquare(tileLocation) != null) ||
                (TileMap.IsWallTile(tileLocation)))
            {
                return;
            }

            if (Vector2.Distance(
                    TileMap.GetSquareCenter(startX, startY),
                    Player.BaseSprite.WorldCenter) < minDistanceFromPlayer)
            {
                return;
            }

            List <Vector2> path =
                PathFinder.FindPath(
                    new Vector2(startX, startY),
                    TileMap.GetSquareAtPixel(
                        Player.BaseSprite.WorldCenter));

            if (path != null)
            {
                Rectangle squareRect =
                    TileMap.SquareWorldRectangle(startX, startY);

                Sprite activeSprite = new Sprite(
                    new Vector2(squareRect.X, squareRect.Y),
                    texture,
                    initialActiveFrame,
                    Vector2.Zero);

                for (int x = 1; x < 3; x++)
                {
                    activeSprite.AddFrame(
                        new Rectangle(
                            initialActiveFrame.X + (x *
                                                    initialActiveFrame.Width),
                            initialActiveFrame.Y,
                            initialActiveFrame.Width,
                            initialActiveFrame.Height));
                }
                activeSprite.CollisionRadius = 15;

                Sprite disabledSprite = new Sprite(
                    new Vector2(squareRect.X, squareRect.Y),
                    texture,
                    initialDisabledFrame,
                    Vector2.Zero);

                for (int x = 1; x < 3; x++)
                {
                    disabledSprite.AddFrame(
                        new Rectangle(
                            initialDisabledFrame.X + (x *
                                                      initialDisabledFrame.Width),
                            initialDisabledFrame.Y,
                            initialDisabledFrame.Width,
                            initialDisabledFrame.Height));
                }

                ComputerTerminal terminal = new ComputerTerminal(
                    activeSprite,
                    disabledSprite,
                    new Vector2(startX, startY));

                float timerOffset = (float)rand.Next(1, 100);
                terminal.LastSpawnCounter = timerOffset / 100f;

                computerTerminals.Add(terminal);

                activeCount++;
            }
        }