public void LoadLevel(Scene scene, int levelNum) { string levelNumStr = Convert.ToString(levelNum); // Load In Level level = new LevelLoader(); string filePath = "/Application/maps/level" + levelNumStr + ".tmx"; XMLLoader.LoadLevel(level, filePath); // Load In Objects spikes = level.LoadInSpikes(scene); // Level sprites = level.LoadInLevel(scene); // Obstacles blackHoles = level.LoadInBlackHoles(scene); breakableWalls = level.LoadInBreakableWalls(scene); laserGates = level.LoadInLaserGates(scene); windTunnels = level.LoadInWindTunnels(scene); // Collectables coins = level.LoadInCoins(scene); gems = level.LoadInGems(scene); //Player Position spawnPoint = level.playerPos; levelFlag = level.LoadInFlag(scene); overallLevelScore = level.CalculateOverallLevelScore(); }
public void AddObject(string type, float x, float y, float rotation) { switch (type) { // Collectables case "Coin": Coin coin = new Coin(); coin.setPosition(new Vector2(x, y)); coin.setRotation(-rotation); coins.Add(coin); break; case "Gem": Gem gem = new Gem(); gem.setPosition(new Vector2(x, y)); gem.setRotation(-rotation); gems.Add(gem); break; // Obstacles case "Small Spikes": Spikes smallSpikes = new Spikes(1); if (rotation == 0) { smallSpikes.setPosition(new Vector2(x, y - 100.0f)); } else { smallSpikes.setPosition(new Vector2(x - 220.0f, y - 165.0f)); } //rotation += 270; smallSpikes.setRotation(-rotation); spikes.Add(smallSpikes); break; case "Large Spikes": Spikes largeSpikes = new Spikes(2); if (rotation == 0) { largeSpikes.setPosition(new Vector2(x, y - 100.0f)); } else { largeSpikes.setPosition(new Vector2(x - 240.0f, y - 210.0f)); } //rotation += 270; largeSpikes.setRotation(-rotation); spikes.Add(largeSpikes); break; case "Black Hole": BlackHole blackHole = new BlackHole(); if (rotation == 0) { blackHole.setPosition(new Vector2(x, y)); } else { blackHole.setPosition(new Vector2(x, y)); } blackHole.setRotation(-rotation); blackHole.setDirection((int)rotation); blackHoles.Add(blackHole); break; case "Breakable Wall": BreakableWall breakableWall = new BreakableWall(); if (rotation == 0) { breakableWall.setPosition(new Vector2(x, y)); } else { breakableWall.setPosition(new Vector2(x, y)); } breakableWall.setRotation(-rotation); breakableWall.setDirection((int)rotation); breakableWalls.Add(breakableWall); break; case "Laser Gate": LaserGate laserGate = new LaserGate(rnd.Next(0, 18)); if (rotation == 0) { laserGate.setPosition(new Vector2(x, y)); } else { laserGate.setPosition(new Vector2(x, y)); } laserGate.setRotation(-rotation); laserGate.setDirection((int)rotation); laserGates.Add(laserGate); break; case "Wind Tunnel": WindTunnel windTunnel = new WindTunnel(); if (rotation == 0) { windTunnel.setPosition(new Vector2(x, y)); } else { windTunnel.setPosition(new Vector2(x, y)); } windTunnel.setRotation(-rotation); windTunnel.setDirection((int)rotation); windTunnels.Add(windTunnel); break; // Level Flag case "Level": levelFlag = new LevelFlag(); levelFlag.setPosition(new Vector2(x, y - 80.0f)); levelFlag.setRotation(-rotation); break; // Player Position case "Player": playerPos = new Vector2(x, y); break; } }
public void Dispose() { if (coins != null) { foreach (Coin theCoin in coins) { theCoin.HideSprite(); } } if (gems != null) { foreach (Gem theGem in gems) { theGem.HideSprite(); } } if (spikes != null) { foreach (Spikes s in spikes) { s.HideSprite(); } } if (breakableWalls != null) { foreach (BreakableWall bw in breakableWalls) { bw.HideSprite(); } } if (blackHoles != null) { foreach (BlackHole bh in blackHoles) { bh.HideSprite(); } } if (laserGates != null) { foreach (LaserGate lg in laserGates) { lg.HideSprite(); } } if (windTunnels != null) { foreach (WindTunnel wt in windTunnels) { wt.HideSprite(); } } level.Clear(); coins.Clear(); gems.Clear(); levelFlag.Dispose(); blackHoles.Clear(); breakableWalls.Clear(); laserGates.Clear(); spikes.Clear(); windTunnels.Clear(); foreach (int num in level) { level.RemoveAt(num); } level = null; coins = null; gems = null; levelFlag = null; blackHoles = null; breakableWalls = null; laserGates = null; spikes = null; windTunnels = null; }