public void loadLevel(Level level) { myLevel_ = level; drawPipeline_ = myLevel_.Pipeline_; collisionDetector_ = myLevel_.CollisionDetector_; if (player_ != null && myLevel_.getPlayerStartLocation() != null && myLevel_.getPlayerStartLocation() != Vector2.Zero) { player_.setPosition(myLevel_.getPlayerStartLocation()); player_.setDrawPipeline(drawPipeline_); } else if (myLevel_.getPlayerStartLocation() != null && myLevel_.getPlayerStartLocation() != Vector2.Zero) { player_ = new ActuatedMainPlayer(drawPipeline_, collisionDetector_, myLevel_.getPlayerStartLocation(), new Vector2(1.0f, 0.0f)); myLevel_.setPlayer(player_); } else { player_ = null; } // Initialize mouse and/or camera if (player_ == null) { engine_.IsMouseVisible = true; } else { GlobalHelper.getInstance().getCurrentCamera().setCenter(player_.getPosition().X, player_.getPosition().Y); engine_.IsMouseVisible = false; } WorldState.reset(); myLevel_.initializeForGameplay(); // Initialize player and HUD if (player_ != null) { List<GameTexture> myTextures = new List<GameTexture>(); myTextures.Add(TextureMap.getInstance().getTexture(PISTOL_TEX_NAME)); myTextures.Add(TextureMap.getInstance().getTexture(SHOTGUN_TEX_NAME)); myTextures.Add(TextureMap.getInstance().getTexture(MACHINEGUN_TEX_NAME)); healthBarPos_ = HEALTH_BAR_POSITION; weaponIconPos_ = WEAPON_ICON_POSITION; healthTextPos_ = new Vector2(healthBarPos_.X + HEALTH_TEXT_OFFSET_X, healthBarPos_.Y + HEALTH_TEXT_OFFSET_Y); ammoTextPos_ = AMMO_TEXT_POSITION; healthBar_ = new HeadsUpDisplayObject(drawPipeline_, TextureMap.getInstance().getTexture(HEALTH_BAR_FILL_TEX_NAME), healthBarPos_, Vector2.Zero, HUD_DRAW_DEPTH); weapon_ = new HeadsUpDisplayWeapon(drawPipeline_, TextureMap.getInstance().getTexture(WEAPON_TEX_NAME), myTextures, weaponIconPos_, Vector2.Zero, HUD_DRAW_DEPTH); ammo_ = new HeadsUpDisplayText(ammoTextPos_, FONT_DRAW_DEPTH, FontEnum.Kootenay14, player_.Weapon_.CurrentAmmo_); player_.getHealth().addObserver(healthBar_); player_.getWeapon().addObserver(weapon_); player_.getAmmo().addObserver(ammo_); player_.setCollisionDetector(collisionDetector_); } }
/// <summary> /// Factory method to load a level from the file system. /// </summary> /// <param name="filepath">Complete path to the level Xml.</param> /// <param name="engine">Game engine.</param> /// <returns>An initialized level.</returns> public static Level getLevelFromFile(string filepath, Engine engine) { Level level; using (ManagedXml manager = new ManagedXml(engine)) { XmlDocument doc = manager.loadFromFile(filepath); level = new Level(false); level.initializeLevelFromXml(doc, engine); } return level; }
/// <summary> /// Constructs a state of gameplay using the provided level /// </summary> public EngineStateGameplay(Engine engine, Level level) { engine_ = engine; GlobalHelper.getInstance().setGameplayState(this); GlobalHelper.getInstance().getCurrentCamera().setScreenWidth((float)engine_.graphics_.PreferredBackBufferWidth); GlobalHelper.getInstance().getCurrentCamera().setScreenHeight((float)engine_.graphics_.PreferredBackBufferHeight); loadLevel(level); }
/// <summary> /// Factory method to load a level from packaged Content. /// </summary> /// <param name="levelname">Content-based path to the level.</param> /// <param name="engine">Game engine.</param> /// <returns>An initialized level.</returns> public static Level getLevelFromContent(string levelname, Engine engine) { Level level; using (ManagedXml manager = new ManagedXml(engine)) { XmlDocument doc = manager.load(Path.Combine(LEVELS_FOLDER, levelname)); level = new Level(true); level.initializeLevelFromXml(doc, engine); } return level; }