private bool IfValidPathThenUpdateLocation(WorldMap worldMap, float xpos, float ypos) { var Target = new Vector2(xpos, ypos); if (worldMap.IsValidPath(Location, Target)) { this.Location = Target; return(true); } return(false); }
/// <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) { Creature player = worldMap.Player; if (worldMap.WinCondition || player.Health <= 0) { HandleKeyboard(); return; } if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (!player.Is("attacking") && player.Is("slowed")) { player.Speed = player.Get("slowed", 0); } Vector3 shift = HandleKeyboard(); float aspect = GraphicsDevice.Viewport.AspectRatio; float targetX = engine.Camera.X + shift.X; float targetY = engine.Camera.Y + shift.Y; float xpixels = (targetX / aspect) * screenw / 2; float ypixels = (targetY) * screenh / 2; var worldMapTarget = new Vector2(worldMap.X + xpixels, worldMap.Y - ypixels); if (!worldMap.Loading) { if (worldMap.IsValidPath(worldMap.Viewport, worldMapTarget, (worldMap.MapWidth / 2) - 32, (worldMap.MapHeight / 2) - 32)) { engine.Camera = new Vector3(engine.Camera.X + shift.X, engine.Camera.Y + shift.Y, engine.Camera.Z + shift.Z); engine.Target = new Vector3(engine.Target.X + shift.X, engine.Target.Y + shift.Y, -1); worldMap.Viewport = worldMapTarget; // keep player at the center of the screen. //worldMap.Player.Location = worldMap.ConvertLocationToPixelPosition(worldMap.Viewport); } } base.Update(gameTime); engine.Update(gameTime); base.Draw(gameTime); //Console.WriteLine("TenGame Update time: {0}", DateTime.Now.Ticks - ticks); }