public void Handle(float iterationDuration, PlayersInput input) { this.BallHandle(); this.LegsHandleBeforeStep(); this.PlayerLeftOperate(input, iterationDuration); this.PlayerRightOperate(input, iterationDuration); this.world.Step(iterationDuration / 1000, 8, 4); this.LegsHandleAfterStep(iterationDuration); this.DetectGoal(); this.CheckImpudentDefense(iterationDuration); }
private PlayersInput GetPlayerInput() { var input = new PlayersInput(); if (Keyboard.IsKeyPressed(Keyboard.Key.A)) { input.PlayerLeftLeft = true; } if (Keyboard.IsKeyPressed(Keyboard.Key.D)) { input.PlayerLeftRight = true; } if (Keyboard.IsKeyPressed(Keyboard.Key.W)) { input.PlayerLeftJump = true; } if (Keyboard.IsKeyPressed(Keyboard.Key.LControl)) { input.PlayerLeftKick = true; } if (Keyboard.IsKeyPressed(Keyboard.Key.Left)) { input.PlayerRightLeft = true; } if (Keyboard.IsKeyPressed(Keyboard.Key.Right)) { input.PlayerRightRight = true; } if (Keyboard.IsKeyPressed(Keyboard.Key.Up)) { input.PlayerRightJump = true; } if (Keyboard.IsKeyPressed(Keyboard.Key.RControl)) { input.PlayerRightKick = true; } return(input); }
protected void PlayerRightOperate(PlayersInput input, float iterationDuration) { if (this.playerRightTimers.Jump >= 0) { this.playerRightTimers.Jump -= iterationDuration; } Vector2 velocity; velocity = this.playerRight.LinearVelocity; if (input.PlayerRightLeft && (velocity.X > -2.3)) { this.playerRight.ApplyForce(new Vector2(-11, 0), this.playerRight.Position); } if (input.PlayerRightRight && (velocity.X < 2.3)) { this.playerRight.ApplyForce(new Vector2(11, 0), this.playerRight.Position); } if (this.PlayerRightCanJump() && (this.playerRightTimers.Jump < 0)) { if (input.PlayerRightJump) { this.playerRight.ApplyLinearImpulse(new Vector2(0, -0.72f), this.playerRight.Position); this.playerRightTimers.Jump = 100; } } if (this.playerRightLegForce > 0.1f) { this.playerRightLegForce *= 0.97f; } if (input.PlayerRightKick && this.legRight.AngularVelocity < System.Math.PI * 9) { this.playerRightLegForce = 1.5f; } if (this.playerRightLegForce > 0.1f) { this.legRight.ApplyTorque(this.playerRightLegForce); } }
private void PlayerLeftOperate(PlayersInput input, float iterationDuration) { if (this.playerLeftTimers.Jump >= 0) { this.playerLeftTimers.Jump -= iterationDuration; } Vec2 velocity; velocity = this.playerLeft.GetLinearVelocity(); if (input.PlayerLeftLeft && (velocity.X > -2.6)) { this.playerLeft.ApplyForce(new Vec2(-11, 0), this.playerLeft.GetPosition()); } if (input.PlayerLeftRight && (velocity.X < 2.6)) { this.playerLeft.ApplyForce(new Vec2(11, 0), this.playerLeft.GetPosition()); } if (this.PlayerLeftCanJump() && (this.playerLeftTimers.Jump < 0)) { if (input.PlayerLeftJump) { this.playerLeft.ApplyImpulse(new Vec2(0, -0.78f), this.playerLeft.GetPosition()); this.playerLeftTimers.Jump = 100; } } if (this.playerLeftLegForce < -0.1f) { this.playerLeftLegForce *= 0.97f; } if (input.PlayerLeftKick && this.legLeft.GetAngularVelocity() > -System.Math.PI * 9) { this.playerLeftLegForce = -1.5f; } if (this.playerLeftLegForce < -0.1f) { this.legLeft.ApplyTorque(this.playerLeftLegForce); } }