public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { float elapsed = (float)gameTime.ElapsedGameTime.Milliseconds; // This code just gets the current FPS (I read somewhere online that this method ISN'T how you're supposed to calculate FPS, so maybe I should re-write this frametime += gameTime.ElapsedGameTime.Milliseconds; framecount++; if (frametime > 1000) { fps = framecount; frametime = 1; framecount = 1; } // Updates the map if the player exits to the left, right, top, or bottom #region Player Off-Screen Handling try { if (player.getRect().Left > 1280) { player.playerState.position.X = 0; activeMap.Dispose(); activeMap = world.getMap(1, 0); loadEntities(); } if (player.getRect().Right < 0) { player.playerState.position.X = 1280 - 64; activeMap.Dispose(); activeMap = world.getMap(-1, 0); loadEntities(); } if (player.getRect().Bottom < 0) { player.playerState.position.Y = 720 - 128; activeMap.Dispose(); activeMap = world.getMap(0, -1); loadEntities(); } if (player.getRect().Top > 720) { player.playerState.position.Y = 0; activeMap.Dispose(); activeMap = world.getMap(0, 1); loadEntities(); } } catch (IndexOutOfRangeException e) { Environment.Exit(0); } #endregion Player Off-Screen Handling player.Update(gameTime); lantern.update(gameTime); base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); }
public override void LoadContent() { GameState state = ((Game1)(game)).state; player.Initialize(Vector2.Zero, game); player.pickUpLantern(lantern); world.loadArrays(); activeMap = world.getMap(0, 0); loadEntities(); lighting = game.Content.Load<Effect>("lighting"); black = game.Content.Load<Texture2D>("black"); font = game.Content.Load<SpriteFont>("Fonts/plain"); base.LoadContent(); }