private void setPosition(Vector2 blackHolePosition, int levelWidth, int levelHeight)
        {   //set bounds on new spawn location
            int minX, maxX, minY, maxY;

            //spawn in bounds -- default for burst wave
            minX = 0;
            maxX = levelWidth;
            minY = 0;
            maxY = levelHeight;

            if (_isTrickleWave)     //spawn out of bounds
            {
                switch (XnaHelper.RandomInt(0, 3))
                {
                case 0:         //top
                    minX = -OUT_OF_BOUNDS_SPAWN_BUFFER;
                    maxX = levelWidth + OUT_OF_BOUNDS_SPAWN_BUFFER;
                    minY = -OUT_OF_BOUNDS_SPAWN_BUFFER;
                    maxY = 0;
                    break;

                case 1:         //right
                    minX = levelWidth;
                    maxX = levelWidth + OUT_OF_BOUNDS_SPAWN_BUFFER;
                    minY = -OUT_OF_BOUNDS_SPAWN_BUFFER;
                    maxY = levelHeight + OUT_OF_BOUNDS_SPAWN_BUFFER;
                    break;

                case 2:         //bottom
                    minX = -OUT_OF_BOUNDS_SPAWN_BUFFER;
                    maxX = levelWidth + OUT_OF_BOUNDS_SPAWN_BUFFER;
                    minY = levelHeight;
                    maxY = levelHeight + OUT_OF_BOUNDS_SPAWN_BUFFER;
                    break;

                case 3:         //left
                    minX = -OUT_OF_BOUNDS_SPAWN_BUFFER;
                    maxX = 0;
                    minY = -OUT_OF_BOUNDS_SPAWN_BUFFER;
                    maxY = levelHeight + OUT_OF_BOUNDS_SPAWN_BUFFER;
                    break;
                }
            }

            XnaHelper.RandomizeVector(ref _spawnLocation, minX, maxX, minY, maxY);

            //if spawned too close to black hole, try again
            if ((_spawnLocation - blackHolePosition).Length() < MIN_BLACKHOLE_SPAWN_DISTANCE)
            {
                setPosition(blackHolePosition, _levelBounds.Width, _levelBounds.Height);
            }
        }
Esempio n. 2
0
        private void setWaypoint(Vector2 blackHolePosition, int levelWidth, int levelHeight)
        {   //set bounds on new spawn location
            int minX, maxX, minY, maxY;

            //spawn in bounds
            minX = 0;
            maxX = levelWidth;
            minY = 0;
            maxY = levelHeight;

            //keep reselecting position until find a position far enough from black hole
            do
            {
                XnaHelper.RandomizeVector(ref _nextWaypoint, minX, maxX, minY, maxY);
            }while (Vector2.Distance(blackHolePosition, _nextWaypoint) < MIN_BLACKHOLE_DISTANCE);
        }
Esempio n. 3
0
        private void setPosition(Vector2 blackHolePosition, int levelWidth, int levelHeight)
        {   //set bounds on new spawn location
            int minX, maxX, minY, maxY;

            //spawn in bounds -- default for burst wave
            minX = 0;
            maxX = levelWidth;
            minY = 0;
            maxY = levelHeight;

            switch (XnaHelper.RandomInt(0, 3))
            {
            case 0:         //top
                minX = -OUT_OF_BOUNDS_SPAWN_BUFFER;
                maxX = levelWidth + OUT_OF_BOUNDS_SPAWN_BUFFER;
                minY = -OUT_OF_BOUNDS_SPAWN_BUFFER;
                maxY = 0;
                break;

            case 1:         //right
                minX = levelWidth;
                maxX = levelWidth + OUT_OF_BOUNDS_SPAWN_BUFFER;
                minY = -OUT_OF_BOUNDS_SPAWN_BUFFER;
                maxY = levelHeight + OUT_OF_BOUNDS_SPAWN_BUFFER;
                break;

            case 2:         //bottom
                minX = -OUT_OF_BOUNDS_SPAWN_BUFFER;
                maxX = levelWidth + OUT_OF_BOUNDS_SPAWN_BUFFER;
                minY = levelHeight;
                maxY = levelHeight + OUT_OF_BOUNDS_SPAWN_BUFFER;
                break;

            case 3:         //left
                minX = -OUT_OF_BOUNDS_SPAWN_BUFFER;
                maxX = 0;
                minY = -OUT_OF_BOUNDS_SPAWN_BUFFER;
                maxY = levelHeight + OUT_OF_BOUNDS_SPAWN_BUFFER;
                break;
            }

            do
            {
                XnaHelper.RandomizeVector(ref _position, minX, maxX, minY, maxY);
            }while (Vector2.Distance(blackHolePosition, _position) < MIN_BLACKHOLE_DISTANCE);
        }
 private void shatter()
 {
     _lifeState = LifeState.Shattered;
     for (int row = 0; row < ICE_DIVISIONS; row++)
     {
         for (int col = 0; col < ICE_DIVISIONS; col++)
         {
             _fragments[row, col].Health     = FRAGMENT_HEALTH * _statusEffects.Cryo / MAX_STAT_EFFECT;
             _fragments[row, col].Position.X = Position.X + (0.5f + _sprite.Width * (float)col / ICE_DIVISIONS);
             _fragments[row, col].Position.Y = Position.Y + (0.5f + _sprite.Height * (float)row / ICE_DIVISIONS);
             XnaHelper.RandomizeVector(ref _fragments[row, col].Velocity, -FRAGMENT_MAX_VELOCITY, FRAGMENT_MAX_VELOCITY,
                                       -FRAGMENT_MAX_VELOCITY, FRAGMENT_MAX_VELOCITY);
             Vector2.Add(ref _fragments[row, col].Velocity, ref _velocity, out _fragments[row, col].Velocity);
             Vector2.Multiply(ref _fragments[row, col].Velocity, FRAGMENT_VELOCITY_FACTOR, out _fragments[row, col].Velocity);
             _fragments[row, col].Angle           = 0f;
             _fragments[row, col].AngularVelocity = XnaHelper.RandomAngle(0.0f, FRAGMENT_MAX_ANGULAR_VELOCITY);
             _fragments[row, col].ScaleFactor     = 1f;
             _fragments[row, col].Active          = true;
         }
     }
 }
        public virtual void Update(GameTime gameTime, Rectangle levelBounds)
        {
            switch (_lifeState)
            {
            case LifeState.Living:
            case LifeState.Ghost:
            {
                if (Panicked)
                {
                    _panicTimer -= gameTime.ElapsedGameTime;
                    if (_panicTimer <= TimeSpan.Zero)
                    {
                        _panicTimer = TimeSpan.FromSeconds(PANIC_DIRECTION_CHANGE_FREQUENCY);
                        XnaHelper.RandomizeVector(ref _moveDirection, -1, 1, -1, 1);
                        _lookDirection = _moveDirection;
                    }
                }
                lookThisWay(LookDirection);
                if (MoveDirection.Length() > 0)
                {
                    moveThisWay(MoveDirection, gameTime);
                }

                //handle burning
                ApplyDamage(_statusEffects.Fire * (float)gameTime.ElapsedGameTime.TotalSeconds * FIRE_DPS);

                break;
            }

            case LifeState.Disabled:
            case LifeState.Frozen:
            {
                if (_statusEffects.Cryo <= 0)
                {
                    _lifeState = LifeState.Living;
                    //still cold after defrosting
                    _statusEffects.Cryo = MAX_STAT_EFFECT / 2;
                }
                break;
            }

            case LifeState.Shattered:
            {
                for (int y = 0; y < ICE_DIVISIONS; y++)
                {
                    for (int x = 0; x < ICE_DIVISIONS; x++)
                    {
                        _fragments[x, y].Angle       += _fragments[x, y].AngularVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        _fragments[x, y].Position    += _fragments[x, y].Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        _fragments[x, y].Velocity    += _fragments[x, y].Acceleration * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        _fragments[x, y].Acceleration = Vector2.Zero;
                        _fragments[x, y].Health      -= FRAGMENT_MELT_RATE * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        _fragments[x, y].ScaleFactor  = _fragments[x, y].Health / FRAGMENT_HEALTH * FRAGMENT_SCALE_FACTOR;
                        XnaHelper.ClampVector(ref _fragments[x, y].Velocity, FRAGMENT_MAX_VELOCITY, out _fragments[x, y].Velocity);
                        if (_fragments[x, y].BeingEaten)
                        {
                            _fragments[x, y].Health -= FRAGMENT_EAT_RATE * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        }
                    }
                }
                return;
            }

            case LifeState.BeingEaten:
            {
                _sprite.ScaleFactor -= BLACK_HOLE_EAT_SCALE_FACTOR * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (_sprite.ScaleFactor <= 0)
                {
                    _lifeState = LifeState.Destroyed;
                }
                break;
            }

            case LifeState.Destroyed:
            default:
            {
                return;             //don't update anything
            }
            }

            stayInBounds(levelBounds.Width, levelBounds.Height);
            _velocity += _acceleration * (float)gameTime.ElapsedGameTime.TotalSeconds;
            Position  += _velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            controlVelocity(_maxSpeed, gameTime.ElapsedGameTime);
            _sprite.Angle += _angularVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;

            LookDirection = Vector2.Zero;
            MoveDirection = Vector2.Zero;
            _acceleration = Vector2.Zero;

            if (_movementParticleEffect != null)
            {
                _movementParticleEffect.Update(gameTime);
            }

            //burning visual effect
            _burningParticleEffect.Spawn(Position, 0.0f, gameTime.ElapsedGameTime, _velocity);
            _burningParticleEffect.IntensityFactor = _statusEffects.Fire / MAX_STAT_EFFECT;
            _burningParticleEffect.Update(gameTime);

            //cryo visual effect
            if (_statusEffects.Cryo > 0 && _lifeState != LifeState.Disabled)
            {
                _sprite.Shade = Color.Lerp(Color.White, Color.Blue, _statusEffects.Cryo / MAX_STAT_EFFECT);
            }

            _hitRect.X = (int)Position.X - _hitRect.Width / 2;
            _hitRect.Y = (int)Position.Y - _hitRect.Height / 2;

            //manage stat effects
            if (_statusEffects.Cryo >= MAX_STAT_EFFECT && _lifeState != LifeState.Frozen)
            {
                _lifeState          = LifeState.Frozen;
                _iceIntegrity       = maxHealth * ICE_INTEGRITY_FACTOR;
                _statusEffects.Fire = 0;    //stop burning if frozen
            }

            //decrement every stat effect based on status resist
            _statusEffects -= _statusResist * (float)gameTime.ElapsedGameTime.TotalSeconds;
            _statusEffects.Clamp(0, MAX_STAT_EFFECT);

            _sprite.Update(gameTime);
        }