/* Start() - when game begins
  *
  * initializes waypoints
  *
  */
 private void Start()
 {
     enemy  = GetComponent <EnemyPink>();
     target = Waypoints.points[waypointIndex];
 }
Beispiel #2
0
        /// <summary>
        /// Loads the level map from resource map file and initializes
        /// all necessary local variables accordingly.
        /// </summary>
        /// <param name="level">current game level</param>
        private void loadMap(int level)
        {
            // all levels are of same width and height (20 x 20)
            width  = 20;
            height = 20;

            this.level = level;

            // initializing default level state (level is beginning, then chase mode first, no blue ghosts)
            blueGhosts   = false;
            levelBegin   = true;
            eatingPacMan = false;
            setChase(true);

            levelBeginTimer = 3000;
            lastTime        = Timing.Now();

            string[] file = LevelLoader.loadMapToString("Content/maps/" + level + ".lvl").Split(new char[] { '\n' });

            // first line of resource map file contains PacMan starting position
            string[] pacManCoordinates = file[0].Split(new char[] { ' ' });
            int      pacManSpawnX      = LevelLoader.parseInt(pacManCoordinates[0]);
            int      pacManSpawnY      = LevelLoader.parseInt(pacManCoordinates[1]);

            entityManager.getPacMan().setxSpawn(pacManSpawnX * Tile.SIZE);
            entityManager.getPacMan().setySpawn(pacManSpawnY * Tile.SIZE);
            entityManager.getPacMan().setX(entityManager.getPacMan().getxSpawn());
            entityManager.getPacMan().setY(entityManager.getPacMan().getySpawn());

            // initialize the tile array
            tiles = new int[width, height];

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // there is no food underneath PacMan's starting position
                    if ((y == pacManSpawnY) && (x == pacManSpawnX))
                    {
                        tiles[x, y] = EMPTY;
                        continue;
                    }

                    // convert character from resource map file to integer
                    int c = LevelLoader.charToInt(file[1 + y][x]);

                    switch (c)
                    {
                    case WALL:
                        tiles[x, y] = WALL;
                        continue;

                    case KILLER_FOOD:
                        entityManager.addFood(new FoodKiller(handler, x * Tile.SIZE, y * Tile.SIZE));
                        break;

                    case BANANA:
                        entityManager.addFood(new FoodBanana(handler, x * Tile.SIZE, y * Tile.SIZE));
                        break;

                    case CHERRY:
                        entityManager.addFood(new FoodCherry(handler, x * Tile.SIZE, y * Tile.SIZE));
                        break;

                    case STRAWBERRY:
                        entityManager.addFood(new FoodStrawberry(handler, x * Tile.SIZE, y * Tile.SIZE));
                        break;

                    case ENEMY_PINK:
                        // pink enemy needs to be accessed by red enemy to properly count red enemy's target tile,
                        // hence it is stored in the entity manager by itself
                        EnemyPink pinkie = new EnemyPink(handler, x * Tile.SIZE, y * Tile.SIZE);
                        entityManager.addMoving(pinkie);
                        entityManager.setPinkie(pinkie);
                        break;

                    case ENEMY_PURPLE:
                        entityManager.addMoving(new EnemyPurple(handler, x * Tile.SIZE, y * Tile.SIZE));
                        break;

                    case ENEMY_RED:
                        entityManager.addMoving(new EnemyRed(handler, x * Tile.SIZE, y * Tile.SIZE));
                        break;

                    case ENEMY_YELLOW:
                        entityManager.addMoving(new EnemyYellow(handler, x * Tile.SIZE, y * Tile.SIZE));
                        break;

                    case EMPTY:
                        entityManager.addFood(new FoodNormal(handler, x * Tile.SIZE, y * Tile.SIZE));
                        foodCount++;
                        break;

                    case EMPTY_WITHOUT_FOOD:
                    default:
                        break;
                    }

                    tiles[x, y] = EMPTY;
                }
            }

            // PacMan is added as last to the entity manager, in order to render him as last
            entityManager.addMoving(entityManager.getPacMan());
        }