/// <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) { this.DisplayFps.Update(gameTime); MouseState mouseState = Mouse.GetState(); World.Map.Field.iField Field = this.Viewport[0].getField(mouseState.X, mouseState.Y); if (Field != OldField) { Field.alpha = 0.5f; OldField.alpha = 1.0f; OldField = Field; } KeyboardState keyState = Keyboard.GetState(); if (keyState.IsKeyDown(Keys.A)) this.Viewport[0].Camera.X -= (int)gameTime.ElapsedGameTime.TotalMilliseconds; if (keyState.IsKeyDown(Keys.D)) this.Viewport[0].Camera.X += (int)gameTime.ElapsedGameTime.TotalMilliseconds; if (keyState.IsKeyDown(Keys.W)) this.Viewport[0].Camera.Y -= (int)gameTime.ElapsedGameTime.TotalMilliseconds; if (keyState.IsKeyDown(Keys.S)) this.Viewport[0].Camera.Y += (int)gameTime.ElapsedGameTime.TotalMilliseconds; /*if (keyState.IsKeyDown(Keys.T) && !this.LastkeyState.IsKeyDown(Keys.T)) this.Viewport[0].Zoom *= 0.5f; if (keyState.IsKeyDown(Keys.G) && !this.LastkeyState.IsKeyDown(Keys.G)) this.Viewport[0].Zoom /= 0.5f; */ if (keyState.IsKeyDown(Keys.T) && !this.LastkeyState.IsKeyDown(Keys.T)) this.Viewport[0].Zoom *= 2.5f; if (keyState.IsKeyDown(Keys.G) && !this.LastkeyState.IsKeyDown(Keys.G)) this.Viewport[0].Zoom /= 2.5f; if (keyState.IsKeyDown(Keys.Left)) this.Player.Position.X -= 2; if (keyState.IsKeyDown(Keys.Right)) this.Player.Position.X += 2; if (keyState.IsKeyDown(Keys.Up)) this.Player.Position.Y -= 2; if (keyState.IsKeyDown(Keys.Down)) this.Player.Position.Y += 2; // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || keyState.IsKeyDown(Keys.Q) || keyState.IsKeyDown(Keys.Escape)) this.Exit(); this.LastkeyState = keyState; // TODO: Add your update logic here this.UpdateTitle(); base.Update(gameTime); }
/// <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() { this.DisplayFps = new Element.DisplayFps(); int size = 100; this.WorldMap = new WorldMap(size, size, this); this.Viewport = new Viewport[1]; Rectangle Screen = new Rectangle(0, 0, 400, 300); Screen.Width = graphics.PreferredBackBufferWidth; Screen.Height = graphics.PreferredBackBufferHeight; if (this.debugViewport == true) { Screen.X = 200; Screen.Y = 200; Screen.Width = 400; Screen.Height = 300; } this.Viewport[0] = new Viewport(this.WorldMap, Screen, new Vector2(100, 50), new Vector2(0, 0)); this.LastkeyState = Keyboard.GetState(); this.OldField = this.WorldMap.getField(0, 0); this.Player = new Player(new Vector2(100, 100), 10); base.Initialize(); this.UpdateTitle(); }