예제 #1
0
        /// <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");
        }
예제 #2
0
 protected override void PreStep()
 {
     if (_button)
     {
         _leftJoint.SetMotorSpeed(20.0f);
         _rightJoint.SetMotorSpeed(-20.0f);
     }
     else
     {
         _leftJoint.SetMotorSpeed(-10.0f);
         _rightJoint.SetMotorSpeed(10.0f);
     }
 }
예제 #3
0
        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);
            }
        }
예제 #4
0
 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());
     }
 }
예제 #5
0
        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);
            }
        }
예제 #6
0
        /// <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());
            }
        }
예제 #7
0
        /// <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());
            }
        }
예제 #8
0
        /// <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());
            }
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
        /// <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");
        }
예제 #11
0
        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;
        }