Esempio n. 1
0
        public static List<Alien> Build(int playerNumber, int waveSize, int startX, int deltaX)
        {
            var map = Match.GetInstance().Map;
            var deltaY = playerNumber == 1 ? -1 : 1;
            var middleHeightOfMap = map.Height / 2;

            // make sure aliens dont go out of map
            while (map.IsOutOfXBounds(startX + 3 * deltaX * (waveSize - 1)))
            {
                startX -= 3 * deltaX;
            }

            // Spawn
            var wave = new List<Alien>();
            var alienY = middleHeightOfMap + deltaY;
            var alienX = startX;
            Alien alien = null;
            for (var i = 0; i < waveSize; i++)
            {
                try
                {
                    alien = new Alien(playerNumber) { X = alienX, Y = alienY };
                    alien.DeltaX = deltaX;

                    map.AddEntity(alien);
                    wave.Add(alien);

                    //test
                    Match.GetInstance().Map.AddTempEntity(new NodeEntity(Match.GetInstance().Depth, alien));
                }
                catch (CollisionException ex)
                {
                    var depth = Match.GetInstance().Depth;

                    var nodeAlien = new NodeEntity(depth, alien);
                    Match.GetInstance().Map.AddTempEntity(nodeAlien);//for undo purposes

                    //keep up with score kill special case
                    Match.GetInstance().Map.AddKillEntity(nodeAlien);
                    Match.GetInstance().Map.AddKillEntity(new NodeEntity(depth, ex.Entity, hasMoved: false, isKillLikely: true));

                    // Alien[0]
                    // Missile[1]

                    ex.Entity.Destroy();

                    if (ex.Entity.GetType() == typeof(Missile))
                    {
                        ((Missile)ex.Entity).ScoreKill(alien);
                    }
                }

                alienX += 3 * deltaX;
            }

            return wave;
        }
Esempio n. 2
0
 public void AddTempEntity(NodeEntity nodeEntity)
 {
     TempEntities.Add(nodeEntity);
 }
Esempio n. 3
0
 public void AddKillEntity(NodeEntity nodeEntity)
 {
     KillEntities.Add(nodeEntity);
 }
Esempio n. 4
0
 public void AddTempEntity(NodeEntity nodeEntity)
 {
     UpdateManager.AddTempEntity(nodeEntity);
 }
Esempio n. 5
0
 internal void AddKillEntity(NodeEntity nodeEntity)
 {
     UpdateManager.AddKillEntity(nodeEntity);
 }
Esempio n. 6
0
        public void SpawnShip()
        {
            var map = Match.GetInstance().Map;
            var ship = new Ship(PlayerNumber)
            {
                X = map.Width / 2 - 1,
                Y = PlayerNumber == 1 ? map.Height - 3 : 2
            };

            try
            {
                if (Match.GetInstance().GetRoundNumber() > 0) Lives--;
                map.AddEntity(ship);
                Ship = ship;

                //test
                Match.GetInstance().Map.AddTempEntity(new NodeEntity(Match.GetInstance().Depth, ship));
            }
            catch (CollisionException e)
            {
                foreach (Entity entity in e.Entities)
                {
                    if (entity.GetType() == typeof(Missile))
                    {
                        ((Missile)entity).ScoreKill(ship);

                        var depth = Match.GetInstance().Depth;

                        var nodeShip = new NodeEntity(depth, ship);

                        Match.GetInstance().Map.AddTempEntity(nodeShip);

                        Match.GetInstance().Map.AddKillEntity(new NodeEntity(depth, entity, isKillLikely: true));

                        Match.GetInstance().Map.AddKillEntity(nodeShip);

                        entity.Destroy();
                        OnShipKilled();
                    }
                    else if (entity.GetType() == typeof(Alien) || entity.GetType() == typeof(Bullet))
                    {
                        Match.GetInstance().Map.AddKillEntity(new NodeEntity(Match.GetInstance().Depth, entity));
                        entity.Destroy();
                        OnShipKilled();
                    }
                }
            }
        }