public void OnSensorChanged(AccelerometerState acc) { if (isInstance) { currentControl.OnSensorChanged(acc); } }
/// <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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } //Update the Touches BEFORE updating the Game Objects TouchCollection touch = TouchPanel.GetState(); AccelerometerState accelstate = Accelerometer.GetState(); phsX.Gravity = (float)9.8 * (new Vector2(accelstate.Acceleration.X, -accelstate.Acceleration.Y)); foreach (TouchLocation tl in touch) { foreach (Geom b in phsX.GeomList) { b.Body.ApplyForce((tl.Position - b.Position) / (float)2.0); } } phsX.Update((float)(1.0 / 30.0)); //Update physX base.Update(gameTime); }
/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { GetInput(keyboardState, gamePadState, touchState, accelState, orientation); ApplyPhysics(gameTime); if (IsAlive && IsOnGround) { if (Math.Abs(Velocity.X) - 0.02f > 0) { sprite.PlayAnimation(runAnimation); } else { sprite.PlayAnimation(idleAnimation); } } // Clear input. movement = 0.0f; isJumping = false; }
public void HandleInput(InputState input) { //Must check for TouchLocationState as wel as Count //Otherwise, FireMissile will be called twice //Once for 'Pressed' and once for 'Released' if ((input.TouchState.Count > 0) && input.TouchState[0].State == TouchLocationState.Pressed) { FireMissile(); } _accelerometerState = input.CurrentAccelerometerState; if (_accelerometerState.X > .1) { Velocity = _leftRightVector; } if (_accelerometerState.X < -.1) { Velocity = -_leftRightVector; } //near Zero tilt left or right so //set velocity to zero if ((_accelerometerState.X < .1) && (_accelerometerState.X > -.1)) { Velocity = Vector2.Zero; } }
/// <summary> /// Updates all objects in the world, performs collision between them, /// and handles the time limit with scoring. /// </summary> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { // Pause while the player is dead or time is expired. if (!Player.IsAlive || TimeRemaining == TimeSpan.Zero) { // Still want to perform physics on the player. Player.ApplyPhysics(gameTime); } else if (ReachedExit) { // Animate the time being converted into points. int seconds = (int)Math.Round(gameTime.ElapsedGameTime.TotalSeconds * 100.0f); seconds = Math.Min(seconds, (int)Math.Ceiling(TimeRemaining.TotalSeconds)); timeRemaining -= TimeSpan.FromSeconds(seconds); score += seconds * PointsPerSecond; } else { timeRemaining -= gameTime.ElapsedGameTime; Player.Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); UpdateGems(gameTime); // Falling off the bottom of the level kills the player. if (Player.BoundingRectangle.Top >= Height * Tile.Height) { OnPlayerKilled(null); } UpdateEnemies(gameTime); // The player has reached the exit if they are standing on the ground and // his bounding rectangle contains the center of the exit tile. They can only // exit when they have collected all of the gems. if (Player.IsAlive && Player.IsOnGround && Player.BoundingRectangle.Contains(exit)) { OnExitReached(); } } // Clamp the time remaining at zero. if (timeRemaining < TimeSpan.Zero) { timeRemaining = TimeSpan.Zero; } }
/// <summary> /// Gets player horizontal movement and jump commands from input. /// </summary> private void GetInput( KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { // Get analog horizontal movement. movement = gamePadState.ThumbSticks.Left.X * MoveStickScale; // Ignore small movements to prevent running in place. if (Math.Abs(movement) < 0.5f) { movement = 0.0f; } // Move the player with accelerometer if (Math.Abs(accelState.Acceleration.Y) > 0.10f) { // set our movement speed movement = MathHelper.Clamp(-accelState.Acceleration.Y * AccelerometerScale, -1f, 1f); // if we're in the LandscapeLeft orientation, we must reverse our movement if (orientation == DisplayOrientation.LandscapeRight) { movement = -movement; } } // If any digital horizontal movement input is found, override the analog movement. if (gamePadState.IsButtonDown(Buttons.DPadLeft) || keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { movement = -1.0f; } else if (gamePadState.IsButtonDown(Buttons.DPadRight) || keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { movement = 1.0f; } // Check if the player wants to jump. isJumping = gamePadState.IsButtonDown(JumpButton) || keyboardState.IsKeyDown(Keys.Space) || keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W) || touchState.AnyTouch(); }
private void HandleInput(GameTime gameTime) { // get all of our input states keyboardState = Keyboard.GetState(); touchState = TouchPanel.GetState(); gamePadState = virtualGamePad.GetState(touchState, GamePad.GetState(PlayerIndex.One)); accelerometerState = Accelerometer.GetState(); if (keyboardState.IsKeyDown(Keys.Escape) || keyboardState.IsKeyDown(Keys.Q)) { Exit(); } #if !NETFX_CORE // Exit the game when back is pressed. if (gamePadState.Buttons.Back == ButtonState.Pressed) { Exit(); } #endif bool continuePressed = keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.AnyTouch(); // Perform the appropriate action to advance the game and // to get the player back to playing. if (!wasContinuePressed && continuePressed) { if (!level.Player.IsAlive) { level.StartNewLife(); } else if (level.TimeRemaining == TimeSpan.Zero) { if (level.ReachedExit) { LoadNextLevel(); } else { ReloadCurrentLevel(); } } } wasContinuePressed = continuePressed; virtualGamePad.Update(gameTime); }
/// <summary> /// Handles the input base. /// </summary> /// <param name="input">Input.</param> public override void HandleInputBase(vxInputManager input) { // get all of our input states keyboardState = Keyboard.GetState(); touchState = TouchPanel.GetState(); //gamePadState = virtualGamePad.GetState(touchState, GamePad.GetState(PlayerIndex.One)); accelerometerState = Accelerometer.GetState(); //virtualGamePad.Update(gameTimeBase); // #if !NETFX_CORE // // Exit the game when back is pressed. // if (gamePadState.Buttons.Back == ButtonState.Pressed) // vxEngine.Game.Exit(); // #endif }
/// <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) { base.Update(gameTime); touchCollection = TouchPanel.GetState(); accelerometerState = Accelerometer.GetState(); // Use X axis to determine if the Zune is being viewed from the // left or right side. // Leave fixed for now, need to rethink recalculating marble // positions when screen is rotated. if (accelerometerState.Acceleration.X >= 0.0 && accelerometerState.Acceleration.X < 1.0) { screenOrientation = ScreenOrientation.LandscapeRight; screenRotation = 4.72f; } else { screenOrientation = ScreenOrientation.LandscapeLeft; screenRotation = 1.57f; } if (screenOrientation != priorScreenOrientation) { if (GameState == GameState.Play2D) { mainGame.RecalculateMarblePositions(); } priorScreenOrientation = screenOrientation; } if (NextGameState != GameState.None) { ChangeGameState(); } }
/// <summary> /// Gets player horizontal movement and jump commands from input. /// </summary> private void GetInput( KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { // Get analog horizontal movement. movement = gamePadState.ThumbSticks.Left.X * MoveStickScale; // Ignore small movements to prevent running in place. if (Math.Abs(movement) < 0.5f) movement = 0.0f; // Move the player with accelerometer if (Math.Abs(accelState.Acceleration.Y) > 0.10f) { // set our movement speed movement = MathHelper.Clamp(-accelState.Acceleration.Y * AccelerometerScale, -1f, 1f); // if we're in the LandscapeLeft orientation, we must reverse our movement if (orientation == DisplayOrientation.LandscapeRight) movement = -movement; } // If any digital horizontal movement input is found, override the analog movement. if (gamePadState.IsButtonDown(Buttons.DPadLeft) || keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { movement = -1.0f; } else if (gamePadState.IsButtonDown(Buttons.DPadRight) || keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { movement = 1.0f; } // Check if the player wants to jump. isJumping = gamePadState.IsButtonDown(JumpButton) || keyboardState.IsKeyDown(Keys.Space) || keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W) || touchState.AnyTouch(); }
private void HandleInput() { // get all of our input states keyboardState = Keyboard.GetState(); gamePadState = GamePad.GetState(PlayerIndex.One); touchState = TouchPanel.GetState(); accelerometerState = Accelerometer.GetState(); // Exit the game when back is pressed. if (gamePadState.Buttons.Back == ButtonState.Pressed) { } //Exit(); bool continuePressed = keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.AnyTouch(); // Perform the appropriate action to advance the game and // to get the player back to playing. if (!wasContinuePressed && continuePressed) { if (!level.Player.IsAlive) { level.StartNewLife(); } else if (level.TimeRemaining == TimeSpan.Zero) { if (!level.ReachedExit) ReloadCurrentLevel(); // LoadNextLevel(); //else } } wasContinuePressed = continuePressed; }
//Updates all objects in the world, performs collision between them, //and handles the time limit with scoring. public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, AccelerometerState accelState, DisplayOrientation orientation ) { if (!this.Player.IsAlive || this.TimeRemaining == TimeSpan.Zero) { //Still want to perform physics on the player. this.Player.ApplyPhysics(gameTime); } else if(ReachedExit) { //Animate the time being converted into points. int seconds = (int)Math.Round(gameTime.ElapsedGameTime.TotalSeconds * 100.0f); seconds = Math.Min(seconds, (int)Math.Ceiling(this.TimeRemaining.TotalSeconds)); timeRemaining -= TimeSpan.FromSeconds(seconds); score += seconds + GlobalConstants.LevelPointsPerSecond; } else { timeRemaining -= gameTime.ElapsedGameTime; this.Player.Update(gameTime, keyboardState, gamePadState, accelState, orientation); this.UpdateGems(gameTime); //Falling off the bottom of the level kills the player. if (this.Player.BoundingRectangle.Top >= this.Height * GlobalConstants.TileHeight) { this.OnPlayerKilled(null); } this.UpdateGems(gameTime); //The player has reached the exit if they are standing on the ground and //his bounding rectangle contains the center of the exit tile. They can only //exit when they have collected all of the gems. if (this.Player.IsAlive && this.Player.IsOnGround && this.Player.BoundingRectangle.Contains(exit)) { this.OnExitReached(); } } }
/// <summary> /// Polls input states and handles player input. /// </summary> public override void HandleInput(InputState input) { int playerIndex = (int)ControllingPlayer.Value; keyboardState = input.CurrentKeyboardStates[playerIndex]; gamePadState = input.CurrentGamePadStates[playerIndex]; touchState = TouchPanel.GetState(); accelerometerState = Accelerometer.GetState(); if (level.Player.Alive && level.EndReached) LoadNextLevel(); if (!level.Player.Alive) if (level.Player.Lives > 0) level.NewLife(); else { ScreenManager.AddScreen(new GameOverScreen(), ControllingPlayer); ReloadLevel(); } bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; if (input.GamePadWasConnected[playerIndex]) controlCheck.wasConnected = true; if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } if (!gamePadState.IsConnected) { controlCheck.wasConnected = false; input.GamePadWasConnected[playerIndex] = false; } }
/// <summary> /// Updates input, physics and animations for the player. /// </summary> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { ReadInput(keyboardState, gamePadState, touchState, accelState, orientation); ApplyPhysics(gameTime); Camera.Location = new Vector2( MathHelper.Clamp(Camera.Location.X, Position.X - Camera.viewWidth * 3 / 4, Position.X - Camera.viewWidth / 4), MathHelper.Clamp(Camera.Location.Y, Position.Y - Camera.viewHeight * 3 / 8, Position.Y - Camera.viewHeight * 5 / 8)); if (Alive && Grounded) if (Math.Abs(Velocity.X) - 0.02f > 0) sprite.PlayAnimation(run); else sprite.PlayAnimation(idle); movement = 0.0f; jumping = false; }
/// <summary> /// Gets player horizontal movement and jump commands from input. /// </summary> private void GetInput( KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { // Get analog horizontal movement. movement = gamePadState.ThumbSticks.Left.X * MoveStickScale; // Ignore small movements to prevent running in place. if (Math.Abs(movement) < 0.5f) movement = 0.0f; // Move the player with accelerometer if (Math.Abs(accelState.Acceleration.Y) > 0.10f) { // set our movement speed movement = MathHelper.Clamp(-accelState.Acceleration.Y * AccelerometerScale, -1f, 1f); // if we're in the LandscapeLeft orientation, we must reverse our movement if (orientation == DisplayOrientation.LandscapeRight) movement = -movement; } // If any digital horizontal movement input is found, override the analog movement. if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { movement = -1.0f; } else if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { movement = 1.0f; } // Weapon switching if (gamePadState.IsButtonDown(Buttons.DPadLeft)) { weapon.Reset(); weapon = m_handgun; } else if (gamePadState.IsButtonDown(Buttons.DPadUp)) { weapon.Reset(); weapon = m_shotgun; } else if (gamePadState.IsButtonDown(Buttons.DPadRight)) { weapon.Reset(); weapon = m_knife; } if (gamePadState.IsButtonDown(SwitchButton) && !old_gamePadState.IsButtonDown(SwitchButton)) { weapon.Reset(); if (weapon == m_handgun) weapon = m_shotgun; else if (weapon == m_shotgun) weapon = m_knife; else weapon = m_handgun; } // Check if the player wants to jump. isJumping = gamePadState.IsButtonDown(JumpButton) || keyboardState.IsKeyDown(Keys.Space) || keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W) || touchState.AnyTouch(); if (gamePadState.IsButtonDown(RollButton) && !old_gamePadState.IsButtonDown(RollButton)) { if (canRollAgain && isOnGround) { isRolling = true; canRollAgain = false; } } isThrowGrenade = false; if (!isRolling) { // release the charged bomb if (old_gamePadState.IsButtonDown(GrenadeButton) && !gamePadState.IsButtonDown(GrenadeButton)) { m_bomb.Shoot(); } // charge up the bomb throw if button held if (gamePadState.IsButtonDown(GrenadeButton) && isOnGround && m_bomb.CanAttack) { isThrowGrenade = true; m_bomb.Charging(this.position); } // other attacks else if ((gamePadState.IsButtonDown(FireButton) && !old_gamePadState.IsButtonDown(FireButton)) || (keyboardState.IsKeyDown(Keys.Z)) || (gamePadState.IsButtonDown(FireButton2) && !old_gamePadState.IsButtonDown(FireButton2))) { weapon.Shoot(); } } old_gamePadState = gamePadState; }
public AccelerometerStateEventArgs(AccelerometerState state, string message) { _state = state; _message = message; }
public override void HandleInput(GameTime gameTime, InputState input) { //// get all of our input states keyboardState = Keyboard.GetState(); //gamePadState = GamePad.GetState(PlayerIndex.One); touchState = TouchPanel.GetState(); accelerometerState = Accelerometer.GetState(); if (maze.player.IsAlive == false) { if (keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.Any() == true) { maze.StartRoom().StartNewLife(ScreenManager.GraphicsDevice); } } // Exit the game when back is pressed. ///// if (gamePadState.Buttons.Back == ButtonState.Pressed) ////// Exit(); bool continuePressed = keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.Any(); wasContinuePressed = continuePressed; }
private void HandleInput() { // get all of our input states keyboardState = Keyboard.GetState(); gamePadState = GamePad.GetState(PlayerIndex.One); touchState = TouchPanel.GetState(); accelerometerState = Accelerometer.GetState(); // Exit the game when back is pressed. if (gamePadState.Buttons.Back == ButtonState.Pressed || keyboardState.IsKeyDown(Keys.Escape)) { Exit(); } bool continuePressed = keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.AnyTouch(); wasContinuePressed = continuePressed; }
private void HandleInput(GameTime gameTime) { // get all of our input states previousKeyboardState = keyboardState; keyboardState = Keyboard.GetState(); touchState = TouchPanel.GetState(); gamePadState = virtualGamePad.GetState(touchState, GamePad.GetState(PlayerIndex.One)); accelerometerState = Accelerometer.GetState(); MouseState mouseState = Mouse.GetState(); Vector2 playerPos = Vector2.Transform(level.Player.Position, globalTransformation); Vector2 lookDir = Vector2.Normalize(mouseState.Position.ToVector2() - playerPos); spotlight.Rotation = (float) Math.Atan2(lookDir.Y, lookDir.X); #if !NETFX_CORE // Exit the game when back is pressed. if (gamePadState.Buttons.Back == ButtonState.Pressed) Exit(); #endif if (keyboardState.IsKeyDown(ConsoleToggleOpenKey) && !previousKeyboardState.IsKeyDown(ConsoleToggleOpenKey)) Console.ToggleOpenClose(); var continuePressed = false; if (!Console.IsAcceptingInput) { penumbraController.InputEnabled = true; continuePressed = keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.AnyTouch(); // Perform the appropriate action to advance the game and // to get the player back to playing. if (!wasContinuePressed && continuePressed) { if (!level.Player.IsAlive) { level.StartNewLife(); } else if (level.TimeRemaining == TimeSpan.Zero) { if (level.ReachedExit) LoadNextLevel(); else ReloadCurrentLevel(); } } } else { penumbraController.InputEnabled = false; } wasContinuePressed = continuePressed; virtualGamePad.Update(gameTime); }
/// <summary> /// Gets player horizontal movement and jump commands from input. /// </summary> private Enumeration.Input GetInput(KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { ///Dim status As AForge.Controls.Joystick.Status = _ ///joy.GetCurrentStatus() if (spriteState.Value().Priority == Enumeration.PriorityState.Force) { return Enumeration.Input.none; } ///If status.IsButtonPressed _ ///(AForge.Controls.Joystick.Buttons.Button1) = True Then ///Maze.NextLevel() ///End If if (PrinceOfPersiaGame.CONFIG_DEBUG == true) { if (keyboardState.IsKeyDown(Keys.NumPad8)) { SpriteRoom = Maze.UpRoom(SpriteRoom); return Enumeration.Input.none; } if (keyboardState.IsKeyDown(Keys.NumPad2)) { SpriteRoom = Maze.DownRoom(SpriteRoom); return Enumeration.Input.none; } if (keyboardState.IsKeyDown(Keys.NumPad4)) { SpriteRoom = Maze.LeftRoom(SpriteRoom); return Enumeration.Input.none; } if (keyboardState.IsKeyDown(Keys.NumPad6)) { SpriteRoom = Maze.RightRoom(SpriteRoom); return Enumeration.Input.none; } if (keyboardState.IsKeyDown(Keys.NumPad1)) { SpriteRoom = Maze.PreviuosRoom(SpriteRoom); return Enumeration.Input.none; } if (keyboardState.IsKeyDown(Keys.D2)) { Maze.NextLevel(); return Enumeration.Input.none; } if (keyboardState.IsKeyDown(Keys.D1)) { Maze.PreviousLevel(); return Enumeration.Input.none; } if (keyboardState.IsKeyDown(Keys.NumPad9)) { SpriteRoom = Maze.RoomGet(SpriteRoom); return Enumeration.Input.none; } if (keyboardState.IsKeyDown(Keys.NumPad3)) { SpriteRoom = Maze.NextRoom(SpriteRoom); return Enumeration.Input.none; } if (keyboardState.IsKeyDown(Keys.NumPad0)) { Maze.StartRoom().StartNewLife(graphicsDevice); return Enumeration.Input.none; } if (keyboardState.IsKeyDown(Keys.OemMinus)) { AnimationSequence.frameRate = AnimationSequence.frameRate - 0.1f; return Enumeration.Input.none; } if (keyboardState.IsKeyDown(Keys.OemPlus)) { AnimationSequence.frameRate = AnimationSequence.frameRate + 0.1f; return Enumeration.Input.none; } if (keyboardState.IsKeyDown(Keys.NumPad5)) { //Maze.player.Resheathe(); Maze.player.Sword = true; Maze.player.LivePoints = 15; Maze.player.Energy = 15; return Enumeration.Input.none; } } ////////// //SHIFT ////////// if (keyboardState.GetPressedKeys().Count() == 1 && keyboardState.GetPressedKeys()[0] == (Keys.LeftShift | Keys.RightShift)) { return Enumeration.Input.shift; } ////////// //LEFT ////////// if (keyboardState.IsKeyDown(Keys.Up) & keyboardState.IsKeyDown(Keys.Left)) { return Enumeration.Input.leftup; } else if (keyboardState.IsKeyDown(Keys.Down) & keyboardState.IsKeyDown(Keys.Left)) { return Enumeration.Input.leftdown; } else if (keyboardState.IsKeyDown(Keys.Left) & (keyboardState.IsKeyDown(Keys.LeftShift) | (keyboardState.IsKeyDown(Keys.RightShift)))) { return Enumeration.Input.leftshift; } else if (gamePadState.IsButtonDown(Buttons.DPadLeft) || keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { return Enumeration.Input.left; ////////// //RIGHT ////////// } else if (keyboardState.IsKeyDown(Keys.Up) & keyboardState.IsKeyDown(Keys.Right)) { return Enumeration.Input.rightup; } else if (keyboardState.IsKeyDown(Keys.Down) & keyboardState.IsKeyDown(Keys.Right)) { return Enumeration.Input.righdown; } else if (keyboardState.IsKeyDown(Keys.Right) & (keyboardState.IsKeyDown(Keys.LeftShift) | (keyboardState.IsKeyDown(Keys.RightShift)))) { return Enumeration.Input.rightshift; } else if (gamePadState.IsButtonDown(Buttons.DPadRight) || keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { return Enumeration.Input.right; ////// //UP// ////// } else if (gamePadState.IsButtonDown(Buttons.DPadUp) || keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) { return Enumeration.Input.up; /////// //DOWN/ /////// } else if (gamePadState.IsButtonDown(Buttons.DPadDown) || keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) { return Enumeration.Input.down; } else { //////// //NONE// return Enumeration.Input.none; } }
/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { Enumeration.Input input = GetInput(keyboardState, gamePadState, touchState, accelState, orientation); ParseInput(input); if (IsAlive == false & IsOnGround == true) { DeadFall(); return; } //ApplyPhysicsNew(gameTime); HandleCollisionsNew(); float elapsed = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); // TODO: Add your game logic here. sprite.UpdateFrame(elapsed, ref _position, ref flip, ref spriteState); }
/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation, InputManager inputManager) { // Hook for InputManager inputManager.Update(); if (IsAlive) { GetInput(keyboardState, gamePadState, touchState, accelState, orientation, inputManager); } ApplyPhysics(gameTime); if (IsAlive) { if (isOnGround) { if (Math.Abs(Velocity.X) - 0.02f > 0) { if (Velocity.X > 0) { sprite.PlayAnimation(runRightAnimation); isRight = true; } else { sprite.PlayAnimation(runLeftAnimation); isRight = false; } } else { idle(); } } else if (isClimbing) { if (Velocity.Y > 0.02f) { sprite.PlayAnimation(ladderDownAnimation); } else if (Velocity.Y < 0.02f) { sprite.PlayAnimation(ladderUpAnimation); } if (Math.Abs(Velocity.Y) <= 0.02f) { sprite.Pause(); } } else if (!isJumping) { if (Velocity.X > 0) { sprite.PlayAnimation(fallRightAnimation); } else if (Velocity.X < 0) { sprite.PlayAnimation(fallLeftAnimation); } else { sprite.PlayAnimation(isRight ? fallRightAnimation : fallLeftAnimation); } } } // Check for fall damage checkFallDamage(); // Clear input. movement = Vector2.Zero; wasClimbing = isClimbing; isClimbing = false; isJumping = false; }
/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { float elapsed = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); // TODO: Add your game logic here. sprite.UpdateFrame(elapsed, ref _position, ref flip, ref spriteState); }
public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { float elapsed = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); itemAnimation.UpdateFrameItem(elapsed, ref position, ref flip, ref itemState); }
/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation, Viewport viewport) { if (!IsRespawnable) return; GetInput(keyboardState, gamePadState, touchState, accelState, orientation); if (isThrowGrenade) { sprite.PlayAnimation(grenadeAnimation); m_bomb.Update(gameTime, Position, flip); } else { ApplyPhysics(gameTime); if (IsAlive && IsOnGround && !isRolling) { if (Math.Abs(Velocity.X) - 0.02f > 0) { sprite.PlayAnimation(runAnimation); } else { sprite.PlayAnimation(idleAnimation); } } //weapon.Update(gameTime, Position, flip); m_handgun.Update(gameTime, Position, flip); m_shotgun.Update(gameTime, Position, flip); m_knife.Update(gameTime, Position, flip); m_bomb.Update(gameTime, Position, flip); //Sprite effects if (pulseRed) { pulseRedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; if (pulseRedTime > MAX_PULSE_TIME) { pulseRed = false; pulseRedTime = 0.0f; } } } // Clear input. movement = 0.0f; isJumping = false; }
/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { HandleCollision(); if (object.ReferenceEquals(this.GetType(), typeof(Spikes))) { ((Spikes)this).elapsedTimeOpen += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); if (((Spikes)this).elapsedTimeOpen > ((Spikes)this).timeOpen) { ((Spikes)this).Close(); } } if (object.ReferenceEquals(this.GetType(), typeof(Lava))) { ((Lava)this).elapsedTimeOpen += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); if (((Lava)this).elapsedTimeOpen > ((Lava)this).timeOpen) { ((Lava)this).Close(); } } if (object.ReferenceEquals(this.GetType(), typeof(Chomper))) { ((Chomper)this).elapsedTimeOpen += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); if (((Chomper)this).elapsedTimeOpen > ((Chomper)this).timeOpen) { ((Chomper)this).Close(); } } if (object.ReferenceEquals(this.GetType(), typeof(Gate))) { ((Gate)this).elapsedTimeOpen += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); if (((Gate)this).timeOpen == 0 && ((Gate)this).tileState.Value().state == Enumeration.StateTile.opened) { ((Gate)this).Opened(); } else if (((Gate)this).elapsedTimeOpen > ((Gate)this).timeOpen) { ((Gate)this).Close(); } } if (object.ReferenceEquals(this.GetType(), typeof(PressPlate))) { ((PressPlate)this).elapsedTimeOpen += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); if (((PressPlate)this).elapsedTimeOpen > ((PressPlate)this).timeOpen & ((PressPlate)this).State == Enumeration.StateTile.dpressplate) { ((PressPlate)this).DePress(); } } if (object.ReferenceEquals(this.GetType(), typeof(Loose))) { if (((Loose)this).tileState.Value().state == Enumeration.StateTile.loose) { ((Loose)this).elapsedTimeOpen += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); if (((Loose)this).elapsedTimeOpen > ((Loose)this).timeFall) { ((Loose)this).Fall(); } } } float elapsed = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); tileAnimation.UpdateFrameTile(elapsed, ref _position, ref flip, ref tileState); }
/// <summary> /// Gets player horizontal movement and jump commands from input. /// </summary> private void GetInput(AccelerometerState accelState, TouchCollection touchState) { // Get input state. GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); KeyboardState keyboardState = Keyboard.GetState(); // Get analog horizontal movement. movement = gamePadState.ThumbSticks.Left.X * MoveStickScale; // Ignore small movements to prevent running in place. if (Math.Abs(movement) < 0.5f) movement = 0.0f; if (Math.Abs(accelState.Acceleration.X) > 0.10f) { if (accelState.Acceleration.X > 0.0f) movement = 1.0f; else movement = -1.0f; } //override digital if touch input is found // Process touch locations. bool touchJump = false; foreach (TouchLocation location in touchState) { switch (location.State) { case TouchLocationState.Pressed: touchJump = true; break; case TouchLocationState.Moved: break; case TouchLocationState.Released: break; } } // If any digital horizontal movement input is found, override the analog movement. if (gamePadState.IsButtonDown(Buttons.DPadLeft) || keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { movement = -1.0f; } else if (gamePadState.IsButtonDown(Buttons.DPadRight)|| keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { movement = 1.0f; } // Check if the player wants to jump. isJumping = gamePadState.IsButtonDown(JumpButton) || keyboardState.IsKeyDown(Keys.Space) || keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W) || touchJump; }
void _accelerometer_ReadingChanged(AccelerometerState state) { _lastReading = state; }
/// <summary> /// Handles input for horizontal movement and jumps. /// </summary> public void ReadInput( KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { //360 Controller movements movement = gamePadState.ThumbSticks.Left.X * MoveStickScale; #if WINDOWS_PHONE if (PhoneMainMenuScreen.GameOptions.controlOptions != 2) movement = VirtualThumbsticks.LeftThumbstick.X * MoveStickScale; #endif //Stops animating in place for analog controls if (Math.Abs(movement) < 0.5f) movement = 0.0f; #if WINDOWS_PHONE if (PhoneMainMenuScreen.GameOptions.controlOptions != 1) { // Move the player with accelerometer if (Math.Abs(accelState.Acceleration.Y) > 0.10f) { // set our movement speed movement = MathHelper.Clamp(-accelState.Acceleration.Y * AccelerometerScale, -1f, 1f); // if we're in the LandscapeLeft orientation, we must reverse our movement if (orientation == DisplayOrientation.LandscapeRight) movement = -movement; } } #endif //Keyboard movements (overwrites analog stick) if (keyboardState.IsKeyDown(Keys.A) || gamePadState.IsButtonDown(Buttons.DPadLeft)) movement = -1.0f; else if (keyboardState.IsKeyDown(Keys.D) || gamePadState.IsButtonDown(Buttons.DPadRight)) movement = 1.0f; //checks for jumps jumping = gamePadState.IsButtonDown(Buttons.A) || keyboardState.IsKeyDown(Keys.Space) || keyboardState.IsKeyDown(Keys.Down); #if WINDOWS_PHONE if (PhoneMainMenuScreen.GameOptions.controlOptions == 2) { jumping = touchState.AnyTouch(); } if (PhoneMainMenuScreen.GameOptions.controlOptions != 2) { if (VirtualThumbsticks.RightThumbstickCenter != null) { jumping = true; } } #endif }
/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, AccelerometerState accelState, DisplayOrientation orientation) { if (!Level.Game.Console.IsAcceptingInput) GetInput(keyboardState, gamePadState, accelState, orientation); ApplyPhysics(gameTime); if (IsAlive && IsOnGround) { sprite.PlayAnimation(Math.Abs(Velocity.X) - 0.02f > 0 ? runAnimation : idleAnimation); } // Clear input. movement = 0.0f; isJumping = false; }
/// <summary> /// Updates all objects in the game world /// </summary> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { if (Player.Alive) if (endReached) { } //end if else { Player.Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); if (Player.BoundingBox.Top >= Camera.worldHeight) Player.OnDeath(); UpdateEnemies(gameTime); if (Player.Alive && Player.BoundingBox.Contains(checkPoint)) { levelMap.rows[checkPoint.Y / Tile.HEIGHT].columns[checkPoint.X / Tile.WIDTH].tileID = 5; start = checkVec; } if (Player.Alive && Player.Grounded && Player.BoundingBox.Contains(end)) OnEndReached(); if (Player.Alive && Player.BoundingBox.Contains(freeLife)) { levelMap.rows[freeLife.Y / Tile.HEIGHT].columns[freeLife.X / Tile.WIDTH].tileID = 0; Player.addLives(1); freeLife = new Point(-1, -1); } } //end else }
// internal because we want our game types to call this. internal static void Update(LandscapeOrientation landscapeOrientation) { #if !WINDOWS // On Zune we can just use the TouchPanel class and fill // our ZuneTouch structures with the same data. // clear out the old touches touches.Clear(); // for each touch on the touch panel foreach (var t in TouchPanel.GetState()) { Vector2 position = t.Position; // adjust the touch's position based on device orientation switch (landscapeOrientation) { case LandscapeOrientation.Right: position = new Vector2(position.Y, 272 - position.X); break; case LandscapeOrientation.Left: position = new Vector2(480 - position.Y, position.X); break; default: break; } // add a new ZuneTouch instance that duplicates the data touches.Add(new ZuneTouch { ID = t.Id, Position = position, State = (ZuneTouchState)(int)t.State, Pressure = t.Pressure }); } // Then we just update our accelerometer property from the Accelerometer class AccelerometerState accState = Accelerometer.GetState(); Acceleration = accState.Acceleration; #else // On PC we use the current and last mouse state's to position our // fake touch as well as update its state. MouseState mouseState = Mouse.GetState(); // we want to make sure we're in bounds of the screen, so figure out if we're // actually in landscape mode or not. int screenWidth = 272, screenHeight = 480; if (landscapeOrientation == LandscapeOrientation.Left || landscapeOrientation == LandscapeOrientation.Right) { screenWidth = 480; screenHeight = 272; } // first we check to see if we have a touch in the collection with a state of released, // and if so, we clear the list out if (touches.Count > 0 && touches[0].State == ZuneTouchState.Released) { touches.Clear(); } // if this is a new press of the left mouse button and the mouse is inside the window... if (mouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released && mouseState.X >= 0 && mouseState.X <= screenWidth && mouseState.Y >= 0 && mouseState.Y <= screenHeight) { // add a new ZuneTouch instance with our data touches.Add(new ZuneTouch { ID = id++, Position = new Vector2(mouseState.X, mouseState.Y), State = ZuneTouchState.Pressed, Pressure = 1 }); } // otherwise if the left button isn't newly pressed and we are tracking a touch already... else if (touches.Count > 0) { // get the touch var touch = touches[0]; // update the position touch.Position = new Vector2(mouseState.X, mouseState.Y); // we assume the touch has moved touch.State = ZuneTouchState.Moved; // if the mouse was released inside the window OR moved outside of the window... if ((mouseState.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed) || mouseState.X < 0 || mouseState.X > screenWidth || mouseState.Y < 0 || mouseState.Y > screenHeight) { // set the State to Released touch.State = ZuneTouchState.Released; } // set the touch back onto the list touches[0] = touch; } lastMouseState = mouseState; // to fake accelerometer data, we use a GamePad's thumbsticks and set the acceleration // using this system: // X Axis of Left Thumbstick = X axis // Y Axis of Left Thumbstick = Y axis // X Axis of Right Thumbstick = Z axis GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); Acceleration = new Vector3( gamePadState.ThumbSticks.Left.X, gamePadState.ThumbSticks.Left.Y, gamePadState.ThumbSticks.Right.X); #endif }
private void InitializeState() { if (_state == null) { _state = new AccelerometerState(); _state.SensorPort = (NxtSensorPort)LegoNxtPort.AnySensorPort; } if (_state.PollingFrequencyMs == 0) _state.PollingFrequencyMs = Contract.DefaultPollingFrequencyMs; if (_state.Tilt == null) _state.Tilt = new AccelerometerReading(); else { _state.Tilt.X = 0.0; _state.Tilt.Y = 0.0; _state.Tilt.Z = 0.0; _state.Tilt.TimeStamp = DateTime.MinValue; } _state.Connected = false; }
public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); // Look up inputs for the active player profile. int playerIndex = (int)ControllingPlayer.Value; // get all of our input states keyboardState = Keyboard.GetState(); gamePadState_1 = GamePad.GetState(PlayerIndex.One); gamePadState_2 = GamePad.GetState(PlayerIndex.Two); gamePadStates[0] = gamePadState_1; gamePadStates[1] = gamePadState_2; touchState = TouchPanel.GetState(); accelerometerState = Accelerometer.GetState(); // Exit the game when back is pressed. //if (gamePadState_1.Buttons.Back == ButtonState.Pressed) // Exit(); if (input.IsPauseGame(null)) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { foreach (Player player in PlatformerGame.Players) { bool continuePressed = keyboardState.IsKeyDown(Keys.Space) || gamePadStates[PlatformerGame.Players.IndexOf(player)].IsButtonDown(Buttons.A) || touchState.AnyTouch(); if (!player.IsAlive) { level.StartNewLife(player); } if (level.ReachedExit) { LoadNextLevel(); } } //check if both player is in the "no-man lands" if (players[0].Position.X == -999.9f && players[1].Position.X == -999.9f) { //players[attacker_id].Reset(Vector2.Zero); level.StartNewLife(players[attacker_id]); } } }
/// <summary> /// Updates all objects in the world, performs collision between them, /// and handles the time limit with scoring. /// </summary> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { // Pause while the player is dead or time is expired. if (!Player.IsAlive || TimeRemaining == TimeSpan.Zero) { // Still want to perform physics on the player. Player.ApplyPhysics(gameTime); } else if (ReachedExit) { // Animate the time being converted into points. int seconds = (int)Math.Round(gameTime.ElapsedGameTime.TotalSeconds * 100.0f); seconds = Math.Min(seconds, (int)Math.Ceiling(TimeRemaining.TotalSeconds)); timeRemaining -= TimeSpan.FromSeconds(seconds); score += seconds * PointsPerSecond; } else { timeRemaining -= gameTime.ElapsedGameTime; Player.Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); UpdateGems(gameTime); // Falling off the bottom of the level kills the player. if (Player.BoundingRectangle.Top >= Height * Tile.Height) OnPlayerKilled(null); UpdateEnemies(gameTime); // The player has reached the exit if they are standing on the ground and // his bounding rectangle contains the center of the exit tile. They can only // exit when they have collected all of the gems. if (Player.IsAlive && Player.IsOnGround && Player.BoundingRectangle.Contains(exit)) { OnExitReached(); } } // Clamp the time remaining at zero. if (timeRemaining < TimeSpan.Zero) timeRemaining = TimeSpan.Zero; }
/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { float elapsed = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); // TODO: Add your game logic here. sprite.UpdateFrame(elapsed, ref _position, ref flip, ref spriteState); if (IsAlive == false) { DropDead(); return; } //bool thereIsKid = false; foreach (Sprite s in SpriteRoom.SpritesInRoom()) { switch (s.GetType().Name) { case "Player": if (true) { if (s.IsAlive == false) { break; // TODO: might not be correct. Was : Exit Select } //thereIsKid = true; if (s.Position.CheckOnRow(Position)) { if (s.Position.CheckOnRowDistancePixel(Position) >= 0 & s.Position.CheckOnRowDistancePixel(Position) <= 70 & Alert == true & spriteState.Value().state == Enumeration.State.strike) { if (spriteState.Value().Name == Enumeration.State.strike.ToString().ToUpper()) { //check if block if (s.spriteState.Value().Name != Enumeration.State.readyblock.ToString().ToUpper()) { spriteState.Value().Name = string.Empty; s.Splash(true, gameTime); //Splash splash = new Splash(SpriteRoom, Position.Value, graphicsDevice, SpriteEffects.None, true); //Maze.sprites.Add(splash); s.Energy = s.Energy - 1; s.StrikeRetreat(); } else { System.Console.WriteLine("P->" + Enumeration.State.readyblock.ToString().ToUpper()); //blocked } } if (s.Energy == 0) { Fastheathe(); } } Alert = true; //Chenge Flip player.. if (Position.X < s.Position.X) { flip = SpriteEffects.None; } else { flip = SpriteEffects.FlipHorizontally; } Advance(s.Position, flip); } else { Alert = false; } break; // TODO: might not be correct. Was : Exit Select } default: break; // TODO: might not be correct. Was : Exit Select } } if (Alert == false) { Stand(); } //Ready(); else Stand(); }
private void UpdateTilesUp(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { int y = Height - 1; for (int x = 0; x <= Width - 1; x++) { // If there is a visible Tile in that position Texture2D texture = null; texture = tiles[x, y].Texture; if (texture != null) { // Draw it in screen space. Rectangle rect = new Rectangle(x * Convert.ToInt32(Math.Truncate(Tile.Size.X)), -1 * Convert.ToInt32(Math.Truncate(Tile.Size.Y)) - BOTTOM_BORDER, Convert.ToInt32(texture.Width), Convert.ToInt32(texture.Height)); Vector2 position = new Vector2(rect.X, rect.Y); tiles[x, y].Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); } } }
/// <summary> /// Gets player horizontal movement and jump commands from input. /// </summary> private void GetInput( KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation, InputManager inputManager) { // Get analog horizontal movement. movement.X = gamePadState.ThumbSticks.Left.X * MoveStickScale; // Get analog vertical movement. movement.Y = gamePadState.ThumbSticks.Left.Y * MoveStickScale; // Ignore small movements to prevent running in place. if (Math.Abs(movement.X) < 0.5f) { movement.X = 0.0f; } if (Math.Abs(movement.Y) < 0.5f) { movement.Y = 0.0f; } /* // Move the player with accelerometer if (Math.Abs(accelState.Acceleration.Y) > 0.10f) { // set our movement speed movement = MathHelper.Clamp(-accelState.Acceleration.Y * AccelerometerScale, -1f, 1f); // if we're in the LandscapeLeft orientation, we must reverse our movement if (orientation == DisplayOrientation.LandscapeRight) movement = -movement; } */ // If any digital horizontal movement input is found, override the analog movement. if (gamePadState.IsButtonDown(Buttons.DPadLeft) || keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { movement.X = -1.0f; } else if (gamePadState.IsButtonDown(Buttons.DPadRight) || keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { movement.X = 1.0f; } // Handle ladder up input if (gamePadState.IsButtonDown(Buttons.DPadUp) || keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) { isClimbing = false; //makes sure the players position is aligned to the center of the ladder if (IsAlignedToLadder()) { //need to check the tile behind the player, not what he is standing on if (level.GetTileCollisionBehindPlayer(position) == TileCollision.Ladder) { isClimbing = true; isJumping = false; isOnGround = false; movement.Y = -1.0f; } } } // Handle ladder down input else if (gamePadState.IsButtonDown(Buttons.DPadDown) || keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) { isClimbing = false; //makes sure the players position is aligned to the center of the ladder if (IsAlignedToLadder()) { //need to check the tile that the player is standing on if (level.GetTileCollisionBelowPlayer(this.Position) == TileCollision.Ladder) { isClimbing = true; isJumping = false; isOnGround = false; movement.Y = 2.0f; } } } // Check if the player wants to jump. // Change this so that we only want to jump if it is a new press - i.e. KeyPressDown() // //isJumping = gamePadState.IsButtonDown(JumpButton) || keyboardState.IsKeyDown(Keys.Space) || keyboardState.IsKeyDown(Keys.Up) || // keyboardState.IsKeyDown(Keys.W) || touchState.AnyTouch(); isJumping = inputManager.IsNewPress(JumpButton) || inputManager.IsNewPress(Keys.Space) || inputManager.IsNewPress(Keys.Up) || inputManager.IsNewPress(Keys.W); }
public void updategame(float gtime) { music.Play(); // Main game code if (!gameover) { if (bulletcount <= 0) { bulletcount = 0; } if (health <= 0) { gameover = true; } for (int i = 0; i < numberofbullets; i++) { if (playerbullet[i].visible) { playerbullet[i].velocity.Z += playerchar.velocity.Z * 2; playerbullet[i].updateobject(); if (playerbullet[i].position.Z > playerchar.position.Z + 10000) { playerbullet[i].visible = false; } // Check for bullet hitting zombies for (int j = 0; j < numberofzombs; j++) { if (playerbullet[i].bsphere.Intersects(zombies[j].bbox)) { zombiehit.Play(); score += 10; playerbullet[i].visible = false; spawnzombie(j, playerchar.position.Z); } } } } for (int i = 0; i < numberofzombs; i++) { if (zombies[i].position.Z <= playerchar.position.Z - 1000) { spawnzombie(i, playerchar.position.Z); } } // Game is being played if (pad[0].Buttons.Back == ButtonState.Pressed) { gameover = true; // Allow user to quit game } // Check for touch presses on arrow keys Vector2 dirtomove = new Vector2(0, 0); float turnamount = MathHelper.ToRadians(0); TouchCollection tcoll = TouchPanel.GetState(); BoundingSphere touchsphere = new BoundingSphere(new Vector3(0, 0, 0), 1); foreach (TouchLocation t1 in tcoll) { if (t1.State == TouchLocationState.Pressed || t1.State == TouchLocationState.Moved) { touchsphere = new BoundingSphere(new Vector3(t1.Position.X, t1.Position.Y, 0), 1); if (touchsphere.Intersects(up.bbox)) { dirtomove.Y = 1; } if (touchsphere.Intersects(down.bbox)) { dirtomove.Y = -1; } if (touchsphere.Intersects(left.bbox)) { dirtomove.X = 1; } if (touchsphere.Intersects(right.bbox)) { dirtomove.X = -1; } if (touchsphere.Intersects(firebut.bbox) && bulletcount <= 0) { playerfire(); } } } // Move Robot based on touch control input playerchar.moveme(dirtomove, turnamount, gtime, 70); // Check for collisions between player and zombies for (int i = 0; i < numberofzombs; i++) { zombies[i].updateobject(); if (playerchar.bbox.Intersects(zombies[i].bbox) && zombies[i].visible) { playerhit.Play(); zombies[i].visible = false; health--; playerchar.velocity.Z = -playerchar.velocity.Z; spawnzombie(i, playerchar.position.Z); } } // Move Robot based on accelerometer dirtomove = new Vector2(0, 0); AccelerometerState accelsen = accelerometer1.Accelerometer.GetState(); if (accelsen.IsActive) { acc = accelsen.Acceleration; dirtomove.X = accelsen.Acceleration.Y * 2; if (TouchPanel.DisplayOrientation == DisplayOrientation.LandscapeRight) { dirtomove.X = -dirtomove.X; } } // Move Robot based on accelerometer input playerchar.moveme(dirtomove, turnamount, gtime, 70); if (playerchar.velocity.Z < 5) { playerchar.velocity.Z = 5; // Set a minimum speed for the robot } // Set limits for the robots movements int wall_limits = 822; if (playerchar.position.X < -wall_limits) { playerchar.position.X = -wall_limits; } if (playerchar.position.X > wall_limits) { playerchar.position.X = wall_limits; } // Read flick gestures TouchPanel.EnabledGestures = GestureType.Flick; while (TouchPanel.IsGestureAvailable) { GestureSample gs = TouchPanel.ReadGesture(); if (gs.GestureType == GestureType.Flick) { playerchar.jump(Math.Abs(gs.Delta.Y / 175)); // Jump robot based on the Y flick gesture amount } } // Move ground & wall panels forward once you pass them for (int i = 0; i < numberofgrounds; i++) { if (playerchar.position.Z > ground[i].position.Z + (500 * ground[i].size)) { ground[i].position.Z += (800 * ground[i].size * (numberofgrounds - 1)); leftwall[i].position.Z = ground[i].position.Z; rightwall[i].position.Z = ground[i].position.Z; } } // Set side on camera view //gamecamera.setsideon(uservehicle.position, uservehicle.rotation, 1000, 100, 400); // Set the camera to first person //gamecamera.setFPor3P(uservehicle.position, uservehicle.direction, new Vector3(0, 0, 0), 100, 300, 60, 45); // Set overhead camera view //gamecamera.setoverhead(playerchar.position, 2000); // Set the camera to third person gamecamera.setFPor3P(playerchar.position, playerchar.direction, playerchar.velocity, 100, 100, 150, 100); // Allow the camera to look up and down //cameraposition.Y += (pad[0].ThumbSticks.Right.Y * 140); } else { //Stop music if its playing if (music.State == SoundState.Playing) { music.Stop(); } // Game is over, allow game to return to the main menu if (pad[0].Buttons.Back == ButtonState.Pressed) { if (score > highscores[9] && score > 0) { highscores[9] = score; } // SORT HIGHSCORE TABLE Array.Sort(highscores); Array.Reverse(highscores); gamestate = -1; // Allow user to quit game } } }
///<summary> /// Constructor that sets current accelerometer state for the event. </summary> public AccelerometerStateEventArgs(AccelerometerState state) { _state = state; _message = ""; }
/// <summary> /// Updates all objects in the world, performs collision between them, /// and handles the time limit with scoring. /// </summary> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState[] gamePadStates, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation, Viewport viewport) { // Play the bridge withdrawing animation if (isBridgeWithdrawing) { WithdrawBridge(gameTime); } else { // Pause while the player is dead or time is expired. foreach (Player player in PlatformerGame.Players) { if (!player.IsAlive)// || TimeRemaining == TimeSpan.Zero) { // Still want to perform physics on the player. player.ApplyPhysics(gameTime); } else if (ReachedExit) { // Animate the time being converted into points. int seconds = (int)Math.Round(gameTime.ElapsedGameTime.TotalSeconds * 100.0f); seconds = Math.Min(seconds, (int)Math.Ceiling(TimeRemaining.TotalSeconds)); timeRemaining -= TimeSpan.FromSeconds(seconds); score += seconds * PointsPerSecond; } else { timeRemaining -= gameTime.ElapsedGameTime; player.Update(gameTime, keyboardState, gamePadStates[player.PlayerId], touchState, accelState, orientation, viewport); UpdateGems(gameTime); // Falling off the bottom of the level kills the player. if (player.BoundingRectangle.Top >= Height * Tile.Height) { PlatformerGame.attacker_id = (player.PlayerId == 0) ? 1 : 0; fallingSound.Play(); if (!PlatformerGame.bossFight) { player.OnKilled(); player.Reset(); } else { game.displayEpicFail(); } } UpdateEnemies(gameTime); UpdateSpikes(gameTime); UpdateWinnerTile(gameTime); // The player has reached the exit if they are standing on the ground and // his bounding rectangle contains the center of the exit tile. They can only // exit when they have collected all of the gems. if (game.firstKill && player.PlayerId == PlatformerGame.attacker_id) { if (player.IsAlive && player.IsOnGround) { if (player.BoundingRectangle.Contains(exit[PlatformerGame.attacker_id])) { OnExitReached(); } if (player.BoundingRectangle.Contains(bridgeSwitch)) { WithdrawBridge(gameTime); } } } } } } // Clamp the time remaining at zero. if (timeRemaining < TimeSpan.Zero) { //timeRemaining = TimeSpan.Zero; timeRemaining = TimeSpan.FromMinutes(2.0); } }
private void UpdateTilesTemporaney(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { try { //workaroud to thread unsafe...? lock (tilesTemporaney) { foreach (Tile item in tilesTemporaney) { // Insert your code here. item.Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); } } } catch (Exception ex) { } }