Пример #1
0
        private void chkIncludeShip_CheckedChanged(object sender, EventArgs e)
        {
            const double THRUSTERANGLE = 75;

            if (chkIncludeShip.Checked)
            {
                if (_ship == null)
                {
                    #region Create Ship

                    // Set up the ship
                    double    radius = MINRADIUSMASS + (_rand.NextDouble() * (MAXRADIUSMASS - MINRADIUSMASS));
                    SolidBall ship   = new SolidBall(Utility3D.GetRandomVector(_boundryLower, _boundryUpper), new DoubleVector(0, 1, 0, 1, 0, 0), radius, GetMass(radius), GetElasticity(), 1, 1, _boundryLower, _boundryUpper);

                    // Set up the thrusters
                    MyVector thrusterSeed = new MyVector(0, ship.Radius, 0);
                    MyVector zAxis        = new MyVector(0, 0, 1);

                    // Bottom Thrusters
                    _shipThrusterOffset_BottomRight = thrusterSeed.Clone();
                    _shipThrusterOffset_BottomRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(THRUSTERANGLE * -1));

                    _shipThrusterOffset_BottomLeft = thrusterSeed.Clone();
                    _shipThrusterOffset_BottomLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(THRUSTERANGLE));

                    // Top Thrusters
                    thrusterSeed = new MyVector(0, ship.Radius * -1, 0);
                    _shipThrusterOffset_TopRight = thrusterSeed.Clone();
                    _shipThrusterOffset_TopRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(THRUSTERANGLE));

                    _shipThrusterOffset_TopLeft = thrusterSeed.Clone();
                    _shipThrusterOffset_TopLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(THRUSTERANGLE * -1));

                    // Add to the map
                    _ship = new BallBlip(ship, CollisionStyle.Standard, RadarBlipQual.BallUserDefined03, TokenGenerator.NextToken());
                    _map.Add(_ship);

                    #endregion
                }
            }
            else
            {
                if (_ship != null)
                {
                    _map.Remove(_ship.Token);
                    _ship = null;
                }
            }
        }
Пример #2
0
        private void Exploding()
        {
            // Keep setting my velocity back to zero
            base.Ball.Velocity.StoreNewValues(new MyVector());

            // See if enough time has gone by
            bool isExpired = false;

            if (_explosion == null)
            {
                isExpired = true;
            }
            else
            {
                // Bump up my elapsed time
                _explosion.ElapsedTime += _curTickElapsedTime;

                if (_explosion.ElapsedTime > _explosion.Duration)
                {
                    isExpired = true;
                }
            }

            if (isExpired)
            {
                // Let myself know that I am in the process of dying
                _state = ProjectileState.Dying;

                // Tell the map to drop me, and drop reference to the map.
                _map.Remove(this.Token);
                _map.Collisions -= new CollisionsDelegate(Map_Collisions);
                _map             = null;
            }
        }
Пример #3
0
        public void CanAddAndRemove()
        {
            var sourceNode = new Node(Utils.Id("foo"));
            var simpleMap  = new SimpleMap <NodeID, NodeID>();

            simpleMap.Init(sourceNode, db);
            for (int i = 0; i < 100; i++)
            {
                simpleMap.Add(Utils.Id($"foo/{i}"), Utils.Id("bar"));
            }
            for (int i = 0; i < 100; i += 2)
            {
                simpleMap.Remove(Utils.Id($"foo/{i}"));
            }
            for (int i = 0; i < 100; i++)
            {
                if (i % 2 == 1)
                {
                    Assert.Contains(Utils.Id($"foo/{i}"), simpleMap);
                }
                else
                {
                    Assert.DoesNotContain(Utils.Id($"foo/{i}"), simpleMap);
                }
            }
        }
Пример #4
0
        void picturebox_KeyDown(object sender, KeyEventArgs e)
        {
            if (!_active)
            {
                return;
            }

            // NOTE:  This event fires A LOT while the key is being held down, so don't do anything expensive

            if (e.Shift)
            {
                _isShiftPressed = true;
            }

            if (e.Control)
            {
                _isCtrlPressed = true;
            }

            if ((e.KeyCode == Keys.C && e.Control) || (e.KeyCode == Keys.Insert && e.Control))
            {
                Copy();
            }
            else if ((e.KeyCode == Keys.V && e.Control) || (e.KeyCode == Keys.Insert && e.Shift))
            {
                Paste();
            }
            if ((e.KeyCode == Keys.X && e.Control) || (e.KeyCode == Keys.Delete && e.Shift))
            {
                Copy();
                foreach (long token in _selectedObjects)
                {
                    if (_cantDeleteTokens.Contains(token))
                    {
                        continue;
                    }

                    _map.Remove(token);
                }
            }
        }
Пример #5
0
        private void InsureBlipAddedRemoved(bool added)
        {
            if (added)// && !_cursorInMap)			// I can't trust that (they may have cleared all blips outside of this class
            {
                foreach (RadarBlip blip in _map.GetAllBlips())
                {
                    if (blip.Token == _cursorBlip.Token)
                    {
                        return;
                    }
                }

                // It's not in
                _map.Add(_cursorBlip);
                _cursorInMap = true;
            }
            else if (!added && _cursorInMap)
            {
                // Take it out
                _map.Remove(_cursorBlip.Token);
                _cursorInMap = false;
            }
        }
Пример #6
0
        private void PropsChangedSprtNew()
        {
            MyVector position = null;

            // Kill Existing
            if (_ship != null)
            {
                position = _ship.Ball.Position.Clone();
                _map.Remove(_ship.Token);
                _ship = null;
            }
            else
            {
                position = Utility3D.GetRandomVector(_boundryLower, _boundryUpper);
            }

            _tractorBeams.Clear();
            _cannon = null;
            _machineGuns.Clear();

            #region New Ship

            //TODO:  Listen to global props
            double elasticity      = .75d;
            double kineticFriction = .75d;
            double staticFriction  = 1d;

            // Build New
            Ball          newBall;
            RadarBlipQual blipQual;        // logic came from BallAdder.CommitObject

            switch (_type)
            {
            case ShipTypeQual.None:
                return;

            case ShipTypeQual.Ball:
                #region Ball

                newBall = new Ball(position, new DoubleVector(0, 1, 0, 1, 0, 0), _shipSize, UtilityCore.GetMassForRadius(_shipSize, 1d), elasticity, kineticFriction, staticFriction, _boundryLower, _boundryUpper);

                blipQual = RadarBlipQual.BallUserDefined00;

                _thrustForce = GetThrustForce(newBall.Mass);
                _torqueballLeftRightThrusterForce = _thrustForce;

                #endregion
                break;

            case ShipTypeQual.SolidBall:
                #region Solid Ball

                newBall = new SolidBall(position, new DoubleVector(0, 1, 0, 1, 0, 0), _shipSize, UtilityCore.GetMassForRadius(_shipSize, 1d), elasticity, kineticFriction, staticFriction, _boundryLower, _boundryUpper);

                blipQual = RadarBlipQual.BallUserDefined01;

                _thrustForce = GetThrustForce(newBall.Mass);
                _torqueballLeftRightThrusterForce = GetLeftRightThrusterMagnitude(((SolidBall)newBall).InertialTensorBody);

                #endregion
                break;

            default:
                throw new ApplicationException("Unknown ShipTypeQual: " + _type.ToString());
            }

            newBall.RotateAroundAxis(new MyVector(0, 0, 1), Math.PI);

            // Finish Building
            _ship = new BallBlip(newBall, CollisionStyle.Standard, blipQual, _blipToken);
            _map.Add(_ship);

            #endregion

            if (this.CreateNewTractorBeams != null)
            {
                this.CreateNewTractorBeams(this, new EventArgs());
            }

            #region Guns

            _cannon = new ProjectileWeapon(300, 150, UtilityCore.GetMassForRadius(150, 1d), 25, true, _ignoreOtherProjectiles, RadarBlipQual.Projectile, false, _map, _boundryLower, _boundryUpper);
            _cannon.AddBarrel(_ship.Ball.OriginalDirectionFacing.Standard.Clone());
            _cannon.AddFiringMode(20);
            _cannon.SetProjectileExplosion(450, 2, 10000);
            _cannon.SeProjectileFuse(500);
            _cannon.SetShip(_ship);

            for (int cntr = 0; cntr < 2; cntr++)
            {
                ProjectileWeapon weapon = new ProjectileWeapon(30, 20, UtilityCore.GetMassForRadius(20, 1d), 100, true, _ignoreOtherProjectiles, RadarBlipQual.Projectile, false, _map, _boundryLower, _boundryUpper);
                weapon.AddBarrel(new MyVector(), new MyQuaternion());
                weapon.AddFiringMode(2);
                weapon.SetProjectileExplosion(40, 2, 300);
                weapon.SeProjectileFuse(500);
                weapon.SetShip(_ship);

                _machineGuns.Add(weapon);
            }

            #endregion
        }
Пример #7
0
        // Keyboard
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            /*
             * if (keyData == Keys.Up)
             * {
             *  _isUpPressed = true;
             * }
             * if (keyData == Keys.Down)
             * {
             *  _isDownPressed = true;
             * }
             * if (keyData == Keys.Left)
             * {
             *  _isLeftPressed = true;
             * }
             * if (keyData == Keys.Right)
             * {
             *  _isRightPressed = true;
             * }
             * if (keyData == Keys.W)
             * {
             *  _isWPressed = true;
             * }
             * if (keyData == Keys.S)
             * {
             *  _isSPressed = true;
             * }
             */

            if (keyData == Keys.Delete)
            {
                foreach (long selectedToken in _selector.SelectedObjects)
                {
                    if (_ignoreTokens.Contains(selectedToken))
                    {
                        continue;
                    }

                    _map.Remove(selectedToken);
                }
            }

            if (keyData == Keys.Space)
            {
                btnStopVelocity_Click(this, new EventArgs());
            }

            if (keyData == Keys.F5)
            {
                scenes1.LoadCurrentScene();
            }
            if (keyData == Keys.F6)
            {
                scenes1.SaveCurrentScene();
            }

            if (keyData == Keys.P)
            {
                btnRunning.Checked = !btnRunning.Checked;
                btnRunning_Click(this, new EventArgs());
            }

            return(base.ProcessCmdKey(ref msg, keyData));
            //return true;
        }