Пример #1
0
        public override void Initialize(GameScreen parentScreen)
        {
            base.Initialize(parentScreen);

            // Load the clip. Note that this instance is shared with all
            // entities that want this clip file.
            Clip clip = parentScreen.Content.Load <Clip>(Settings.ClipFile);

            clip.Init(parentScreen.Content);

            // Create the ClipInstance. This allows different entities to
            // share the same clip and play their own animations on it
            ClipInstance = new ClipInstance(clip);
            //ClipInstance.Scale = new Vector2(-1.0f, 1.0f);

            // Set the initial position of the clip instance
            Position = Settings.Position;
            Origin   = Settings.Origin;
            Rotation = MathHelper.ToRadians(Settings.Rotation);
            Scale    = Settings.Scale;
            FlipX    = Settings.FlipX;
            FlipY    = Settings.FlipY;

            if (string.IsNullOrEmpty(Settings.DefaultAnimName))
            {
                ClipInstance.Play(clip.AnimSet.Anims[0], Settings.DefaultAnimLooping);
            }
            else
            {
                ClipInstance.Play(Settings.DefaultAnimName, Settings.DefaultAnimLooping);
            }
            ClipInstance.Update(Settings.DefaultAnimOffset);
        }
Пример #2
0
        float PlayNewEnemyAnimation()
        {
            ClipAnimSet newAnimSet = null;
            AnimKey     key        = new AnimKey(GetAnimState(), _animDirection);

            if (_animations.TryGetValue(key, out newAnimSet))
            {
                if (newAnimSet != currentAnimSet)
                {
                    bool     isLooping = key.State == AnimState.Idle || key.State == AnimState.Run || key.State == AnimState.Attack;
                    ClipAnim newAnim   = newAnimSet.GetNextAnim();
                    if (newAnim == null)
                    {
                        throw new InvalidOperationException("Could not find Enemy animation for " + key.State.ToString() + "-" + key.Direction.ToString());
                    }
                    else
                    {
                        ClipInstance.Play(newAnim, isLooping);
                    }
                    currentAnimSet = newAnimSet;
                }
                return(ClipInstance.CurrentAnim.DurationInSecondsRemaining);
            }
            return(0.0f);
        }
Пример #3
0
        void SwitchToState(UnitState state)
        {
            // cancel any pending transition
            countdownToNextState = 0.0f;
            currentState         = state;
            switch (state)
            {
            case UnitState.Idle:
                ClipInstance.Play("idle", true);
                TransitionToState(UnitState.AttackOrMove, 0.5f);
                break;

            case UnitState.Move:
                ClipInstance.Play("walk", true);
                TransitionToState(UnitState.AttackOrMove, 0.5f);
                break;

            case UnitState.AttackOrMove:
                AttackOrMove();
                break;

            case UnitState.Attack:
            {
                if (IsEnemy)
                {
                    ClipInstance.Play("attack", false);
                }
                else
                if (random.Next(2) == 0)
                {
                    ClipInstance.Play("attackA", false);
                }
                else
                {
                    ClipInstance.Play("attackB", false);
                }

                targetUnit.Hit(this.Damage);
                TransitionToState(UnitState.Idle, ClipInstance.CurrentAnim.DurationInSeconds);
            }
            break;

            case UnitState.Hit:
                //LevelScreen.ParentGame.Audio.Play("enemyhit01");
                ClipInstance.Play("hit", false);
                TransitionToState(UnitState.Idle, ClipInstance.CurrentAnim.DurationInSeconds);
                break;

            case UnitState.Die:
                LevelScreen.ParentGame.Audio.Play("enemydeath01");
                ClipInstance.Play("death", false);
                Deactivate(ClipInstance.CurrentAnim.DurationInSeconds + 3.0f);
                IsAlive = false;
                Physics.Bodies[0].CollidesWith = (Category)SpinelessCollisionCategories.Terrain;
                break;
            }
        }
Пример #4
0
        void PlayNewEnemyAnimation()
        {
            ClipAnim newAnim = null;

            if (_animations.TryGetValue(new AnimKey(CurrentState, _animDirection), out newAnim))
            {
                if (newAnim != ClipInstance.CurrentAnim)
                {
                    ClipInstance.Play(newAnim);
                }
            }
        }
Пример #5
0
        private void PlayNewEggAnimation()
        {
            ClipAnim newAnim = null;

            if (_animations.TryGetValue(CurrentState, out newAnim))
            {
                if (newAnim != ClipInstance.CurrentAnim)
                {
                    ClipInstance.Play(newAnim);
                }
            }
        }
Пример #6
0
        void PlayNewCharacterAnimation()
        {
            ClipAnimSet newAnimSet = null;

            if (_animations.TryGetValue(new AnimKey(CurrentState, CurrentWeapon, _animDirection),
                                        out newAnimSet))
            {
                if (newAnimSet != lastAnimSet)
                {
                    ClipInstance.Play(newAnimSet.GetNextAnim());
                    lastAnimSet = newAnimSet;
                }
            }
        }
Пример #7
0
        public override void Initialize(GameScreen parentScreen)
        {
            base.Initialize(parentScreen);

            AimTexture = new Texture2D(ParentScreen.ParentGame.GraphicsDevice, 1, 1);
            AimTexture.SetData <Color>(new Color[] { Color.White });

            // find fire durations
            ClipInstance.Play(BOMB_FIRE_CLIP_NAME);
            bombReloadTime = ClipInstance.CurrentAnim.DurationInSeconds;
            ClipInstance.Play(BOW_FIRE_CLIP_NAME);
            bowReloadTime = ClipInstance.CurrentAnim.DurationInSeconds;

            // set state and current clip
            state = PrincessState.IdleBow;
            ClipInstance.Play(BOW_IDLE_CLIP_NAME);
        }
Пример #8
0
        private void Fire()
        {
            dragVector = dragStart - dragEnd;
            if (dragVector.Length() > 250f)
            {
                dragVector.Normalize();
                dragVector *= 250f;
            }
            dragVector *= POWER;

            this.LevelScreen.FireProjectile(this.Position + fireOffset, dragVector, 0, currentProjectileType);
            timeSinceLastFired = 0;

            if (currentProjectileType == ProjectileType.Arrow)
            {
                state = PrincessState.FiringBow;
                ClipInstance.Play(BOW_FIRE_CLIP_NAME);
            }
            else
            {
                state = PrincessState.ThrowingBomb;
                ClipInstance.Play(BOMB_FIRE_CLIP_NAME);
            }
        }
Пример #9
0
        public override void Update(float dt)
        {
            timeSinceLastFired += dt;

            if (Input.MouseDown(MouseButton.Left))
            {
                if (!isDragging && timeSinceLastFired > (currentProjectileType == ProjectileType.Arrow ? bowReloadTime : bombReloadTime))
                {
                    if (Vector2.Distance(this.Position - LevelScreen.Camera2D.Position, new Vector2(Input.MouseX, Input.MouseY)) < DRAG_RADIUS)
                    {
                        isDragging = true;
                        dragStart  = new Vector2(Input.MouseX, Input.MouseY);
                    }
                }

                dragEnd      = new Vector2(Input.MouseX, Input.MouseY);
                dragDistance = MathHelper.Clamp(Vector2.Distance(dragStart, dragEnd), 0, MAX_DRAG_DISTANCE);

                // TODO update drag distance sound
                // TODO update drag distance animation

                angle = (float)Math.Atan2(dragStart.Y - dragEnd.Y, dragStart.X - dragEnd.X);
            }
            else if (Input.MouseJustUp(MouseButton.Left) && isDragging)
            {
                isDragging = false;

                if (dragDistance < MIN_DRAG_DISTANCE)
                {
                    // do nothing...
                }
                else
                {
                    Fire();
                }
            }

            float fear = 0.0f;

            foreach (Unit u in LevelScreen.Units.ActiveUnits)
            {
                if (u.UnitType != UnitType.Knight && u.Health > 0.0f)
                {
                    float distToPrincess = Math.Abs(u.Physics.Bodies[0].Position.X - Physics.Bodies[0].Position.X);
                    fear += FEAR_STRENGTH / (distToPrincess * distToPrincess);
                }
            }
            fearFactorTarget = fear;
            FearFactor      += (fearFactorTarget - FearFactor) * dt * FEAR_RATE_OF_CHANGE;
            FearFactor       = Math.Min(1.0f, FearFactor);

            if (Input.MouseDW != lastScrollPos && updatesSinceWeaponChange > 30)
            {
                // change current project type, state and clip
                if (currentProjectileType == ProjectileType.Bomb)
                {
                    currentProjectileType = ProjectileType.Arrow;
                    state = PrincessState.IdleBow;
                    ClipInstance.Play(BOW_IDLE_CLIP_NAME);
                }
                else
                {
                    currentProjectileType = ProjectileType.Bomb;
                    state = PrincessState.IdleBomb;
                    ClipInstance.Play(BOMB_IDLE_CLIP_NAME);
                }

                lastScrollPos            = Input.MouseDW;
                updatesSinceWeaponChange = 0;
            }
            else
            {
                updatesSinceWeaponChange++;
                lastScrollPos = Input.MouseDW;
            }

            // Update state and the current clip, if need be. NOTE: The only other state/clip transitions are when changing gun and in Fire().
            switch (state)
            {
            case PrincessState.IdleBomb:
            {
                if (isDragging)
                {
                    state = PrincessState.AimingBomb;
                    ClipInstance.Play(BOMB_AIM_CLIP_NAME);
                }
            }
            break;

            case PrincessState.IdleBow:
            {
                if (isDragging)
                {
                    state = PrincessState.PullingBackBow;
                    ClipInstance.Play(BOW_AIM_CLIP_NAME);
                }
            }
            break;

            case PrincessState.AimingBomb:
            {
                if (!isDragging)
                {
                    state = PrincessState.IdleBomb;
                    ClipInstance.Play(BOMB_IDLE_CLIP_NAME);
                }
            }
            break;

            case PrincessState.PullingBackBow:
            {
                if (!isDragging)
                {
                    state = PrincessState.IdleBow;
                    ClipInstance.Play(BOW_IDLE_CLIP_NAME);
                }
            }
            break;

            case PrincessState.ThrowingBomb:
            {
                if (timeSinceLastFired > bombReloadTime)
                {
                    state = PrincessState.IdleBomb;
                    ClipInstance.Play(BOMB_IDLE_CLIP_NAME);
                }
            }
            break;

            case PrincessState.FiringBow:
            {
                if (timeSinceLastFired > bowReloadTime)
                {
                    state = PrincessState.IdleBow;
                    ClipInstance.Play(BOW_IDLE_CLIP_NAME);
                }
            }
            break;
            }

            base.Update(dt);
        }
Пример #10
0
        public override void Update(float dt)
        {
            base.Update(dt);
            var iconMoveRight = ((LevelScreen)ParentScreen).Hud.IconMoveRight;
            var iconMoveLeft  = ((LevelScreen)ParentScreen).Hud.IconMoveLeft;

            if ((Input.MouseJustDown(MouseButton.Left) && iconMoveRight.DestRect.Contains(Input.MouseX, Input.MouseY)) ||
                Input.KeyJustDown(Keys.Right))
            {
                moveForce = new Vector2(MOVE_FORCE, 0.0f);
                ClipInstance.Play("moving", true, true, 1.0f);
                if (Cue.IsValidForPlay(cueMove))
                {
                    cueMove = ParentScreen.ParentGame.Audio.Play("seige");
                    cueMove.Sound.Volume = CUE_MIN_VOL;
                }
            }
            else if ((Input.MouseJustDown(MouseButton.Left) && iconMoveLeft.DestRect.Contains(Input.MouseX, Input.MouseY)) ||
                     Input.KeyJustDown(Keys.Left))
            {
                moveForce = new Vector2(-MOVE_FORCE, 0.0f);
                ClipInstance.Play("moving", true, false, 1.0f);
                if (Cue.IsValidForPlay(cueMove))
                {
                    cueMove = ParentScreen.ParentGame.Audio.Play("seige");
                    cueMove.Sound.Volume = CUE_MIN_VOL;
                }
            }

            if (moveForce != Vector2.Zero)
            {
                if (!Input.MouseDown(MouseButton.Left) && !Input.KeyDown(Keys.Right) && !Input.KeyDown(Keys.Left))
                {
                    moveForce = Vector2.Zero;
                    ClipInstance.Stop();
                }

                if (cueMove != null && !cueMove.IsDisposed && cueMove.IsPlaying)
                {
                    if (cueVolume < cueMove.Settings.Volume)
                    {
                        cueVolume           += Math.Max(dt, (cueMove.Settings.Volume - cueVolume) * 4f * dt);
                        cueVolume            = Math.Min(1.0f, cueVolume);
                        cueMove.Sound.Volume = cueVolume;
                    }
                }
            }
            else
            {
                if (cueMove != null && !cueMove.IsDisposed && cueMove.IsPlaying)
                {
                    if (cueVolume > CUE_MIN_VOL)
                    {
                        cueVolume           -= Math.Max(dt, (cueVolume - CUE_MIN_VOL) * 4f * dt);
                        cueVolume            = Math.Max(0.0f, cueVolume);
                        cueMove.Sound.Volume = cueVolume;
                    }
                    else
                    {
                        cueMove.Stop(AudioStopOptions.Immediate);
                    }
                }
            }

            if (moveForce != Vector2.Zero && moveForce.X * physics.Bodies[0].LinearVelocity.X >= 0)
            {
                physics.Bodies[0].ApplyForce(ref moveForce);
            }
            else
            {
                if (physics.Bodies[0].LinearVelocity.Length() > 0.001f)
                {
                    Vector2 stopForce = -STOP_FORCE *Vector2.Normalize(physics.Bodies[0].LinearVelocity);

                    physics.Bodies[0].ApplyForce(ref stopForce);
                }
                else
                {
                    physics.Bodies[0].LinearVelocity = Vector2.Zero;
                }
            }

            // Follow!
            ParentScreen.Camera2D.Position = Position + cameraOffset;
        }