Example #1
0
        private Vector2 determineMoveDirection()
        {
            if (reachedTargetSquare())
            {
                currentTargetSquare = getNewTargetSquare();
            }

            Vector2 squareCenter = TileMap.GetSquareCenter(currentTargetSquare);

            return(squareCenter - EnemySprite.WorldCenter);
        }
Example #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++;
            }
        }
Example #3
0
 private bool reachedTargetSquare()
 {
     return(Vector2.Distance(EnemySprite.WorldCenter, TileMap.GetSquareCenter(currentTargetSquare)) <= 2);
 }