コード例 #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            const double ELAPSEDTIME = .5;

            #region Do Physics

            _poolBall.PrepareForNewTimerCycle();


            if (_isMouseJustReleased)
            {
                _isMouseJustReleased = false;

                MyVector force = new MyVector(_mouseDownPoint);
                force.Subtract(new MyVector(_curMousePoint));

                MyVector offset = new MyVector(_mouseDownPoint);
                offset.Subtract(_poolBall.Position);

                _poolBall.ApplyExternalForce(offset, force);
            }


            _poolBall.TimerTestPosition(ELAPSEDTIME);
            _poolBall.TimerFinish();

            #endregion

            #region Draw

            ClearPictureBox();

            if (_isMouseDown)
            {
                DrawVector(_poolBall.Position, new MyVector(_mouseDownPoint.X, _mouseDownPoint.Y, 0), Color.Olive);
                DrawVector(new MyVector(_mouseDownPoint.X, _mouseDownPoint.Y, 0), new MyVector(_curMousePoint.X, _curMousePoint.Y, 0), Color.Gold);
            }

            DrawBall(_poolBall, Color.Silver, Color.MediumPurple, Color.Purple);

            BlitImage();

            #endregion
        }
コード例 #2
0
        private void timer2_Tick(object sender, EventArgs e)
        {
            const double GRAVITY       = 20;
            const double THRUSTERFORCE = 30;
            const double ELAPSEDTIME   = .5;

            List <MyVector[]> thrustLines = new List <MyVector[]>();

            #region Color PictureBoxes

            if (_isUpPressed)
            {
                pctUp.BackColor = SystemColors.ControlDark;
            }
            else
            {
                pctUp.BackColor = SystemColors.Control;
            }

            if (_isDownPressed)
            {
                pctDown.BackColor = SystemColors.ControlDark;
            }
            else
            {
                pctDown.BackColor = SystemColors.Control;
            }

            if (_isLeftPressed && radPairedThrusters.Checked)
            {
                pctLeft.BackColor = SystemColors.ControlDark;
            }
            else
            {
                pctLeft.BackColor = SystemColors.Control;
            }

            if (_isRightPressed && radPairedThrusters.Checked)
            {
                pctRight.BackColor = SystemColors.ControlDark;
            }
            else
            {
                pctRight.BackColor = SystemColors.Control;
            }

            if (_isWPressed && radIndependantThrusters.Checked)
            {
                pctW.BackColor = SystemColors.ControlDark;
            }
            else
            {
                pctW.BackColor = SystemColors.Control;
            }

            if (_isSPressed && radIndependantThrusters.Checked)
            {
                pctS.BackColor = SystemColors.ControlDark;
            }
            else
            {
                pctS.BackColor = SystemColors.Control;
            }

            #endregion

            #region Do Physics

            _ship.PrepareForNewTimerCycle();

            if (radIndependantThrusters.Checked)
            {
                #region Independant Thrusters

                if (_isUpPressed)
                {
                    timer2_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_BottomRight, new MyVector(0, -1, 0), THRUSTERFORCE);            // up
                }

                if (_isDownPressed)
                {
                    timer2_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_TopRight, new MyVector(0, 1, 0), THRUSTERFORCE);                // down
                }

                if (_isWPressed)
                {
                    timer2_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_BottomLeft, new MyVector(0, -1, 0), THRUSTERFORCE);             // w
                }

                if (_isSPressed)
                {
                    timer2_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_TopLeft, new MyVector(0, 1, 0), THRUSTERFORCE);         // s
                }

                #endregion
            }
            else
            {
                #region Paired Thrusters

                if (_isUpPressed)
                {
                    timer2_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_BottomRight, new MyVector(0, -1, 0), THRUSTERFORCE);            // up
                    timer2_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_BottomLeft, new MyVector(0, -1, 0), THRUSTERFORCE);             // w
                }

                if (_isDownPressed)
                {
                    timer2_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_TopRight, new MyVector(0, 1, 0), THRUSTERFORCE);        // down
                    timer2_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_TopLeft, new MyVector(0, 1, 0), THRUSTERFORCE);         // s
                }

                if (_isLeftPressed)
                {
                    timer2_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_BottomRight, new MyVector(0, -1, 0), THRUSTERFORCE);    // up
                    timer2_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_TopLeft, new MyVector(0, 1, 0), THRUSTERFORCE);         // s
                }

                if (_isRightPressed)
                {
                    timer2_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_TopRight, new MyVector(0, 1, 0), THRUSTERFORCE);                // down
                    timer2_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_BottomLeft, new MyVector(0, -1, 0), THRUSTERFORCE);             // w
                }

                #endregion
            }

            if (chkShipGravity.Checked)
            {
                _ship.ExternalForce.Add(new MyVector(0, GRAVITY, 0));
            }

            _ship.TimerTestPosition(ELAPSEDTIME);
            _ship.TimerFinish();

            #endregion

            #region Draw

            ClearPictureBox();

            // Ship
            DrawBall(_ship, Color.SteelBlue, Color.LightSteelBlue, Color.DimGray);

            // Thrusters
            DrawThruster(_ship, _shipThrusterOffset_BottomRight);
            DrawThruster(_ship, _shipThrusterOffset_BottomLeft);
            DrawThruster(_ship, _shipThrusterOffset_TopRight);
            DrawThruster(_ship, _shipThrusterOffset_TopLeft);

            // Thrust Lines
            foreach (MyVector[] thrustPair in thrustLines)
            {
                MyVector thrustStart = _ship.Rotation.GetRotatedVector(thrustPair[0], true);
                thrustStart.Add(_ship.Position);

                MyVector thrustStop = thrustPair[1] * -20d;
                thrustStop.Add(thrustPair[0]);
                thrustStop = _ship.Rotation.GetRotatedVector(thrustStop, true);
                thrustStop.Add(_ship.Position);

                DrawVector(thrustStart, thrustStop, Color.Coral, 4);
            }

            BlitImage();

            #endregion
        }