public void Update(GameTime gameTime) { Game1 g1 = (Game1)game; if (displaying || g1.Gesture == ManipMode.GRAB || g1.Gesture == ManipMode.SELECTGRAB) { nextSparkle -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (nextSparkle < 0) { sparkleSystem.DefaultColor = g1.Gesture != ManipMode.GRAB ? Color.Lime : grabColours[sparkleRandom.Next(0, grabColours.Length)]; var ranX = (float)(sparkleRandom.NextDouble() * 0.5 - 0.25); sparkleSystem.AddInstance(((Game1)game).CursorPos, new Vector2(ranX, ranX + 1) * 20); nextSparkle = (float)sparkleRandom.NextDouble() * sparkleIntv; } } sparkleSystem.Update(gameTime); if ((g1.Gesture == ManipMode.SELECT || g1.Gesture == ManipMode.SELECTGRAB) && lastGesture == ManipMode.NONE) { sparkleSystem.DefaultColor = Color.White; int pCount = sparkleRandom.Next(20, 50); for (int i = 0; i < pCount; i++) { var ranX = (float)(sparkleRandom.NextDouble() * 0.5 - 0.25); sparkleSystem.AddInstance(((Game1)game).CursorPos, 50); } } lastGesture = g1.Gesture; }
private void OnKeyDown_InsertMode(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) { manip_mode = ManipMode.Cursor; e.Handled = true; } }
/// <summary> /// Performs updates on the trial to determine whether or not it has been successfully completed or not. /// </summary> /// <param name="gameTime">The elapsed time since the previous call</param> public virtual void Update(GameTime gameTime) { cursorPos = ((Game1)game).CursorPos; lastGesture = gesture; gesture = ((Game1)game).Gesture; foreach (Entity entity in selectableList) { entity.Update(gameTime); } foreach (Entity entity in draggableList) { entity.Update(gameTime); } foreach (Entity entity in sceneryList) { entity.Update(gameTime); } }
private void OnKeyDown_CursorMode(object sender, KeyEventArgs e) { if (e.Key == Key.L) { KeyEventArgs ee = new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, Key.Right); ee.RoutedEvent = e.RoutedEvent; text_area.RaiseEvent(ee); e.Handled = true; } else if (e.Key == Key.H) { KeyEventArgs ee = new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, Key.Left); ee.RoutedEvent = e.RoutedEvent; text_area.RaiseEvent(ee); e.Handled = true; } else if (e.Key == Key.J) { KeyEventArgs ee = new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, Key.Down); ee.RoutedEvent = e.RoutedEvent; text_area.RaiseEvent(ee); e.Handled = true; } else if (e.Key == Key.K) { KeyEventArgs ee = new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, Key.Up); ee.RoutedEvent = e.RoutedEvent; text_area.RaiseEvent(ee); e.Handled = true; } else if (e.Key == Key.I) { manip_mode = ManipMode.Insert; } e.Handled = true; }
/// <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 (!DataLogger.Initialized && collectingData) { DataLogger.Initialize(username, accessDirectory, this, gameTime); } if (kAccess != null) { kAccess.Update(gameTime); } if (wAccess != null) { wAccess.Update(gameTime); } #region Damper /* * float damper = 1f; * if (Keyboard.GetState().IsKeyDown(Keys.LeftShift)) * { * damper = 0.5f; * } * else if (Keyboard.GetState().IsKeyDown(Keys.LeftControl)) * { * damper = 0.25f; * }*/ #endregion #region Door stuff /** * if (Keyboard.GetState().IsKeyDown(Keys.Enter) && lastState.IsKeyUp(Keys.Enter)) * { * Ghost ghost = new Ghost(this, new Vector3(camera.Position.X + (3 * (float)Math.Sin(camrotation)), * baseY, camera.Position.Z + (3 * (float)Math.Cos(camrotation))), camera); * * ghost.scale = 10; * ghostList.Add(ghost); * } * if (Keyboard.GetState().IsKeyDown(Keys.R) && doorList.Count > 0) * { * Door d = doorList[selDoor]; * d.rotation += 0.015f * damper; * d.rotation %= MathHelper.TwoPi; * } * else if (Keyboard.GetState().IsKeyDown(Keys.T) && doorList.Count > 0) * { * Door d = doorList[selDoor]; * d.rotation -= 0.015f * damper; * d.rotation %= MathHelper.TwoPi; * } * if (Keyboard.GetState().IsKeyDown(Keys.W) && doorList.Count > 0) * { * Door d = doorList[selDoor]; * d.position = new Vector3(d.position.X, d.position.Y, d.position.Z + speed/2 * damper); * * } * else if (Keyboard.GetState().IsKeyDown(Keys.S) && doorList.Count > 0) * { * Door d = doorList[selDoor]; * d.position = new Vector3(d.position.X, d.position.Y, d.position.Z - speed/2 * damper); * * } * if (Keyboard.GetState().IsKeyDown(Keys.A) && doorList.Count > 0) * { * Door d = doorList[selDoor]; * d.position = new Vector3(d.position.X + speed/2 * damper, d.position.Y, d.position.Z); * * } * else if (Keyboard.GetState().IsKeyDown(Keys.D) && doorList.Count > 0) * { * Door d = doorList[selDoor]; * d.position = new Vector3(d.position.X - speed/2 * damper, d.position.Y, d.position.Z); * * } * if (Keyboard.GetState().IsKeyDown(Keys.Z) && doorList.Count > 0) * { * Door d = doorList[selDoor]; * d.position = new Vector3(d.position.X, d.position.Y - speed/2 * damper, d.position.Z); * * } * else if (Keyboard.GetState().IsKeyDown(Keys.X) && doorList.Count > 0) * { * Door d = doorList[selDoor]; * d.position = new Vector3(d.position.X, d.position.Y + speed/2 * damper, d.position.Z); * * } * if (Keyboard.GetState().IsKeyDown(Keys.F) && doorList.Count > 0) * { * Door d = doorList[selDoor]; * d.scale += 0.01f * damper; * * } * else if (Keyboard.GetState().IsKeyDown(Keys.G) && doorList.Count > 0) * { * Door d = doorList[selDoor]; * d.scale -= 0.01f * damper; * * } * if (Keyboard.GetState().IsKeyDown(Keys.Q) && lastState.IsKeyUp(Keys.Q) && doorList.Count > 0) * { * Door d = doorList[selDoor]; * d.initRotation += MathHelper.PiOver2; * * } * else if (Keyboard.GetState().IsKeyDown(Keys.E) && lastState.IsKeyUp(Keys.E) && doorList.Count > 0) * { * Door d = doorList[doorList.Count - 1]; * d.initRotation -= MathHelper.PiOver2; * } * * if (Keyboard.GetState().IsKeyDown(Keys.OemPeriod) && lastState.IsKeyUp(Keys.OemPeriod) && selDoor < doorList.Count-1) * { * selDoor++; * } * else if (Keyboard.GetState().IsKeyDown(Keys.OemComma) && lastState.IsKeyUp(Keys.OemComma) && selDoor > 0) * { * selDoor--; * }**/ #endregion #region Movement Stuff (commented) /* * if (Keyboard.GetState().IsKeyDown(Keys.Left)) * { * camrotation += 0.035f * damper; * camrotation %= MathHelper.TwoPi; * camera.YRotation = camrotation; * } * else if (Keyboard.GetState().IsKeyDown(Keys.Right)) * { * camrotation -= 0.035f * damper; * camrotation %= MathHelper.TwoPi; * camera.YRotation = camrotation; * } * if (Keyboard.GetState().IsKeyDown(Keys.Up)) * { * camBobDuration += (float)gameTime.ElapsedGameTime.TotalSeconds*10; * * camera.Position = new Vector3(camera.Position.X + (speed * damper * (float)Math.Sin(camrotation)), * baseY + (float)Math.Sin(camBobDuration)/2f, * camera.Position.Z + (speed * damper * (float)Math.Cos(camrotation))); * } * else if (Keyboard.GetState().IsKeyDown(Keys.Down)) * { * camBobDuration += (float)gameTime.ElapsedGameTime.TotalSeconds * 10; * camera.Position = new Vector3(camera.Position.X - (speed * damper * (float)Math.Sin(camrotation)), * baseY + (float)Math.Sin(camBobDuration)/2f, * camera.Position.Z - (speed * damper * (float)Math.Cos(camrotation))); * } * * if (Keyboard.GetState().IsKeyDown(Keys.P)) * { * baseY += speed * damper / 2f; * camera.Position = new Vector3(camera.Position.X, baseY + (float)Math.Sin(camBobDuration), camera.Position.Z); * } * else if (Keyboard.GetState().IsKeyDown(Keys.L)) * { * baseY -= speed * damper / 2f; * camera.Position = new Vector3(camera.Position.X, baseY + (float)Math.Sin(camBobDuration), camera.Position.Z); * }*/ #endregion #region RenderDebug /* * if (Keyboard.GetState().IsKeyDown(Keys.M) && lastState.IsKeyUp(Keys.M) && fcrList.Count > 0) * { * displayingFCR = !displayingFCR; * }*/ #endregion if (Mouse.GetState().RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && inSeq && seqIt == -1) { seqIt = 0; StartTrial(Type.GetType("HarryPotterGame.Trials." + trialSequences[seqIt])); } if (Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D0) && lastState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.D0)) { StartTrial(Type.GetType("HarryPotterGame.Trials.KCalibration")); } if (Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D1) && lastState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.D1)) { StartTrial(Type.GetType("HarryPotterGame.Trials.P1")); } if (Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D2) && lastState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.D2)) { StartTrial(Type.GetType("HarryPotterGame.Trials.G1")); } if (Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D3) && lastState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.D3)) { StartTrial(Type.GetType("HarryPotterGame.Trials.D1")); } if (Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D4) && lastState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.D4)) { StartTrial(Type.GetType("HarryPotterGame.Trials.P2")); } if (Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D7) && lastState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.D7)) { StartTrial(Type.GetType("HarryPotterGame.Trials.P3")); } if (Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D8) && lastState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.D8)) { StartTrial(Type.GetType("HarryPotterGame.Trials.D3")); } if (Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape)) { this.Exit(); } if (Mouse.GetState().X < 20) { Mouse.SetPosition(20, Mouse.GetState().Y); } if (Mouse.GetState().X > GraphicsDevice.Viewport.Width - 20) { Mouse.SetPosition(GraphicsDevice.Viewport.Width - 20, Mouse.GetState().Y); } if (Mouse.GetState().Y < 20) { Mouse.SetPosition(Mouse.GetState().X, 20); } if (Mouse.GetState().Y > GraphicsDevice.Viewport.Height - 20) { Mouse.SetPosition(Mouse.GetState().X, GraphicsDevice.Viewport.Height - 20); } if (trial != null) { UpdateTrial(gameTime); } if (collectingData) { DataLogger.Update(gameTime); } if (wandCursor != null) { wandCursor.Update(gameTime); } /* * Input modes and gesture styles are defined and specified within this portion of the code */ switch (inputMode) { case InputMode.MOUSE: averagePoints.Insert(0, new Vector2(Mouse.GetState().X, Mouse.GetState().Y)); if (averagePoints.Count > pointCapacity) { averagePoints.RemoveAt(averagePoints.Count - 1); } cursorPos = Vector2.Zero; foreach (Vector2 pastPoint in averagePoints) { cursorPos += pastPoint; } cursorPos /= averagePoints.Count; if (Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { if (Mouse.GetState().RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { gesture = ManipMode.SELECTGRAB; } else { gesture = ManipMode.SELECT; } } else if (Mouse.GetState().RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { gesture = ManipMode.GRAB; } else { gesture = ManipMode.NONE; } if (Mouse.GetState().MiddleButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { gesture = ManipMode.SELECT; cursorPos = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2); Mouse.SetPosition(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2); } break; case InputMode.KINECT: averagePoints.Insert(0, kAccess.CursorPos); if (averagePoints.Count > pointCapacity) { averagePoints.RemoveAt(averagePoints.Count - 1); } cursorPos = Vector2.Zero; foreach (Vector2 pastPoint in averagePoints) { cursorPos += pastPoint; } cursorPos /= averagePoints.Count; if (Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { if (Mouse.GetState().RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { gesture = ManipMode.GRAB; } else { gesture = ManipMode.SELECT; } } else { gesture = ManipMode.NONE; } break; case InputMode.WAND: averagePoints.Insert(0, kAccess.CursorPos); if (averagePoints.Count > pointCapacity) { averagePoints.RemoveAt(averagePoints.Count - 1); } cursorPos = Vector2.Zero; foreach (Vector2 pastPoint in averagePoints) { cursorPos += pastPoint; } cursorPos /= averagePoints.Count; if (wAccess.SelectDetected) { gesture = ManipMode.SELECT; } else if (wAccess.GrabDetected) { gesture = ManipMode.GRAB; } else { gesture = ManipMode.NONE; } break; } lastState = Keyboard.GetState(); lastMouseState = Mouse.GetState(); if (wAccess != null) { lastWMState = wAccess.GetState(); } base.Update(gameTime); }