예제 #1
0
        public void Update(LD44Game game, Level level, float delta)
        {
            PlayerMob playerMob = level.Mobs.OfType <PlayerMob>().First();

            if (Vector2.Distance(playerMob.Body.Position, Body.Position) < 7f)
            {
                if (playerMob.Body.Position.X > Body.Position.X)
                {
                    Sprite.Effects = SpriteEffects.FlipHorizontally;
                }
                else if (playerMob.Body.Position.X < Body.Position.X)
                {
                    Sprite.Effects = SpriteEffects.None;
                }

                _shootCharger -= delta;
                if (_shootCharger <= 0f)
                {
                    game.Content.Load <SoundEffect>("Sounds/projectile").Play();

                    var projectile = new ProjectileMob {
                        Animation = new AnimationState <Sprite>(game.SpriteAnimations["projectile"], 0.2f)
                        {
                            IsLooping = true
                        }
                    };
                    projectile.Body.Position = Body.Position;
                    projectile.Body.Velocity = Vector2.Normalize(playerMob.Body.Position - Body.Position) * 20f;
                    level.FutureMobs.Add(projectile);

                    _shootCharger = 3f;
                }
            }
        }
예제 #2
0
        public void Update(LD44Game game, Level level, float delta)
        {
            if (_hasTarget)
            {
                _timer += delta;
                if (_timer > _speed)
                {
                    _timer = _speed;
                }

                float p = _timer / _speed;
                p = 1f - (float)Math.Pow(1f - p, _smoothing);

                Body.Position = _startPosition * (1f - p) + _targetPosition * p - new Vector2(0f, _arc * (float)Math.Sin(p * (float)Math.PI));
            }

            switch (_state)
            {
            case State.None: {
                _thinkTimer -= delta;

                if (_thinkTimer <= 0f)
                {
                    int action = _random.Next(3);

                    if (action == _lastAction)
                    {
                        action--;
                        if (action < 0)
                        {
                            action = 2;
                        }
                    }

                    _lastAction = action;

                    switch (action)
                    {
                    case 0: {
                        if (_random.Next(2) == 0)
                        {
                            _state = State.PreparingToChargeLeft;

                            _hasTarget      = true;
                            _startPosition  = Body.Position;
                            _targetPosition = new Vector2(25.5f, 15.5f);
                            _timer          = 0f;
                            _speed          = 2f;
                            _arc            = 2f;
                            _smoothing      = 3f;

                            _chargeNum = 0;
                        }
                        else
                        {
                            _state = State.PreparingToChargeRight;

                            _hasTarget      = true;
                            _startPosition  = Body.Position;
                            _targetPosition = new Vector2(6.5f, 15.5f);
                            _timer          = 0f;
                            _speed          = 2f;
                            _arc            = 2f;
                            _smoothing      = 3f;

                            _chargeNum = 0;
                            break;
                        }
                        break;
                    }

                    case 1: {
                        _state = State.Summoning;

                        _hasTarget      = true;
                        _startPosition  = Body.Position;
                        _targetPosition = new Vector2(12f + 8f * (float)_random.NextDouble(), 13.5f);
                        _timer          = 0f;
                        _speed          = 2f;
                        _arc            = 1f;
                        _smoothing      = 2f;
                        break;
                    }

                    case 2: {
                        _state = State.PreparingToShoot;

                        _hasTarget      = true;
                        _startPosition  = Body.Position;
                        _targetPosition = new Vector2(12f + 8f * (float)_random.NextDouble(), 9.5f);
                        _timer          = 0f;
                        _speed          = 2f;
                        _arc            = 2f;
                        _smoothing      = 3f;
                        break;
                    }
                    }
                }
                break;
            }

            case State.PreparingToChargeLeft: {
                if (_timer >= _speed)
                {
                    _startPosition  = Body.Position;
                    _targetPosition = new Vector2(5.5f, 15.5f);
                    _timer          = 0f;
                    _speed          = 1.75f - _chargeNum / 7f;
                    _state          = State.ChargingLeft;
                    _arc            = 0f;
                    _smoothing      = 1.5f;

                    game.Content.Load <SoundEffect>("Sounds/dash").Play();
                }
                break;
            }

            case State.PreparingToChargeRight: {
                if (_timer >= _speed)
                {
                    _startPosition  = Body.Position;
                    _targetPosition = new Vector2(26.5f, 15.5f);
                    _timer          = 0f;
                    _speed          = 1.75f - _chargeNum / 7f;
                    _state          = State.ChargingRight;
                    _arc            = 0f;
                    _smoothing      = 1.5f;

                    game.Content.Load <SoundEffect>("Sounds/dash").Play();
                }
                break;
            }

            case State.ChargingLeft: {
                if (_timer >= _speed)
                {
                    _chargeNum++;

                    if (_chargeNum < 5)
                    {
                        if (_random.Next(3) == 0)
                        {
                            _startPosition  = Body.Position;
                            _targetPosition = new Vector2(26.5f, 15.5f);
                            _timer          = 0f;
                            _speed          = 1.75f - _chargeNum / 7f;
                            _state          = State.ChargingRight;
                            _arc            = 0f;
                            _smoothing      = 1.5f;

                            game.Content.Load <SoundEffect>("Sounds/dash").Play();
                        }
                        else
                        {
                            _state = State.PreparingToChargeLeft;

                            _hasTarget      = true;
                            _startPosition  = Body.Position;
                            _targetPosition = new Vector2(25.5f, 15.5f);
                            _timer          = 0f;
                            _speed          = 2f - _chargeNum / 5f;
                            _arc            = 2f;
                            _smoothing      = 3f - _chargeNum / 5f;
                        }
                    }
                    else
                    {
                        _state      = State.None;
                        _thinkTimer = 2f;
                    }
                }
                break;
            }

            case State.ChargingRight: {
                if (_timer >= _speed)
                {
                    _chargeNum++;

                    if (_chargeNum < 5)
                    {
                        if (_random.Next(3) == 0)
                        {
                            _startPosition  = Body.Position;
                            _targetPosition = new Vector2(5.5f, 15.5f);
                            _timer          = 0f;
                            _speed          = 1.75f - _chargeNum / 7f;
                            _state          = State.ChargingLeft;
                            _arc            = 0f;
                            _smoothing      = 1.5f;

                            game.Content.Load <SoundEffect>("Sounds/dash").Play();
                        }
                        else
                        {
                            _state = State.PreparingToChargeRight;

                            _hasTarget      = true;
                            _startPosition  = Body.Position;
                            _targetPosition = new Vector2(6.5f, 15.5f);
                            _timer          = 0f;
                            _speed          = 2f - _chargeNum / 5f;
                            _arc            = 2f;
                            _smoothing      = 3f - _chargeNum / 5f;
                        }
                    }
                    else
                    {
                        _state      = State.None;
                        _thinkTimer = 2f;
                    }
                }
                break;
            }

            case State.Summoning: {
                if (_timer > _speed * 3f / 4f)
                {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["valgox_aiming"], 1f);
                }

                if (_timer >= _speed)
                {
                    var bat = new EliteBatMob {
                        Animation = new AnimationState <Sprite>(game.SpriteAnimations["elite_bat_flying"], 0.5f)
                        {
                            IsLooping = true
                        }
                    };
                    bat.Body.Position = new Vector2(6.5f + 19f * (float)_random.NextDouble(), 12f);
                    level.FutureMobs.Add(bat);

                    _state      = State.None;
                    _thinkTimer = 2f;

                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["valgox_idle"], 0.5f)
                    {
                        IsLooping = true
                    };
                }
                break;
            }

            case State.PreparingToShoot: {
                if (_timer >= _speed)
                {
                    _state      = State.Shooting;
                    _shootTimer = 0.5f;
                    _shotNum    = 0;
                }
                break;
            }

            case State.Shooting: {
                _shootTimer -= delta;

                if (_shootTimer < 0.2f)
                {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["valgox_aiming"], 1f);
                }
                else if (Animation.Animation != game.SpriteAnimations["valgox_idle"])
                {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["valgox_idle"], 0.5f)
                    {
                        IsLooping = true
                    };
                }

                if (_shootTimer <= 0f)
                {
                    game.Content.Load <SoundEffect>("Sounds/projectile").Play();

                    PlayerMob playerMob = level.Mobs.OfType <PlayerMob>().First();

                    var projectile = new ProjectileMob {
                        Animation = new AnimationState <Sprite>(game.SpriteAnimations["projectile"], 0.2f)
                        {
                            IsLooping = true
                        }
                    };
                    projectile.Body.Position = Body.Position;
                    projectile.Body.Velocity = Vector2.Normalize(playerMob.Body.Position - Body.Position) * 20f;
                    level.FutureMobs.Add(projectile);

                    _shotNum++;
                    _shootTimer += 2f / _shotNum;

                    _hasTarget      = true;
                    _startPosition  = Body.Position;
                    _targetPosition = new Vector2(12f + 8f * (float)_random.NextDouble(), 9f + 3f * (float)_random.NextDouble());
                    _timer          = 0f;
                    _speed          = _shootTimer;
                    _arc            = 0f;
                    _smoothing      = 2f;
                }

                if (_shotNum >= 8)
                {
                    _state      = State.None;
                    _thinkTimer = 2f;

                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["valgox_idle"], 0.5f)
                    {
                        IsLooping = true
                    };
                }
                break;
            }
            }
        }