示例#1
0
        public override void Move(CVGameTime gameTime)
        {
            if (_reloadTimeRemaining > 0)
            {
                _reloadTimeRemaining -= gameTime.ElapsedGameTime.TotalMilliseconds;

                if (_reloadTimeRemaining <= 0)
                {
                    _shotsRemaining = 3;
                }
            }
            if (_reloadTimeRemaining <= 0)
            {
                if (_shotsRemaining > 0)
                {
                    var elapsedTime = gameTime.ElapsedGameTime.TotalMilliseconds;

                    if (_recoilTimeRemaining > 0)
                    {
                        _recoilTimeRemaining -= elapsedTime;
                        if (_recoilTimeRemaining < 0)
                        {
                            _recoilTimeRemaining    = 0;
                            _recoveryTimeRemaining += _recoilTimeRemaining;
                            elapsedTime             = _recoilTimeRemaining * -1; // keep the difference to carry into recovery time to be decreased
                        }
                        else
                        {
                            elapsedTime = 0f;
                        }
                    }
                    if (_recoveryTimeRemaining > 0)
                    {
                        _recoveryTimeRemaining -= elapsedTime;
                    }

                    if (_recoilTimeRemaining <= 0 && _recoveryTimeRemaining <= 0)
                    {
                        // target
                        Player nearestPlayer = (Player)TargetingLogic.FindNearest(this.BoundingBox().Center.ToVector(), CurrentStage.Players);

                        // aim
                        this.direction    = nearestPlayer.WorldPosition.X < this.WorldPosition.X ? Player.PlayerDirection.Left : Player.PlayerDirection.Right;
                        _targetClockAngle = TargetingLogic.FindClockPosition(this.BoundingBox().Center.ToVector(), nearestPlayer.WorldPosition);

                        // fire
                        _gun.AddProjectile(this.CurrentStage, GunBarrelLocation(), _targetClockAngle * 30, 1.2f);
                        _shotsRemaining--;

                        _recoilTimeRemaining   = _recoilTime;
                        _recoveryTimeRemaining = _recoveryTime;
                    }
                }
                else
                {
                    // out of shots, time to reload
                    _reloadTimeRemaining = _reloadTime;
                }
            }
        }
示例#2
0
        public override void Move(CVGameTime gameTime)
        {
            if (_emergeStatus == 0 && SpawnConditionsMet())
            {
                _emergeStatus        = 1;
                _emergeTimeRemaining = _emergeTime;
            }
            else if (_emergeStatus == 1 || _emergeStatus == 2)
            {
                if (_emergeTimeRemaining > 0)
                {
                    _emergeTimeRemaining -= gameTime.ElapsedGameTime.Milliseconds;
                    if (_emergeTimeRemaining <= 0)
                    {
                        _emergeStatus++;
                        _emergeTimeRemaining = _emergeTime + Math.Abs(_emergeTimeRemaining);
                    }
                }
            }
            else if (_emergeStatus == 3)
            {
                if (_reloadTimeRemaining > 0)
                {
                    _reloadTimeRemaining -= gameTime.ElapsedGameTime.TotalMilliseconds;

                    if (_reloadTimeRemaining <= 0)
                    {
                        _shotsRemaining = 3;
                    }
                }
                if (_reloadTimeRemaining <= 0)
                {
                    if (_shotsRemaining > 0)
                    {
                        var elapsedTime = gameTime.ElapsedGameTime.TotalMilliseconds;

                        //if (_recoilTimeRemaining > 0)
                        //{
                        //    _recoilTimeRemaining -= elapsedTime;
                        //    if (_recoilTimeRemaining < 0)
                        //    {
                        //        _recoilTimeRemaining = 0;
                        //        _recoveryTimeRemaining += _recoilTimeRemaining;
                        //        elapsedTime = _recoilTimeRemaining * -1; // keep the difference to carry into recovery time to be decreased
                        //    }
                        //    else
                        //    {
                        //        elapsedTime = 0f;
                        //    }
                        //}
                        if (_recoveryTimeRemaining > 0)
                        {
                            _recoveryTimeRemaining -= elapsedTime;
                        }

                        if (//_recoilTimeRemaining <= 0 &&
                            _recoveryTimeRemaining <= 0)
                        {
                            // target
                            Player nearestPlayer = (Player)TargetingLogic.FindNearest(this.BoundingBox().Center.ToVector(), CurrentStage.Players);

                            // aim
                            _targetClockAngle = TargetingLogic.FindClockPosition(this.BoundingBox().Center.ToVector(), nearestPlayer.BoundingBox().Center.ToVector());

                            if (_targetClockAngle >= 9 && _targetClockAngle <= 11)
                            {
                                // fire
                                _gun.AddProjectile(this.CurrentStage, GunBarrelLocation(), _targetClockAngle * 30, 1.2f);
                                _shotsRemaining--;
                            }

                            _recoveryTimeRemaining = _recoveryTime;
                        }
                    }
                    else
                    {
                        // out of shots, time to reload
                        _reloadTimeRemaining = _reloadTime;
                    }
                }
            }
        }
示例#3
0
        public override void Move(CVGameTime gameTime)
        {
            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            TimeSinceLastMove += elapsedTime;

            // do nothing
            Player nearestPlayer = (Player)TargetingLogic.FindNearest(this.WorldPosition, CurrentStage.Players);

            AngleBetweenTurretAndPlayer = TargetingLogic.FindClockPosition(this.WorldPosition, nearestPlayer.BoundingBox().Center.ToVector());

            if (AngleBetweenTurretAndPlayer != _currentPosition)
            {
                if (TimeSinceLastMove > TurretMoveDelay)
                {
                    //TimeSinceLastMove -= TurretMoveDelay;
                    TimeSinceLastMove = 0;

                    //float currentTurretAngle = iCurrentPosition * 30;
                    int iCounterDistance = 0;
                    if (_currentPosition < AngleBetweenTurretAndPlayer)
                    {
                        iCounterDistance = 12 - (int)AngleBetweenTurretAndPlayer + _currentPosition;
                    }
                    else
                    {
                        iCounterDistance = _currentPosition - (int)AngleBetweenTurretAndPlayer;
                    }

                    if (iCounterDistance < 6)
                    {
                        TurretTurnDirection = TurretDirection.CounterClockWise;
                    }
                    else
                    {
                        TurretTurnDirection = TurretDirection.Clockwise;
                    }

                    _currentPosition += (int)TurretTurnDirection;
                    if (_currentPosition == 12)
                    {
                        _currentPosition = 0;
                    }
                    else if (_currentPosition == -1)
                    {
                        _currentPosition = 11;
                    }
                }
            }
            else
            {
                TurretTurnDirection = TurretDirection.TargetFound;
                TimeTargetLocked   += elapsedTime;
                if (TimeTargetLocked > TurretFireDelay)
                {
                    TimeTargetLocked = 0.0f;
                    _gun.AddProjectile(this.CurrentStage, GunBarrelLocation(), _currentPosition * 30, 2f);
                }
            }

            //float f = AngleBetweenTurretAndPlayer - currentTurretAngle;

            //currentTurretDirection = (TurretDirection) Math.Sign(-f % 360 - f % 360);
        }