public void SpawnFruit(int currentLevel) { DrawingRectangle source = DrawingRectangle.Empty; TileItem type; if (currentLevel == 1) { type = TileItem.Cherries; source = new DrawingRectangle(5, 3, 42, 48); } else if (currentLevel == 2) { type = TileItem.Strawberry; source = new DrawingRectangle(114, 2, 45, 50); } else if (currentLevel >= 3 && currentLevel <= 4) { type = TileItem.Peach; source = new DrawingRectangle(112, 55, 46, 52); } else if (currentLevel >= 5 && currentLevel <= 6) { type = TileItem.Apple; source = new DrawingRectangle(3, 55, 47, 51); } else if (currentLevel >= 7 && currentLevel <= 8) { type = TileItem.Grapes; source = new DrawingRectangle(2, 111, 50, 49); } else if (currentLevel >= 9 && currentLevel <= 10) { type = TileItem.Galaxian; source = new DrawingRectangle(109, 111, 52, 48); } else if (currentLevel >= 11 && currentLevel <= 12) { type = TileItem.Bell; source = new DrawingRectangle(2, 164, 49, 50); } else { type = TileItem.Key; source = new DrawingRectangle(120, 164, 30, 51); } var position = new Vector2(14 * PacmanGame.TileWidth, 20 * PacmanGame.TileWidth + PacmanGame.TileWidth / 2f); Fruit = new ScoreItem(type, 10, this, ScreenManager.BonusItemsTileset, position, source); }
/// <summary> /// Eat the item at position. /// </summary> /// <param name="position">Pac-Man position</param> /// <returns>Returns the type of item that was eaten.</returns> public TileItem EatItem(Vector2 position) { ScoreItem item = _tileItems[(int)position.X, (int)position.Y]; if (item != null) { var type = item.ItemType; if (type == TileItem.Dot) { DotsLeft--; Blinky.HandleElroy(ScreenManager.CurrentLevel, DotsLeft); } else if (type == TileItem.Energizer) { EnergizersLeft--; GhostMode = GhostMode.Frightened; } item.Eat(); _tileItems[(int)position.X, (int)position.Y] = null; // TODO: Spawn fruits after 70 dots or 70 dots+energizers? // 1st spawn after 70 dots have been cleared if (Fruit == null && DotsLeft == 170) { SpawnFruit(ScreenManager.CurrentLevel); } // 2nd spawn after 170 dots have been cleared if (Fruit == null && DotsLeft == 70) { SpawnFruit(ScreenManager.CurrentLevel); } return(type); } return(TileItem.None); }