/// <summary> /// Check if networkinputcomponent's parameters are true and do actions on remote player /// </summary> /// <param name="gameTime"></param> /// <param name="playerEntity"></param> private void ParseNetworkInput(GameTime gameTime, Entity playerEntity) { NetworkInputComponent networkInputComponent = ComponentManager.Instance.ConcurrentGetComponentOfEntity <NetworkInputComponent>(playerEntity); VelocityComponent velocityComponent = ComponentManager.Instance.ConcurrentGetComponentOfEntity <VelocityComponent>(playerEntity); TransformComponent transformComponent = ComponentManager.Instance.ConcurrentGetComponentOfEntity <TransformComponent>(playerEntity); GravityComponent gravityComponent = ComponentManager.Instance.ConcurrentGetComponentOfEntity <GravityComponent>(playerEntity); if (networkInputComponent.MoveForward) { PlayerActions.AcceleratePlayerForwards(gameTime, velocityComponent); } if (networkInputComponent.MoveLeft) { PlayerActions.AcceleratePlayerLeftwards(gameTime, velocityComponent); } if (networkInputComponent.MoveRight) { PlayerActions.AcceleratePlayerRightwards(gameTime, velocityComponent); } if (networkInputComponent.Jump) { PlayerActions.PlayerJump(gameTime, velocityComponent); } if (networkInputComponent.MoveBackward) { PlayerActions.AcceleratePlayerBackwards(gameTime, velocityComponent); } }
protected void ExecuteMove(GameTime gameTime, Vector3 currentBlock, Vector3 nextBlock, Vector3 position, VelocityComponent velocity, GravityComponent gravity, AiComponent aiComponent) { PlayerActions.AcceleratePlayerForwards(gameTime, velocity); if (aiComponent.CurrentState == State.Winning) { if (Random.Next(0, 11) == 1) //20% chance to make random move { Console.WriteLine("RandomMove "); if (Random.Next(0, 2) == 1) //50% chance to go left or right { PlayerActions.AcceleratePlayerLeftwards(gameTime, velocity); if (!gravity.HasJumped) { PlayerActions.PlayerJump(gameTime, velocity, null); gravity.HasJumped = true; } } PlayerActions.AcceleratePlayerRightwards(gameTime, velocity); if (!gravity.HasJumped) { PlayerActions.PlayerJump(gameTime, velocity, null); gravity.HasJumped = true; } return; } } Console.WriteLine("Regular move"); if (currentBlock.X < nextBlock.X) //if the block that AI wants to go to is "lower" X value AKA left of the current we need to jump left { PlayerActions.AcceleratePlayerLeftwards(gameTime, velocity); if (!gravity.HasJumped) { PlayerActions.PlayerJump(gameTime, velocity, null); gravity.HasJumped = true; } } if (currentBlock.X > nextBlock.X) //if the block that AI wants to go to is "higher" X value AKA right of the current we need to jump right { PlayerActions.AcceleratePlayerRightwards(gameTime, velocity); if (!gravity.HasJumped) { PlayerActions.PlayerJump(gameTime, velocity, null); gravity.HasJumped = true; } } if (currentBlock.X == nextBlock.X) { PlayerActions.AcceleratePlayerForwards(gameTime, velocity); if (!gravity.HasJumped) { PlayerActions.PlayerJump(gameTime, velocity, null); gravity.HasJumped = true; } } }
/* * Gets player keyboard input and takes appropriate action. */ public void ParsePlayerInput(GameTime gameTime, Entity playerEntity) { VelocityComponent velocityComponent = componentManager.ConcurrentGetComponentOfEntity <VelocityComponent>(playerEntity); KeyboardComponent keyboardComponent = componentManager.ConcurrentGetComponentOfEntity <KeyboardComponent>(playerEntity); GamePadComponent gamePadComponent = componentManager.ConcurrentGetComponentOfEntity <GamePadComponent>(playerEntity); GravityComponent gravityComponent = componentManager.ConcurrentGetComponentOfEntity <GravityComponent>(playerEntity); /* Keyboard actions */ if (keyboardComponent != null && velocityComponent != null) { KeyboardState state = Keyboard.GetState(); if (state.IsKeyDown(Keys.Up) && !state.IsKeyDown(Keys.Down)) { PlayerActions.AcceleratePlayerForwards(gameTime, velocityComponent); } if (state.IsKeyDown(Keys.Down) && !state.IsKeyDown(Keys.Up)) { PlayerActions.AcceleratePlayerBackwards(gameTime, velocityComponent); } if (state.IsKeyDown(Keys.Left) && !state.IsKeyDown(Keys.Right)) { PlayerActions.AcceleratePlayerLeftwards(gameTime, velocityComponent); } if (state.IsKeyDown(Keys.Right) && !state.IsKeyDown(Keys.Left)) { PlayerActions.AcceleratePlayerRightwards(gameTime, velocityComponent); } if (state.IsKeyDown(Keys.Space)) { if (!gravityComponent.HasJumped) { PlayerActions.PlayerJump(gameTime, velocityComponent, playerEntity); gravityComponent.HasJumped = true; } } } #region /* Gamepad actions */ if (gamePadComponent != null && velocityComponent != null) { GamePadState state = GamePad.GetState(gamePadComponent.Index); if (state.IsButtonDown(Buttons.A) && !state.IsButtonDown(Buttons.B)) { PlayerActions.AcceleratePlayerForwards(gameTime, velocityComponent); } if (state.IsButtonDown(Buttons.B) && !state.IsButtonDown(Buttons.A)) { PlayerActions.AcceleratePlayerBackwards(gameTime, velocityComponent); } if (state.IsButtonDown(Buttons.LeftThumbstickLeft) && !state.IsButtonDown(Buttons.LeftThumbstickRight)) { PlayerActions.AcceleratePlayerLeftwards(gameTime, velocityComponent); } if (state.IsButtonDown(Buttons.LeftThumbstickRight) && !state.IsButtonDown(Buttons.LeftThumbstickLeft)) { PlayerActions.AcceleratePlayerRightwards(gameTime, velocityComponent); } if (state.IsButtonDown(Buttons.Y) && !state.IsButtonDown(Buttons.A)) { if (!gravityComponent.HasJumped) { PlayerActions.PlayerJump(gameTime, velocityComponent, playerEntity); gravityComponent.HasJumped = true; } } } #endregion }