/// <summary>
 /// Move the sprite in the given direction based on its moveForce property
 /// </summary>
 /// <param name="direction">Direction to move. Should be normalized for normal movement.</param>
 private void moveThisWay(Vector2 direction, GameTime gameTime)
 {
     //apply movement force, taking into account cryo effect (which slows)
     ApplyForce(_moveForce * direction * (1 - _statusEffects.Cryo / MAX_STAT_EFFECT));
     if (_movementParticleEffect != null)
     {
         _movementParticleEffect.Spawn(Center, XnaHelper.DegreesFromVector(-direction), gameTime.ElapsedGameTime, _velocity);
     }
 }
        protected override void UpdateWeapon(GameTime gameTime)
        {
            if (_firing)
            {
                _attackParticleEffect.Spawn(_owner.Center, XnaHelper.DegreesFromVector(_fireDirection),
                                            gameTime.ElapsedGameTime, _owner.Velocity);
                //recoil
                _owner.ApplyImpact(-_recoil * _fireDirection, 1);
            }

            _attackParticleEffect.Update(gameTime);
        }
예제 #3
0
        protected override void UpdateWeapon(GameTime gameTime)
        {
            _contactEffect.Update(gameTime);
            _destinationEffect.Update(gameTime);
            _proximityEffect.Update(gameTime);

            int projectilesToSpawn = _firing ? _projectilesPerFire : 0;

            foreach (Projectile p in _projectiles)
            {
                if (p.ProjectileState == Projectile.State.Dormant &&
                    projectilesToSpawn > 0)
                {
                    float rotAngle = XnaHelper.RandomAngle(0, _spread);
                    Matrix.CreateRotationZ(MathHelper.ToRadians(rotAngle), out tempMatrix);
                    p.Initialize(_owner.Position, Vector2.Transform(_fireDirection, tempMatrix),
                                 _projectileInfo, _targetDestination, _owner.Velocity,
                                 _contactEffect, _destinationEffect,
                                 _proximityEffect);
                    projectilesToSpawn--;
                }

                p.Update(gameTime);
            }

            System.Diagnostics.Debug.Assert(projectilesToSpawn == 0, "did not spawn all projectiles", "Number left: " + projectilesToSpawn,
                                            new object[] { this });

            if (_fireParticleEffect != null)
            {
                if (_firing)
                {
                    _fireParticleEffect.Spawn(
                        _owner.Position, XnaHelper.DegreesFromVector(_fireDirection),
                        gameTime.ElapsedGameTime, _owner.Velocity);
                }
                _fireParticleEffect.Update(gameTime);
            }
        }
예제 #4
0
        public void Update(GameTime gameTime, Rectangle levelBounds, Vector2 blackHolePos, Vector2 targetPos, Rectangle playerRect)
        {
            _standingEffect.Update(gameTime);
            _chargeEffect.Update(gameTime);
            _explodeEffect.Update(gameTime);
            _sprite.Update(gameTime);

            switch (_state)
            {
            case State.Dormant:
                if (SpawnEnable)
                {
                    _timer -= gameTime.ElapsedGameTime;
                }

                if (_timer <= TimeSpan.Zero)
                {
                    setPosition(blackHolePos, targetPos, levelBounds.Width, levelBounds.Height);
                    _gravity.Position = _position;
                    _state            = State.Appearing;
                    _timer            = TimeSpan.FromSeconds(APPEAR_TIME);
                }
                break;

            case State.Appearing:
                _timer -= gameTime.ElapsedGameTime;
                if (_timer <= TimeSpan.Zero)
                {
                    _timer        = TimeSpan.FromSeconds(MAX_SCAN_TIME);
                    _lockOnTimer  = TimeSpan.FromSeconds(LOCK_ON_TIME);
                    _state        = State.Scanning;
                    _sprite.Shade = Color.White;
                }
                else
                {
                    _standingEffect.Spawn(_position, XnaHelper.DegreesFromVector(_direction), gameTime.ElapsedGameTime, Vector2.Zero);
                    _sprite.Shade = Color.Lerp(Color.Transparent, Color.White,
                                               (APPEAR_TIME - (float)_timer.TotalSeconds) / APPEAR_TIME);
                }
                break;

            case State.Scanning:
                _timer -= gameTime.ElapsedGameTime;
                _standingEffect.Spawn(_position, XnaHelper.DegreesFromVector(_direction), gameTime.ElapsedGameTime, Vector2.Zero);
                _position.Y += scanVelocity(targetPos.Y - _position.Y) * (float)gameTime.ElapsedGameTime.TotalSeconds;
                _hitRect.Y   = (int)_position.Y - _hitRect.Height / 2;
                //scan for player
                //check if player found or scan time up
                if (_hitRect.Top < targetPos.Y && targetPos.Y < _hitRect.Bottom)
                {
                    _lockOnTimer -= gameTime.ElapsedGameTime;
                }
                if (_lockOnTimer < TimeSpan.Zero || _timer < TimeSpan.Zero)
                {
                    _timer     = TimeSpan.FromSeconds(CHARGE_TIME);
                    _state     = State.Locked;
                    _direction = _sprite.FlipH ? -Vector2.UnitX : Vector2.UnitX;
                }
                break;

            case State.Locked:
                _timer -= gameTime.ElapsedGameTime;
                if (_timer < TimeSpan.Zero)
                {
                    _state = State.Charging;
                    Vector2.Multiply(ref _direction, MOVE_SPEED, out _velocity);
                }
                break;

            case State.Charging:
                //trace movement path
                for (int i = 0; i < PARTICLE_SPAWN_GRANULARITY; i++)
                {
                    _position.X += _velocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds / PARTICLE_SPAWN_GRANULARITY;
                    float angle = (_sprite.FlipH) ? 90 : -90;
                    _chargeEffect.Spawn(_position, angle, gameTime.ElapsedGameTime, Vector2.Zero);
                }
                _hitRect.X = (int)_position.X - _hitRect.Width;

                _gravity.Position = _position;
                if (outOfBounds(levelBounds.Width, levelBounds.Height))
                {
                    _sprite.Reset();
                    _timer = _spawnTime;
                    _state = State.Dormant;
                }
                break;

            case State.BeingEaten:
                _timer -= gameTime.ElapsedGameTime;
                //_explodeEffect.Spawn(_position, 0.0f, gameTime.ElapsedGameTime, Vector2.Zero);
                if (_timer <= TimeSpan.Zero)
                {
                    _state = State.Dormant;
                    _timer = _spawnTime;
                }
                break;
            }
        }