コード例 #1
0
ファイル: ShipTurret.cs プロジェクト: AlanWills/UnderSiege
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            FindTarget();

            if (Target != null)
            {
                CheckIfDamagedTarget();

                // Rotate to target
                float angle = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(this, Target.WorldPosition);
                if (Math.Abs(angle - WorldRotation) > 0.1f)
                {
                    RigidBody.AngularVelocity = 3.5f * Trigonometry.GetRotateDirectionForShortestRotation(this, Target.WorldPosition);
                }
                else
                {
                    LocalRotation = angle - Parent.WorldRotation;
                    RigidBody.FullAngularStop();
                }
            }

            FiringArc.Visible = MouseOver || IsSelected;
            FiringArc.Update(gameTime);
        }
コード例 #2
0
ファイル: EnemyShip.cs プロジェクト: AlanWills/UnderSiege
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (TargetShip != null)
            {
                // If we are not driven by another ship, we should update the position
                if ((Parent == UnderSiegeGameplayScreen.SceneRoot || Parent == null))
                {
                    float angle = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(this, TargetShip.WorldPosition);
                    if (Math.Abs(angle - WorldRotation) > 0.1f)
                    {
                        RigidBody.AngularVelocity = Trigonometry.GetRotateDirectionForShortestRotation(this, TargetShip.WorldPosition) * TotalThrust * 0.01f / ShipData.Mass;
                    }
                    else
                    {
                        RigidBody.FullAngularStop();
                    }

                    if ((TargetShip.WorldPosition - WorldPosition).LengthSquared() >= minDistance * minDistance)
                    {
                        RigidBody.LinearVelocity = new Vector2(RigidBody.LinearVelocity.X, TotalThrust / ShipData.Mass);
                    }
                    else
                    {
                        RigidBody.FullLinearStop();
                    }
                }
            }
            else
            {
                FindNearestTargetShip();
            }
        }
コード例 #3
0
        public override void Execute(GameTime gameTime)
        {
            base.Execute(gameTime);

            float targetAngle = Trigonometry.GetAngleOfLineBetweenPositionAndTarget(ObjectToRotate.WorldPosition, Position);
            float distance    = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(ObjectToRotate, Position);

            if (distance < 0.005f)
            {
                // ObjectToRotate.WorldRotation = targetAngle;
                Completed = true;
                return;
            }

            float directionToRotate = Trigonometry.GetRotateDirectionForShortestRotation(ObjectToRotate, Position);

            if (!GlobalVariables.SIMPLEPHYSICS)
            {
                float distanceToStartDeccelerating = ObjectToRotate.RigidBody.AngularVelocity * (float)Math.Ceiling(ObjectToRotate.RigidBody.AngularVelocity / acceleration) * 0.5f;
                if (distance > distanceToStartDeccelerating)
                {
                    ObjectToRotate.RigidBody.AngularAcceleration = directionToRotate * Math.Sign(targetAngle - ObjectToRotate.WorldRotation) * acceleration;
                }
                else
                {
                    ObjectToRotate.RigidBody.AngularAcceleration = directionToRotate * Math.Sign(ObjectToRotate.WorldRotation - targetAngle) * acceleration;
                }
            }
            else
            {
                ObjectToRotate.RigidBody.AngularVelocity = directionToRotate * Math.Sign(targetAngle - ObjectToRotate.WorldRotation) * ObjectToRotate.RigidBody.MaxAngularVelocity;
            }
        }
コード例 #4
0
ファイル: Turret.cs プロジェクト: AlanWills/UnderSiege
        protected override void IfSelected()
        {
            base.IfSelected();

            // Here we are changing the orientation of the turret, so it should not fire
            Orientation      = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(this, ScreenManager.GameMouse.InGamePosition);
            LocalRotation    = Orientation;
            currentFireTimer = 0;
        }
コード例 #5
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            currentLifeTimer += gameTime.ElapsedGameTime;
            if (currentLifeTimer >= TimeSpan.FromSeconds(MissileData.BulletLifeTime))
            {
                Die();
            }

            if (RigidBody.LinearVelocity.X < 0)
            {
                RigidBody.LinearAcceleration = new Vector2(500, RigidBody.LinearAcceleration.Y);
            }
            else
            {
                RigidBody.LinearVelocity     = new Vector2(0, RigidBody.LinearVelocity.Y);
                RigidBody.LinearAcceleration = new Vector2(0, RigidBody.LinearAcceleration.Y);
            }

            if (Target != null && Target.Alive)
            {
                float angle = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(this, Target.WorldPosition);
                if (Math.Abs(angle - WorldRotation) > 0.1f)
                {
                    RigidBody.AngularVelocity = 15 * Trigonometry.GetRotateDirectionForShortestRotation(this, Target.WorldPosition);
                }
                else
                {
                    // Bad that we are assuming it is not parented to anything, but I think that is a valid assumption
                    LocalRotation = angle;
                    RigidBody.FullAngularStop();
                }
            }
            else
            {
                RigidBody.FullAngularStop();
            }

            EngineBlaze.Update(gameTime);

            if (Explosion.Animation.IsPlaying)
            {
                Explosion.Update(gameTime);
            }

            if (Explosion.Animation.Finished)
            {
                Alive = false;
            }
        }
コード例 #6
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            Beam.Update(gameTime);

            if (Target != null)
            {
                float angleToTarget = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(this, Target.WorldPosition);
                if (Math.Abs(angleToTarget - WorldRotation) <= 0.1f)
                {
                    Fire();
                }
                else
                {
                    firing = false;

                    firingSoundEffectInstance.Pause();
                }
            }
            else
            {
                firing = false;

                firingSoundEffectInstance.Pause();
            }

            if (firing)
            {
                Beam.Opacity = (float)Math.Min(Beam.Opacity + 0.02f, 1);
            }
            else
            {
                Beam.Opacity = (float)Math.Max(Beam.Opacity - 0.05f, 0);
            }

            TargetingLine.Visible = Opacity == 0 ? true : false;
        }
コード例 #7
0
        public override void Execute(GameTime gameTime)
        {
            base.Execute(gameTime);

            float targetAngle = Trigonometry.GetAngleOfLineBetweenPositionAndTarget(ObjectToRotate.WorldPosition, Target.WorldPosition);
            float distance    = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(ObjectToRotate, Target.WorldPosition);

            // Once we get sufficiently close to our target, we lock on and no longer use physics to drive the rotation
            if (distance < 0.005f || lockedOn)
            {
                lockedOn = true;
                // ObjectToRotate.WorldRotation = targetAngle;
                ObjectToRotate.RigidBody.FullAngularStop();

                return;
            }

            float directionToRotate = Trigonometry.GetRotateDirectionForShortestRotation(ObjectToRotate, Target.WorldPosition);

            if (!GlobalVariables.SIMPLEPHYSICS)
            {
                float distanceToStartDeccelerating = ObjectToRotate.RigidBody.AngularVelocity * (float)Math.Ceiling(ObjectToRotate.RigidBody.AngularVelocity / acceleration) * 0.5f;
                if (distance > distanceToStartDeccelerating)
                {
                    ObjectToRotate.RigidBody.AngularAcceleration = directionToRotate * Math.Sign(targetAngle - ObjectToRotate.WorldRotation) * acceleration;
                }
                else
                {
                    ObjectToRotate.RigidBody.AngularAcceleration = directionToRotate * Math.Sign(ObjectToRotate.WorldRotation - targetAngle) * acceleration;
                }
            }
            else
            {
                ObjectToRotate.RigidBody.AngularVelocity = directionToRotate * Math.Sign(targetAngle - ObjectToRotate.WorldRotation) * ObjectToRotate.RigidBody.MaxAngularVelocity;
            }
        }
コード例 #8
0
 public virtual void Orient()
 {
     // Here we are changing the orientation of the turret, so it should not fire
     LocalOrientation = Trigonometry.GetAngleOfLineBetweenObjectAndTarget(this, ScreenManager.GameMouse.InGamePosition) - Parent.WorldRotation;
     LocalRotation    = LocalOrientation;
 }