public GameLevel(Game game, GamePlayState gameState, string levenName) : base(game) { this.gameState = gameState; levelRaw = ContentPreImporter.GetLevel(levenName); levelRend = new LevelRenderer(game, levelRaw); levelCollisions = new LevelCollisions(game, levelRaw); font = ContentPreImporter.GetFont("TextFont"); Vector3 playerPos = Vector3.Zero; int enemyFound = 0; //Build the game level creating the enemies, player and pickups for (int y = 0; y < levelRaw.Depth; y++) { for (int x = 0; x < levelRaw.Width; x++) { if (levelRaw.GetAt(x, y).ToString().ToLower() == "p") player = new Player(game, new Vector3(x, 0, y)); else if (levelRaw.GetAt(x, y).ToString().ToLower() == "e") { //Depending on the difficulty only add certain enemies enemyFound++; if ((enemyFound % GlobalSettings.EnemyFrequency) == 0) { objects.Add(new RedHead(game, new Vector3(x, 0, y), levelRaw)); enemies++; } } else if (levelRaw.GetAt(x, y).ToString().ToLower() == "g") { enemyFound++; if ((enemyFound % GlobalSettings.EnemyFrequency) == 0) { objects.Add(new GreenGhost(game, new Vector3(x, 0, y), levelRaw)); enemies++; } } else if (levelRaw.GetAt(x, y).ToString().ToLower() == "h") { objects.Add(new Health(game, new Vector3(x, 0, y))); } } } skybox = new Skybox(Game, 50, ContentPreImporter.GetTexture("grimmnight_small")); //Corner of the box if front left, so to place player in right place we need to add .5 to the left and .5 to the front objects.Add(player); // TODO: Construct any child components here }
public LevelCollisions(Game game, Level lev) : base(game) { level = lev; //Add a collision box for each wall for (int y = 0; y < level.Depth; y++) { for (int x = 0; x < level.Width; x++) { if (level.GetAt(x, y) == '#') { levelBoxes.Add(new BoundingBox( new Vector3(0.0f + x - 0.5f, 0.0f, 0.0f + y - 0.5f), new Vector3(1.0f + x - 0.5f, 1.0f, 1.0f + y - 0.5f) )); } } } }