Пример #1
0
        private void MultiBallTimer_Tick(object sender, EventArgs e)
        {
            // Physics
            #region OLD
            //for (int cntr = 0; cntr < _multiBalls.Count; cntr++)
            //{
            //    // Run the timer
            //    _multiBalls[cntr].PrepareForNewTimerCycle();
            //    _multiBalls[cntr].TimerTestPosition(ELAPSEDTIME);
            //    _multiBalls[cntr].TimerFinish();
            //}
            #endregion
            _map.PrepareForNewTimerCycle();

            if (chkGravity.IsChecked != null && chkGravity.IsChecked.Value)
            {
                DoGravity();
            }

            _map.Timer(ELAPSEDTIME);


            // Render
            RadarBlip[] blips = _map.GetAllBlips();
            for (int cntr = 0; cntr < blips.Length; cntr++)
            {
                Transform3DGroup group = _geometries[cntr].Transform as Transform3DGroup;
                group.Children.Clear();
                group.Children.Add(new TranslateTransform3D(blips[cntr].Sphere.Position.X, blips[cntr].Sphere.Position.Y, blips[cntr].Sphere.Position.Z));
            }
        }
Пример #2
0
        // Timer
        private void timer1_Tick(object sender, EventArgs e)
        {
            Collision[] collisions = null;
            if (btnRunning.Checked)
            {
                #region Physics

                _map.PrepareForNewTimerCycle();

                if (_gravMouse.Active)
                {
                    _gravMouse.Timer();
                }

                _shipController.Timer(ELAPSEDTIME);

                _gravController.Timer();

                collisions = _map.Timer(ELAPSEDTIME);

                if (_selector.Active)
                {
                    _selector.TimerTick(ELAPSEDTIME);
                }

                #endregion
            }

            #region Examine Collisions

            if (collisions != null)
            {
                foreach (Collision collision in collisions)
                {
                    #region Check Temps

                    bool wasTemp = false;

                    if (_tempObjects.Contains(collision.Blip1.Token))
                    {
                        _tempObjects.Remove(collision.Blip1.Token);
                        _map.Remove(collision.Blip1.Token);
                        wasTemp = true;
                    }

                    if (_tempObjects.Contains(collision.Blip2.Token))
                    {
                        _tempObjects.Remove(collision.Blip2.Token);
                        _map.Remove(collision.Blip2.Token);
                        wasTemp = true;
                    }

                    if (wasTemp)
                    {
                        continue;
                    }

                    #endregion

                    if (_ignoreTokens.Contains(collision.Blip1.Token) || _ignoreTokens.Contains(collision.Blip2.Token))
                    {
                        continue;
                    }

                    if (collision.Blip1 is Projectile && !(collision.Blip2 is Projectile))
                    {
                        HurtBlip((Projectile)collision.Blip1, collision.Blip2);
                    }
                    else if (collision.Blip2 is Projectile && !(collision.Blip1 is Projectile))
                    {
                        HurtBlip((Projectile)collision.Blip2, collision.Blip1);
                    }
                }
            }

            #endregion

            #region Reset Z

            _zeroResetCntr++;

            if (_zeroResetCntr % 100000 == 0)
            {
                _zeroResetCntr = 0;

                foreach (RadarBlip blip in _map.GetAllBlips())
                {
                    blip.Sphere.Position.Z = 0;

                    if (blip is BallBlip)
                    {
                        if (((BallBlip)blip).Ball.Velocity.Z != 0d)
                        {
                            MessageBox.Show("not zero velocity");
                        }

                        ((BallBlip)blip).Ball.Velocity.Z = 0;
                    }
                }
            }

            #endregion

            #region Draw

            pictureBox1.PrepareForNewDraw();

            if (_gravMouse.Active)
            {
                _gravMouse.Draw();
            }

            RadarBlip[] blips = _map.GetAllBlips();

            // Draw all the blips
            for (int blipCntr = 0; blipCntr < blips.Length; blipCntr++)
            {
                if (_ignoreTokens.Contains(blips[blipCntr].Token))
                {
                    continue;
                }

                // Ask the selecter if this is selected
                ObjectRenderer.DrawMode drawMode = ObjectRenderer.DrawMode.Standard;
                if (_selector.IsSelected(blips[blipCntr].Token))
                {
                    drawMode = ObjectRenderer.DrawMode.Selected;
                }

                // See if it should be displayed as standard
                CollisionStyle collisionStyle = blips[blipCntr].CollisionStyle;
                if (_selector.TempStationaryObjects.Contains(blips[blipCntr].Token))
                {
                    collisionStyle = CollisionStyle.Standard;
                }

                // Draw the blip
                if (blips[blipCntr] is Projectile)
                {
                    _renderer.DrawProjectile((Projectile)blips[blipCntr], drawMode, false);
                }
                else if (blips[blipCntr].Sphere is RigidBody)
                {
                    _renderer.DrawRigidBody((RigidBody)blips[blipCntr].Sphere, drawMode, collisionStyle, false);
                }
                else if (blips[blipCntr].Sphere is SolidBall)
                {
                    _renderer.DrawSolidBall((SolidBall)blips[blipCntr].Sphere, drawMode, collisionStyle, false);
                }
                else if (blips[blipCntr].Sphere is Ball)
                {
                    _renderer.DrawBall((Ball)blips[blipCntr].Sphere, drawMode, collisionStyle, false);
                }
                else
                {
                    MessageBox.Show("Unknown blip", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            _shipController.Draw();

            // Let the active adder/selecter have a chance to draw
            if (_ballAdder.Mode != BallAdder.AddingMode.Inactive)
            {
                _ballAdder.Draw();
            }
            else if (_selector.Active)
            {
                _selector.Draw();
            }

            pictureBox1.FinishedDrawing();

            #endregion
        }
Пример #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            const double THRUSTERFORCE = 80;

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

            #region Physics

            _map.PrepareForNewTimerCycle();

            switch (_gravityMode)
            {
            case GravityMode.None:
                break;

            case GravityMode.Down:
                DoGravityDown();
                break;

            case GravityMode.EachOther:
                DoGravityEachOther();
                break;
            }

            if (_ship != null)
            {
                #region Ship Thrusters

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

                if (_isWPressed)
                {
                    timer1_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_TopRight, new MyVector(0, 1, 0), THRUSTERFORCE * 10d);          // down
                    timer1_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_TopLeft, new MyVector(0, 1, 0), THRUSTERFORCE * 10d);           // s
                }

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

                if (_isSPressed)
                {
                    timer1_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_BottomRight, new MyVector(0, -1, 0), THRUSTERFORCE * 10d);              // up
                    timer1_TickSprtApplyThrust(thrustLines, _shipThrusterOffset_BottomLeft, new MyVector(0, -1, 0), THRUSTERFORCE * 10d);               // w
                }

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

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

                #endregion
            }

            DoVectorField();

            Collision[] collisions = _map.Timer(_elapsedTime);

            #endregion

            #region Draw

            // Turn the collision list into a list of tokens
            List <long> collisionTokens = GetCollisionTokens(collisions);

            pictureBox1.PrepareForNewDraw();

            #region Vector Field

            if (_vectorField.FieldMode != VectorField2DMode.None)
            {
                List <MyVector[]> drawLines, fieldLines;
                _vectorField.GetDrawLines(out drawLines, out fieldLines);

                foreach (MyVector[] drawLine in drawLines)
                {
                    pictureBox1.DrawLine(Color.DimGray, 1, drawLine[0], drawLine[1]);
                }

                foreach (MyVector[] fieldLine in fieldLines)
                {
                    pictureBox1.DrawArrow(Color.Chartreuse, 1, fieldLine[0], fieldLine[0] + fieldLine[1]);
                }
            }

            #endregion

            RadarBlip[] blips = _map.GetAllBlips();

            Brush brushBall       = new SolidBrush(Color.FromArgb(160, Color.Gold));
            Brush brushTorqueBall = new SolidBrush(Color.FromArgb(160, Color.RoyalBlue));
            Brush brushRed        = new SolidBrush(Color.FromArgb(160, Color.Tomato));

            Brush curBrush;

            for (int blipCntr = 0; blipCntr < blips.Length; blipCntr++)
            {
                if (blips[blipCntr].Sphere is RigidBody)
                {
                    #region Draw Rigid Body

                    DrawRigidBody(blips[blipCntr].Sphere as RigidBody, Color.MediumSlateBlue, Color.White, _drawCollisionsRed && collisionTokens.Contains(blips[blipCntr].Token));

                    #endregion
                }
                else if (_ship != null && blips[blipCntr].Token == _ship.Token)
                {
                    DrawShip(thrustLines);
                }
                else
                {
                    #region Draw Ball

                    bool isSolidBall = blips[blipCntr].Sphere is SolidBall;

                    // Fill the circle
                    if (_drawCollisionsRed && collisionTokens.Contains(blips[blipCntr].Token))
                    {
                        curBrush = brushRed;
                    }
                    else if (isSolidBall)
                    {
                        curBrush = brushTorqueBall;
                    }
                    else
                    {
                        curBrush = brushBall;
                    }

                    pictureBox1.FillCircle(curBrush, blips[blipCntr].Sphere.Position, blips[blipCntr].Sphere.Radius);

                    // Draw direction facing
                    if (isSolidBall)
                    {
                        MyVector dirFacing = blips[blipCntr].Sphere.DirectionFacing.Standard.Clone();
                        dirFacing.BecomeUnitVector();
                        dirFacing.Multiply(blips[blipCntr].Sphere.Radius);
                        dirFacing.Add(blips[blipCntr].Sphere.Position);

                        pictureBox1.DrawLine(Color.White, 2, blips[blipCntr].Sphere.Position, dirFacing);
                    }

                    // Draw an edge
                    pictureBox1.DrawCircle(Color.Black, 1d, blips[blipCntr].Sphere.Position, blips[blipCntr].Sphere.Radius);

                    #endregion
                }
            }

            brushBall.Dispose();
            brushTorqueBall.Dispose();
            brushRed.Dispose();

            pictureBox1.FinishedDrawing();

            #endregion
        }