Exemplo n.º 1
0
        public Enemy(Vector2 position, float health, int bountyGiven, float speed, Player player, List<Texture2D> textures, Pathfinder pathFinder)
            : base(textures[0], position)
        {
            this.startHealth = health;
            this.currentHealth = startHealth;
            this.player = player;
            this.bountyGiven = bountyGiven;
            this.speed = speed;
            EnemyDied += new EnemyDiedEventHandler(player.RaiseStats);

            this.textures = textures;

            this.pathFinder = pathFinder;
        }
        private Queue<Wave> waves = new Queue<Wave>(); // A queue of all our waves

        #endregion Fields

        #region Constructors

        public WaveManager(Level level, int numberOfWaves, Player player, List<Texture2D> textures, Pathfinder pathFinder)
        {
            this.numberOfWaves = numberOfWaves;

            this.level = level;

            for (int i = 0; i < numberOfWaves; i++)
            {
                int initialNumerOfEnemies = 6;
                int numberModifier = (i / 6) + 1;

                Wave wave = new Wave(i, initialNumerOfEnemies *
                   numberModifier, level, player, textures, pathFinder);

                waves.Enqueue(wave);
            }

            StartNextWave();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Construct a new player.
        /// </summary>
        /// 
        public Player(ContentManager Content, string name)
        {
            pathFinder = new Pathfinder(level);
            this.name = name;
            this.money = 100;
            this.lives = 10;
            arrowNormal = Content.Load<Texture2D>("Game/arrow button");
            arrowHover = Content.Load<Texture2D>("Game/arrow hover");
            arrowPressed = Content.Load<Texture2D>("Game/arrow pressed");

            //Initialize the arrow button.

                arrowButton = new Button(arrowNormal, arrowHover,
                    arrowPressed, new Vector2(0, level.Height * 32));

                arrowButton.Clicked += new EventHandler(arrowButton_Clicked);

            SpriteFont font = Content.Load<SpriteFont>("Arial");

            Texture2D topBar = Content.Load<Texture2D>("Game/toolbar");
            enemyTextures = new List<Texture2D>();
            toolBar = new Toolbar(topBar, font, new Vector2(0, (level.Height) * 32));

            Texture2D grass = Content.Load<Texture2D>("Game/grass");
            Texture2D path = Content.Load<Texture2D>("Game/path");

            level.AddTexture(grass);
            level.AddTexture(path);

            enemyTextures.Add(Content.Load<Texture2D>("Game/enemy"));
            enemyTextures.Add(Content.Load<Texture2D>("Game/enemy50"));
            enemyTextures.Add(Content.Load<Texture2D>("Game/enemy25"));
            enemyTextures.Add(Content.Load<Texture2D>("Game/enemy00"));

            Texture2D towerTexture = Content.Load<Texture2D>("Game/arrowtower");
            Texture2D bulletTexture = Content.Load<Texture2D>("Game/bullet");

            waveManager = new WaveManager(level, 10, this, enemyTextures, pathFinder);

            this.towerTexture = towerTexture;
            this.bulletTexture = bulletTexture;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns wether the current cell is clear
        /// </summary>
        private bool IsCellClear(List<Enemy> enemies)
        {
            // Make sure tower is within limits
            bool spaceInBounds = cellX >= 0 && cellY >= 0 &&
                cellX < level.Width && cellY < level.Height;

            bool spaceClearOfEnemies = false;
            bool noEnemyLock = false;
            bool spaceClearOfTowers = false;

            if (spaceInBounds && !(cellX == 4 && cellY == 0) && !(cellX == 4 && cellY == 8))       // FLAGged pete
            {
                // Check for enemies on the spot
                Level lvlSave = new Level();
                lvlSave.Map = (int[,])level.Map.Clone();
                lvlSave.Map[cellX, cellY] = 1;  // maybe it does with x and y corrected.. SetWayPoint(cellX, cellY);// not changing anything oO?!.Map[cellY, cellX] = 1;
                Pathfinder hypoPath = new Pathfinder(lvlSave);

                if (enemies.Count != 0)
                {
                    foreach (Enemy e in enemies)
                    {
                        // TODOne somewhere in the code: Enemy setWaypoint and update; Player..well here /notsomuch: Update
                        // TODOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOne

                        // if enemy is not on the cell
                        spaceClearOfEnemies = (Math.Abs(e.Position.X - tileX) >= 32/*8*/ || Math.Abs(e.Position.Y - tileY) >= 32/*8*/) && (e.Waypoints.Peek().X != cellX/*tileX*/ || e.Waypoints.Peek().Y != cellY/*tileY*/) ? true : false;   // TODOne min 32 pixel dazwischen!
                        // ftodone when enemy would not move towards mouse potential new tower position, it should still be allowed

                        if (!spaceClearOfEnemies)
                        {
                            break;
                        }

                        if (e.Waypoints.Count > 0)
                        {
                            // enemies don't get locked in
                            if (hypoPath.FindPath(new Point((int)e.Waypoints.Peek().X / 32, (int)e.Waypoints.Peek().Y / 32), new Point(4, 8)).Count > 0)    // FLAGged
                            {
                                noEnemyLock = true;
                            }
                        }

                        if (!noEnemyLock)
                        {
                            break;
                        }
                    }

                }
                else
                {
                    spaceClearOfEnemies = true;
                    noEnemyLock = true;
                }
                // start to endpoint flow check
                if (hypoPath.FindPath(new Point(4, 0), new Point(4, 8)).Count < 1)
                    noEnemyLock = false;

                //ob ma durchkann oda nicht

                spaceClearOfTowers = (level.GetIndex(cellX, cellY) != 1);
            }
            //string s = "0";
            //if (spaceInBounds && spaceClearOfEnemies && spaceClearOfTowers && noEnemyLock)
            //    s = "";
            return spaceInBounds && spaceClearOfEnemies && spaceClearOfTowers && noEnemyLock; // If both checks are true return true
        }