/// <inheritdoc /> protected override void PreUpdate() { if (Input.GetKeyDown(KeyCode.A)) { _button = true; } if (Input.GetKeyUp(KeyCode.A)) { _button = false; } if (_button) { _leftJoint.SetMotorSpeed(20.0f); _rightJoint.SetMotorSpeed(-20.0f); } else { _leftJoint.SetMotorSpeed(-10.0f); _rightJoint.SetMotorSpeed(10.0f); } DrawString("Press 'a' to control the flippers"); }
protected override void PreStep() { if (_button) { _leftJoint.SetMotorSpeed(20.0f); _rightJoint.SetMotorSpeed(-20.0f); } else { _leftJoint.SetMotorSpeed(-10.0f); _rightJoint.SetMotorSpeed(10.0f); } }
public override void Update(float dt) { //if (Keyboard.IsPressed(KeyConstant.Space)) base.Update(dt); if (Keyboard.IsDown(KeyConstant.X)) { lrj.SetMotorSpeed(20.0f); rrj.SetMotorSpeed(-20.0f); } else { lrj.SetMotorSpeed(-10.0f); rrj.SetMotorSpeed(10.0f); } }
protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.A) { _motorJoint.SetMotorSpeed(-_motorSpeed); } if (e.KeyCode == Keys.S) { _motorJoint.SetMotorSpeed(0.0f); } if (e.KeyCode == Keys.D) { _motorJoint.SetMotorSpeed(_motorSpeed); } if (e.KeyCode == Keys.M) { _motorJoint.EnableMotor(!_motorJoint.IsMotorEnabled()); } }
public override void Load() { // Ground body Body ground; { ground = Physics.NewBody(m_world); // outline Physics.NewFixture(ground, Physics.NewChainShape(true, new Vector2[] { new Vector2(0.0f, -2.0f), new Vector2(8.0f, 6.0f), new Vector2(8.0f, 20.0f), new Vector2(-8.0f, 20.0f), new Vector2(-8.0f, 6.0f), }), 0); } // Flippers { var p1 = new Vector2(-2.0f, 0.0f); var p2 = new Vector2(2.0f, 0.0f); Body leftFlipper = Physics.NewBody(m_world, p1.X, p1.Y, BodyType.Dynamic); Body rightFlipper = Physics.NewBody(m_world, p2.X, p2.Y, BodyType.Dynamic); var box = Physics.NewRectangleShape(1.75f * 2, 0.1f * 2); Physics.NewFixture(leftFlipper, box, 1.0f); Physics.NewFixture(rightFlipper, box, 1.0f); lrj = Physics.NewRevoluteJoint(ground, leftFlipper, p1); lrj.SetMotorSpeed(0); lrj.SetMotorEnabled(true); lrj.SetLimitsEnabled(true); lrj.SetMaxMotorTorque(1000.0f); lrj.SetLimits(-30.0f * Mathf.PI / 180.0f, 5.0f * Mathf.PI / 180.0f); rrj = Physics.NewRevoluteJoint(ground, rightFlipper, p2); rrj.SetMotorSpeed(0); rrj.SetMotorEnabled(true); rrj.SetLimitsEnabled(true); rrj.SetMaxMotorTorque(1000.0f); rrj.SetLimits(-5.0f * Mathf.PI / 180.0f, 30.0f * Mathf.PI / 180.0f); } // Circle character { var body = Physics.NewBody(m_world, 1.0f, 15.0f, BodyType.Dynamic); body.SetBullet(true); Physics.NewFixture(body, Physics.NewCircleShape(0.2f), 1.0f); } }
/// <inheritdoc /> /// <inheritdoc /> public override void OnKeyDown(KeyInputEventArgs keyInput) { if (keyInput.Key == KeyCodes.A) { _motorJoint.SetMotorSpeed(-_motorSpeed); } if (keyInput.Key == KeyCodes.S) { _motorJoint.SetMotorSpeed(0.0f); } if (keyInput.Key == KeyCodes.D) { _motorJoint.SetMotorSpeed(_motorSpeed); } if (keyInput.Key == KeyCodes.M) { _motorJoint.EnableMotor(!_motorJoint.IsMotorEnabled()); } }
/// <inheritdoc /> protected override void OnStep() { if (Input.GetKeyDown(KeyCode.A)) { _motorJoint.SetMotorSpeed(-_motorSpeed); } if (Input.GetKeyDown(KeyCode.S)) { _motorJoint.SetMotorSpeed(0.0f); } if (Input.GetKeyDown(KeyCode.D)) { _motorJoint.SetMotorSpeed(_motorSpeed); } if (Input.GetKeyDown(KeyCode.M)) { _motorJoint.EnableMotor(!_motorJoint.IsMotorEnabled()); } }
/// <inheritdoc /> /// <inheritdoc /> public override void OnKeyDown(KeyboardKeyEventArgs key) { if (key.Key == Key.A) { _motorJoint.SetMotorSpeed(-_motorSpeed); } if (key.Key == Key.S) { _motorJoint.SetMotorSpeed(0.0f); } if (key.Key == Key.D) { _motorJoint.SetMotorSpeed(_motorSpeed); } if (key.Key == Key.M) { _motorJoint.EnableMotor(!_motorJoint.IsMotorEnabled()); } }
protected override void OnStep() { if (Input.GetKeyDown(KeyCode.A)) { _button = true; } if (Input.GetKeyUp(KeyCode.A)) { _button = false; } if (_button) { _leftJoint.SetMotorSpeed(20.0f); _rightJoint.SetMotorSpeed(-20.0f); } else { _leftJoint.SetMotorSpeed(-10.0f); _rightJoint.SetMotorSpeed(10.0f); } }
/// <inheritdoc /> protected override void PreUpdate() { if (Input.GetKeyDown(KeyCode.A)) { _motorJoint.SetMotorSpeed(-_motorSpeed); } if (Input.GetKeyDown(KeyCode.S)) { _motorJoint.SetMotorSpeed(0.0f); } if (Input.GetKeyDown(KeyCode.D)) { _motorJoint.SetMotorSpeed(_motorSpeed); } if (Input.GetKeyDown(KeyCode.M)) { _motorJoint.EnableMotor(!_motorJoint.IsMotorEnabled()); } DrawString("Keys: left = a, brake = s, right = d, toggle motor = m"); }
public override void Load() { genDT = 0; Body ground = Physics.NewBody(m_world); { Body body = Physics.NewBody(m_world, 0.0f * scale, 10.0f * scale, BodyType.Dynamic); body.SetSleepingAllowed(false); Physics.NewFixture(body, NewRectShape(body, 10.0f * scale, 0.0f * scale, 0.5f * 2 * scale, 10.0f * 2 * scale), 5.0f * scale); Physics.NewFixture(body, NewRectShape(body, -10.0f * scale, 0.0f * scale, 0.5f * 2 * scale, 10.0f * 2 * scale), 5.0f * scale); Physics.NewFixture(body, NewRectShape(body, 0.0f * scale, 10.0f * scale, 10.0f * 2 * scale, 0.5f * 2 * scale), 5.0f * scale); Physics.NewFixture(body, NewRectShape(body, 0.0f * scale, -10.0f * scale, 10.0f * 2 * scale, 0.5f * 2 * scale), 5.0f * scale); //RevoluteJoint jd = Physics.NewRevoluteJoint(ground, body, // new Vector2(0.0f, 10.0f) * scale, // new Vector2(0.0f, 0.0f) * scale // ); RevoluteJoint jd = Physics.NewRevoluteJoint(ground, body, new Vector2(0.0f, 10.0f) * scale, new Vector2(0.0f, 10.0f) * scale ); jd.SetMotorSpeed(-0.05f * Mathf.PI); jd.SetMaxMotorTorque(1e8f * scale); jd.SetMotorEnabled(true); } m_count = 0; }