/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: Add your initialization logic here map = new EzmMap( Content, GraphicsDevice, "TileSets", $@"{Content.RootDirectory}\Levels\map.ezm", true ); player = new Player(0, GraphicsDevice); setResolution(); base.Initialize(); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Escape)) { this.Exit(); } UpdatePlayerDirection(); var nexPosition = player.GetNextPostion(); if (!PlayerWillCollide(new Rectangle((int)nexPosition.X, (int)nexPosition.Y, player.Width, player.Height))) { player.MoveTo(nexPosition); } if (PlayerWillEntryOnCavern(new Rectangle((int)nexPosition.X, (int)nexPosition.Y, player.Width, player.Height))) { map = new EzmMap( Content, GraphicsDevice, "TileSets", $@"{Content.RootDirectory}\Levels\cavern.ezm", true ); } increase += gameTime.ElapsedGameTime.Milliseconds; if (increase >= 1000 / fps) { player.Animate(); increase = 0; } base.Update(gameTime); }