Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 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;
            }
        }
Esempio n. 4
0
        void PlayNewEnemyAnimation()
        {
            ClipAnim newAnim = null;

            if (_animations.TryGetValue(new AnimKey(CurrentState, _animDirection), out newAnim))
            {
                if (newAnim != ClipInstance.CurrentAnim)
                {
                    ClipInstance.Play(newAnim);
                }
            }
        }
Esempio n. 5
0
        public CharacterEntity(EggGameScreen gameScreen, Clip clip,
                               Vector2 position, Vector2 scale, float rotation, Vector2 physicsOffset, float physicsRadius)
        {
            ClipInstance   = new ClipInstance(clip);
            GameScreen     = gameScreen;
            Position       = position; Scale = scale; Rotation = rotation;
            _physicsRadius = physicsRadius;
            _physicsOffset = physicsOffset;
            IsValid        = true;

            SetupDynamics();
        }
Esempio n. 6
0
        private void PlayNewEggAnimation()
        {
            ClipAnim newAnim = null;

            if (_animations.TryGetValue(CurrentState, out newAnim))
            {
                if (newAnim != ClipInstance.CurrentAnim)
                {
                    ClipInstance.Play(newAnim);
                }
            }
        }
Esempio n. 7
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;
                }
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
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);
        }
Esempio n. 11
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;
        }
Esempio n. 12
0
 private static void CheckClipInstanceTranslationBindings(ref ClipInstance clipInstance, ref RigDefinition rig)
 {
     ref var clipBindings = ref clipInstance.Clip.Bindings.TranslationBindings;
Esempio n. 13
0
 public virtual void Draw2D(SpriteBatch spriteBatch)
 {
     ClipInstance.Draw(spriteBatch);
 }
Esempio n. 14
0
 public override void Update(float dt)
 {
     ClipInstance.Update(dt);
     base.Update(dt);
 }
Esempio n. 15
0
    public override void AddGraphSetupComponent(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        var walkShortLeftClip  = ClipBuilder.AnimationClipToDenseClip(WalkShortLeftClip);
        var walkLongLeftClip   = ClipBuilder.AnimationClipToDenseClip(WalkLongLeftClip);
        var walkStraightClip   = ClipBuilder.AnimationClipToDenseClip(WalkStraightClip);
        var walkLongRightClip  = ClipBuilder.AnimationClipToDenseClip(WalkLongRightClip);
        var walkShortRightClip = ClipBuilder.AnimationClipToDenseClip(WalkShortRightClip);

        var jogShortLeftClip  = ClipBuilder.AnimationClipToDenseClip(JogShortLeftClip);
        var jogLongLeftClip   = ClipBuilder.AnimationClipToDenseClip(JogLongLeftClip);
        var jogStraightClip   = ClipBuilder.AnimationClipToDenseClip(JogStraightClip);
        var jogLongRightClip  = ClipBuilder.AnimationClipToDenseClip(JogLongRightClip);
        var jogShortRightClip = ClipBuilder.AnimationClipToDenseClip(JogShortRightClip);

        var clipConfiguration = new ClipConfiguration();

        clipConfiguration.Mask  = 0;
        clipConfiguration.Mask |= (int)ClipConfigurationMask.LoopTime;
        clipConfiguration.Mask |= LoopValues ? (int)ClipConfigurationMask.LoopValues : 0;
        clipConfiguration.Mask |= (int)ClipConfigurationMask.CycleRootMotion;
        clipConfiguration.Mask |= (int)ClipConfigurationMask.DeltaRootMotion;
        clipConfiguration.Mask |= BankPivot ? (int)ClipConfigurationMask.BankPivot : 0;

        clipConfiguration.MotionID = m_MotionId;

        var graphSetup = new AnimationControllerSetup
        {
            WalkShortLeftClip  = walkShortLeftClip,
            WalkLongLeftClip   = walkLongLeftClip,
            WalkStraightClip   = walkStraightClip,
            WalkLongRightClip  = walkLongRightClip,
            WalkShortRightClip = walkShortRightClip,

            JogShortLeftClip  = jogShortLeftClip,
            JogLongLeftClip   = jogLongLeftClip,
            JogStraightClip   = jogStraightClip,
            JogLongRightClip  = jogLongRightClip,
            JogShortRightClip = jogShortRightClip,
        };

        if (Bake)
        {
            var rigDefinition = dstManager.GetComponentData <RigDefinitionSetup>(entity);

            var walkShortLeftClipInstance  = ClipInstance.Create(rigDefinition.Value, walkShortLeftClip);
            var walkLongLeftClipInstance   = ClipInstance.Create(rigDefinition.Value, walkLongLeftClip);
            var walkStraightClipInstance   = ClipInstance.Create(rigDefinition.Value, walkStraightClip);
            var walkLongRightClipInstance  = ClipInstance.Create(rigDefinition.Value, walkLongRightClip);
            var walkShortRightClipInstance = ClipInstance.Create(rigDefinition.Value, walkShortRightClip);

            var jogShortLeftClipInstance  = ClipInstance.Create(rigDefinition.Value, jogShortLeftClip);
            var jogLongLeftClipInstance   = ClipInstance.Create(rigDefinition.Value, jogLongLeftClip);
            var jogStraightClipInstance   = ClipInstance.Create(rigDefinition.Value, jogStraightClip);
            var jogLongRightClipInstance  = ClipInstance.Create(rigDefinition.Value, jogLongRightClip);
            var jogShortRightClipInstance = ClipInstance.Create(rigDefinition.Value, jogShortRightClip);

            graphSetup.WalkShortLeftClip  = UberClipNode.Bake(walkShortLeftClipInstance, clipConfiguration, SampleRate);
            graphSetup.WalkLongLeftClip   = UberClipNode.Bake(walkLongLeftClipInstance, clipConfiguration, SampleRate);
            graphSetup.WalkStraightClip   = UberClipNode.Bake(walkStraightClipInstance, clipConfiguration, SampleRate);
            graphSetup.WalkLongRightClip  = UberClipNode.Bake(walkLongRightClipInstance, clipConfiguration, SampleRate);
            graphSetup.WalkShortRightClip = UberClipNode.Bake(walkShortRightClipInstance, clipConfiguration, SampleRate);

            graphSetup.JogShortLeftClip  = UberClipNode.Bake(jogShortLeftClipInstance, clipConfiguration, SampleRate);
            graphSetup.JogLongLeftClip   = UberClipNode.Bake(jogLongLeftClipInstance, clipConfiguration, SampleRate);
            graphSetup.JogStraightClip   = UberClipNode.Bake(jogStraightClipInstance, clipConfiguration, SampleRate);
            graphSetup.JogLongRightClip  = UberClipNode.Bake(jogLongRightClipInstance, clipConfiguration, SampleRate);
            graphSetup.JogShortRightClip = UberClipNode.Bake(jogShortRightClipInstance, clipConfiguration, SampleRate);

            walkShortLeftClipInstance.Dispose();
            walkLongLeftClipInstance.Dispose();
            walkStraightClipInstance.Dispose();
            walkLongRightClipInstance.Dispose();
            walkShortRightClipInstance.Dispose();

            jogShortLeftClipInstance.Dispose();
            jogLongLeftClipInstance.Dispose();
            jogStraightClipInstance.Dispose();
            jogLongRightClipInstance.Dispose();
            jogShortRightClipInstance.Dispose();

            clipConfiguration.Mask     = 0;
            clipConfiguration.Mask    |= (int)ClipConfigurationMask.NormalizedTime;
            clipConfiguration.Mask    |= (int)ClipConfigurationMask.LoopTime;
            clipConfiguration.Mask    |= (int)ClipConfigurationMask.RootMotionFromVelocity;
            clipConfiguration.MotionID = 0;
        }
        else
        {
            clipConfiguration.Mask |= (int)ClipConfigurationMask.NormalizedTime;
        }

        graphSetup.Configuration = clipConfiguration;

        dstManager.AddComponentData(entity, graphSetup);
    }