Example #1
0
        private void UpdateEnemies()
        {
            if (enemies.CountEntities() <= 0)
            {
                switch (rnd.Next(2))
                {
                case 0:
                    AddEnemies(new Squadron.Formation(rnd.Next(4, 7)));
                    break;

                default:
                    AddEnemies(new Squadron.Vformation(rnd.Next(4, 9)));
                    break;
                }
                NextMovementStrategy();
            }
        }
Example #2
0
 public void ItterateEnemies()
 {
     if (enemies.CountEntities() == 0)
     {
         GalagaBus.GetBus().RegisterEvent(
             GameEventFactory <object> .CreateGameEventForAllProcessors(
                 GameEventType.GameStateEvent,
                 this,
                 "CHANGE_STATE",
                 "GAME_WON", ""));
     }
     enemies.Iterate(delegate(Enemy enemy) {
         if (enemy.Shape.Position.Y < 0f)
         {
             GalagaBus.GetBus().RegisterEvent(
                 GameEventFactory <object> .CreateGameEventForAllProcessors(
                     GameEventType.GameStateEvent,
                     this,
                     "CHANGE_STATE",
                     "GAME_LOST", ""));
         }
     });
 }
Example #3
0
        public bool CleanEnemies()
        {
            EntityContainer <Enemy> newEnemies = new EntityContainer <Enemy>();

            foreach (Enemy enemy in Enemies)
            {
                if (enemy.IsDestroyed())
                {
                    Score.GetInstance().AddPoint(enemy.Points);
                    enemy.DeleteEntity();
                }

                if (!enemy.IsDeleted())
                {
                    newEnemies.AddDynamicEntity(enemy);
                }
            }

            Enemies = newEnemies;

            // returns false if squadron is empty
            return(newEnemies.CountEntities() > 0);
        }
Example #4
0
        /// <summary>
        /// Add a new entity to the instance's platEntity EntityContainer. Also updates the
        /// boundingBox shape if the position and dimensions of the new shape exceed the ones of
        /// boundingBox. Also re-centers the platform's text label to the new center of the
        /// bounding box
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="image"></param>
        public void AddPlatform(StationaryShape shape, IBaseImage image)
        {
            if (platEntity.CountEntities() < 1)
            {
                boundingBox.Position = shape.Position.Copy();
                boundingBox.Extent   = shape.Extent.Copy();
            }

            platEntity.AddStationaryEntity(shape, image);
            if (shape.Position.X < boundingBox.Position.X)
            {
                boundingBox.Position.X = shape.Position.X;
            }

            if (shape.Position.Y < boundingBox.Position.Y)
            {
                boundingBox.Position.Y = boundingBox.Position.Y;
            }

            if (shape.Position.X + shape.Extent.X >
                boundingBox.Position.X + boundingBox.Extent.X)
            {
                boundingBox.Extent.X =
                    (shape.Position.X + shape.Extent.X) - boundingBox.Position.X;
            }

            if (shape.Position.Y + shape.Extent.Y >
                boundingBox.Position.Y + boundingBox.Extent.Y)
            {
                boundingBox.Extent.Y =
                    (shape.Position.Y + shape.Extent.Y) - boundingBox.Position.Y;
            }

            text.GetShape().Position = new Vec2F(
                boundingBox.Position.X + boundingBox.Extent.X / 2 - Constants.EXTENT_X / 2,
                boundingBox.Position.Y);
        }
        /// <summary>
        /// Builds a level object from the given level file path.
        /// </summary>
        /// <param name="filepath"></param>
        /// <returns></returns>
        public Level GetLevelFromFile(string filepath)
        {
            var levelContent = levelLoader.ReadFileContents(filepath);

            //parsing map
            var levelMap = levelContent[Constants.MAP];

            if (levelMap.Count != 23 || levelMap[0].Length != 40)
            {
                throw new Exception(
                          "Error building level. Level must be 40 lines x 23 characters.");
            }

            var platformIds = levelParser.ParsePlatformChars(levelContent[Constants.PLATFORMS]);

            if (platformIds.Count < 1)
            {
                throw new Exception("Error building level. Level must contain platforms.");
            }

            var levelImages = levelParser.ParseImages(levelContent[Constants.IMAGES]);

            if (levelImages.Count < 1)
            {
                throw new Exception("Error building level. Level must contain image mapping.");
            }

            Dictionary <char, Platform> platformDictionary = new Dictionary <char, Platform>();

            foreach (char platformChar in platformIds)
            {
                platformDictionary.Add(platformChar, new Platform(platformChar));
            }
            EntityContainer <Obstacle> obstacles = new EntityContainer <Obstacle>();
            EntityContainer            portals   = new EntityContainer();

            Vec2F extent = new Vec2F(Constants.EXTENT_X, Constants.EXTENT_Y);

            Vec2F  playerStartingPosition = null;
            Player player = new Player(null, null);

            //parsing level map
            int i = 0;

            foreach (string mapString in levelMap)
            {
                for (int j = 0; j < mapString.Length; j++)
                {
                    char  mapChar  = mapString[j];
                    Vec2F position =
                        new Vec2F(
                            j * Constants.EXTENT_X,
                            1 - i * Constants.EXTENT_Y - Constants.EXTENT_Y
                            );

                    StationaryShape shape = new StationaryShape(position, extent);
                    if (mapChar == ' ')
                    {
                        continue;
                    }

                    //checking the individual map chars
                    if (platformIds.Contains(mapString[j]))
                    {
                        platformDictionary[mapChar].AddPlatform(
                            shape, imageContainer.GetImageByName(levelImages[mapChar]));
                    }
                    else if (mapChar == '^')
                    {
                        portals.AddStationaryEntity(shape, null);
                    }
                    else if (mapChar == '<' || mapChar == '>')
                    {
                        playerStartingPosition =
                            new Vec2F(j * Constants.EXTENT_X, 1 - i * Constants.EXTENT_Y);
                        player.Shape.Position = playerStartingPosition;
                    }
                    else
                    {
                        var newObstacle = new Obstacle(shape, null)
                        {
                            Image = imageContainer.GetImageByName(levelImages[mapChar])
                        };
                        obstacles.AddStationaryEntity(newObstacle);
                    }
                }
                i++;
            }

            if (playerStartingPosition == null)
            {
                throw new Exception(
                          "Error building level. Level map must contain a starting position for player.");
            }

            if (portals.CountEntities() < 1)
            {
                throw new Exception(
                          "Error building level. Level map must contain portal entities.");
            }

            var levelCustomers =
                levelParser.ParseCustomerStrings(levelContent[Constants.CUSTOMERS]);

            var name = levelParser.ParseLevelName(levelContent[Constants.NAME]);

            return(new Level(
                       name,
                       portals,
                       obstacles,
                       platformDictionary,
                       levelCustomers,
                       player,
                       playerStartingPosition));
        }
 private bool CheckEnemiesDefeated()
 {
     return(enemies.CountEntities() == 0);
 }