/// <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) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } MouseState mouse = Mouse.GetState(); if (mouse.LeftButton == ButtonState.Pressed && lastMouse.LeftButton == ButtonState.Released) { world.Insert(ShapePrimitives.BezelRectangle(new Vector2(mouse.X, mouse.Y), new Vector2(mouse.X + 20, mouse.Y + 20), 5)); } lastMouse = mouse; float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; KeyboardState ks = Keyboard.GetState(); Vector2 velocity = Vector2.Zero; float speed = 90; // a link to the past link moves at 90 pixels per second! if (ks.IsKeyDown(Keys.W)) { velocity += new Vector2(0, -speed * deltaTime); } if (ks.IsKeyDown(Keys.S)) { velocity += new Vector2(0, speed * deltaTime); } if (ks.IsKeyDown(Keys.A)) { velocity += new Vector2(-speed * deltaTime, 0); } if (ks.IsKeyDown(Keys.D)) { velocity += new Vector2(speed * deltaTime, 0); } world.ClearDebugTag(); List <Polygon> polys = world.Retrieve(new RectangleF(poly1.Origin.X + poly1.BoundingBox.Left, poly1.Origin.Y + poly1.BoundingBox.Top, poly1.BoundingBox.Width, poly1.BoundingBox.Height)); foreach (IPolygon poly in polys) { poly.AddTag("debug"); } Window.Title = polys.Count.ToString(); poly1.Move(polys, velocity); base.Update(gameTime); }