Beispiel #1
0
        /// GameWorld constructor.
        public GameWorld()
        {
            stopwatch = new Stopwatch();
            stopwatch.Start();
            Gold  = 500;
            Lives = 50;
            // Initializes GameWorld.
            _instance = this;

            // Sets total amount of Tiles.
            tiles = tilesH * tilesV;
            // Creates an array of Tiles with size equal to total amount of tiles.
            tilesList = new BaseTile[tiles];
            // Initializes list of Towers.
            towers         = new List <Tower>();
            enemies        = new List <Enemy>();
            coins          = new Queue <Powerup>();
            flyingEntities = new List <FlyingEntity>();
            // Creates Graph.
            graph = new Graph();

            // Fills TileList with Tiles.
            float curX = 0, curY = 0;

            for (int i = 0; i < tiles; i++)
            {
                BaseTile tile = new BaseTile(new Vector2D(curX, curY));
                curX += BaseTile.size;
                if (curX >= (BaseTile.size * tilesH))
                {
                    curX  = 0;
                    curY += BaseTile.size;
                }
                this.tilesList[i] = tile;
            }

            // Adds coins to queue (to be able to explore them).
            coins.Enqueue(new Coin(0, 250, 30, 30));
            coins.Enqueue(new Coin(200, 250, 30, 30));
            coins.Enqueue(new Coin(0, 500, 30, 30));
            coins.Enqueue(new Coin(200, 500, 30, 30));


            // Initializes Graph.
            graph.InitializeGraph();
            // Sets startTile to be upper-left tile.
            startTile = tilesList[0];
            // sets startTile not Buildable.
            startTile.buildable = false;
            // Sets endTile to be bottom-right tile.
            endTile = tilesList[tiles - 1];
            // Sets endTile to not Buildable.
            endTile.buildable = false;
            Bat testEnemy = new Bat(waveCount);

            testEagle  = new Eagle(new Vector2D(100, 100), Vector2D.Zero, Vector2D.Zero, Vector2D.Zero, 20, 5, 5, 10, 10, BehaviorType.SEEK);
            testEagle2 = new Eagle(new Vector2D(100, 100), Vector2D.Zero, Vector2D.Zero, Vector2D.Zero, 20, 5, 5, 10, 10, BehaviorType.OFFSETPURSUIT);
            testEagle2.SetTargetAgent1(testEagle);
            testEagle3 = new Eagle(new Vector2D(100, 100), Vector2D.Zero, Vector2D.Zero, Vector2D.Zero, 20, 5, 5, 10, 10, BehaviorType.EXPLORE)
            {
                goals = coins,
            };
            // Deep copy of goals to be able keep repeating the original queue of goals.
            testEagle3.originalGoals = new Queue <Powerup>(coins);

            flyingEntities.Add(testEagle);
            flyingEntities.Add(testEagle2);
            flyingEntities.Add(testEagle3);
            testEnemy.pos      = tilesList[125].pos;
            testEnemy.path     = Path.GetPath(startTile, tilesList[674]);
            testEnemy.AddForce = new Seek();
            Instance.enemies.Add(testEnemy);
        }