Пример #1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (this.IsGhost)
            {
                CurrentAnimation = IdleAnimation;
            }

            CurrentAnimation.Update(gameTime);
            if (CurrentAnimation.HasFinished)
            {
                CurrentAnimation = CurrentAnimation.NextAnimation;
            }



            if (HasMouseFocus)
            {
                UpdateStatusScreen();
            }

            if (!IsGhost)
            {
                GetSimEntity().Update(gameTime);
            }
        }
Пример #2
0
 internal void Update(GameTime gameTime)
 {
     if (CurrentAnimation != null)
     {
         CurrentAnimation.Update(gameTime);
     }
 }
        public override void Update(GameTime gameTime, GameInfo gameInfo)
        {
            // Update animation
            CurrentAnimation.Update(gameTime);

            base.Update(gameTime, gameInfo);
        }
Пример #4
0
 public override void Update(GameTime gameTime)
 {
     if (CurrentAnimation != null)
     {
         CurrentAnimation.Update(gameTime);
     }
 }
Пример #5
0
        new public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            if (CurrentAnimation != null)
            {
                CurrentAnimation.Update(gameTime);
            }

            base.Update(gameTime, chunks, camera);
        }
Пример #6
0
 public override void Update(GameTime gameTime)
 {
     if (sprite == null)
     {
         return;
     }
     CurrentAnimation.Update(gameTime);
     base.Update(gameTime);
 }
        public override void Update(GameTime gameTime, GameInfo gameInfo)
        {
            // Update animation
            if (CurrentAnimation != null)
            {
                CurrentAnimation.Update(gameTime);
            }

            base.Update(gameTime, gameInfo);
        }
Пример #8
0
        public override void Update(params object[] arguments)
        {
            base.Update(arguments);

            if (Sprite.IsVisible)
            {
                CurrentAnimation.Update();
                Sprite.Texture = CurrentAnimation.TextureIds[CurrentAnimation.CurrentFrame];
            }
        }
Пример #9
0
        public void Update(GameTime gameTime)
        {
            if (CurrentAnimation != null)
            {
                //Console.WriteLine("updating anim" + CurrentAnimation.Name);

                CurrentAnimation.Update(gameTime);

                CurrentFrame = CurrentAnimation.CurrentFrame;
            }
        }
Пример #10
0
        public override void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            if (IsActive)
            {
                if (CurrentAnimation != null)
                {
                    CurrentAnimation.Update(gameTime);
                }
            }


            base.Update(gameTime, chunks, camera);
        }
Пример #11
0
        /// <summary>
        /// Changeds animation dependant on PlayerState.
        /// </summary>
        protected virtual void HandleAnimation(float delta)
        {
            string oldAnimation = CurrentAnimationName;

            #region Handle Animation States
            //  Change the animation depending on the player
            //  state.
            if (_playerState == PlayerState.Grounded)
            {
                CurrentAnimationName = "Idle";
            }
            else if (_playerState == PlayerState.Running)
            {
                CurrentAnimationName = "Run";
            }
            else if (_playerState == PlayerState.Falling)
            {
                CurrentAnimationName = "Falling";
            }
            else if (_playerState == PlayerState.Jumping)
            {
                CurrentAnimationName = "Jumping";
            }
            else if (_playerState == PlayerState.Climbing)
            {
                CurrentAnimationName = "Climbing";
            }
            else if (_playerState == PlayerState.Dead)
            {
                CurrentAnimationName = "Dead";
            }
            else if (_playerState == PlayerState.Swinging)
            {
                CurrentAnimationName = "Swinging";
            }
            #endregion

            //  If the animation has changed, reset its current frame
            if (oldAnimation != CurrentAnimationName)
            {
                CurrentAnimation.ResetCurrentFrame();
            }

            //  Play through the animation
            if (CurrentAnimation != null)
            {
                CurrentAnimation.Update(delta);
            }
        }
Пример #12
0
        public override void Update()
        {
            base.Update();

            if (!Active)
            {
                return;
            }
            CurrentAnimation.Update();

            if (Paused)
            {
                return;
            }

            CurrentAnimation.Update(Speed);
        }
Пример #13
0
        public override void Update(float frameTime)
        {
            base.Update(frameTime);

            if (CurrentAnimation == null || CurrentAnimation.Frames.Count == 0)
            {
                return;
            }


            CurrentAnimation.Update(frameTime);


            if (CurrentAnimation.Paused && Focused)
            {
                if (Input.AnyOfTheseKeysPressed("AnimPreview", Key.A, Key.Left))
                {
                    CurrentAnimation.CurrentFrame.OffSetX -= 1;
                }
                if (Input.AnyOfTheseKeysPressed("AnimPreview", Key.D, Key.Right))
                {
                    CurrentAnimation.CurrentFrame.OffSetX += 1;
                }
                if (Input.AnyOfTheseKeysPressed("AnimPreview", Key.W, Key.Up))
                {
                    CurrentAnimation.CurrentFrame.OffSetY -= 1;
                }
                if (Input.AnyOfTheseKeysPressed("AnimPreview", Key.S, Key.Down))
                {
                    CurrentAnimation.CurrentFrame.OffSetY += 1;
                }

                if (Input.MousePressed(MouseButton.Left, "AnimPreview"))
                {
                    _dragOffSet = WorldMousePosition - CurrentAnimation.CurrentFrame.OffSet;
                }

                if (Input.MouseDown(MouseButton.Left, "AnimPreview"))
                {
                    CurrentAnimation.CurrentFrame.OffSetX = (int)(WorldMousePosition.X - _dragOffSet.X);
                    CurrentAnimation.CurrentFrame.OffSetY = (int)(WorldMousePosition.Y - _dragOffSet.Y);
                }
            }
        }
Пример #14
0
        public void UpdateAnimation(float elapsed)
        {
            CurrentAnimation.Update(elapsed);

            UpdateAnimation(null, RootNode);
        }
Пример #15
0
        public override void Update(GameTime gameTime)
        {
            CurrentAnimation.Update(gameTime);
            if (!(EnemyState == EnemyStates.Damaged || EnemyState == EnemyStates.Dead))
            {
                ProcessDamage();
                Position.X += Velocity.X;
                Position.Y += Velocity.Y;
            }
            foreach (Player player in PlayerManager.Players)
            {
                if (player.Character.PickAggroBox.Intersects(Hitbox) && player.Character.Defending)
                {
                    focusedPlayer = player;
                }
            }
            if (focusedPlayer == null)
            {
                FacingLeft = false;
            }
            else if (focusedPlayer.Character.Hitbox.Center.X < Hitbox.Center.X)
            {
                FacingLeft = false;
            }
            else if (focusedPlayer.Character.Hitbox.Center.X > Hitbox.Center.X)
            {
                FacingLeft = true;
            }

            if (!FacingLeft)
            {
                AttackHitbox.X = (int)(Hitbox.X - AttackRange.X);
            }
            else
            {
                AttackHitbox.X = (int)Position.X + HitboxXDisplacement + Hitbox.Width;
            }
            AttackHitbox.Y = (int)Hitbox.Y;
            Hitbox.X       = (int)Position.X + HitboxXDisplacement;
            Hitbox.Y       = (int)Position.Y + HitboxYDisplacement - (int)PositionZ;
            switch (EnemyState)
            {
            case EnemyStates.Idle:
                foreach (Player player in PlayerManager.Players)
                {
                    if (Vector2.Distance(new Vector2(player.Character.Hitbox.Center.X, player.Character.Hitbox.Center.Y), new Vector2(Hitbox.Center.X, Hitbox.Center.Y)) <= 300)
                    {
                        focusedPlayer = player;
                        SelectAnimation(RunningAnimation);
                        EnemyState = EnemyStates.Chase;
                    }
                }
                break;

            case EnemyStates.Chase:
                float distance = float.MaxValue;
                foreach (Player player in PlayerManager.Players)
                {
                    if (player.Character.PickAggroBox.Intersects(Hitbox) && player.Character.Defending)
                    {
                        focusedPlayer = player;
                        break;
                    }

                    float playerDistance = Vector2.Distance(player.Character.Position, Position);
                    if (distance > playerDistance)
                    {
                        distance      = playerDistance;
                        focusedPlayer = player;
                    }
                }

                if (AttackHitbox.Intersects(focusedPlayer.Character.Hitbox) && focusedPlayer.Character.Hitbox.Bottom > Hitbox.Bottom - 50 &&
                    focusedPlayer.Character.Hitbox.Bottom < Hitbox.Bottom + 50)
                {
                    Velocity.X = 0;
                    Velocity.Y = 0;
                    SelectAnimation(StandingAnimation);
                    EnemyState = EnemyStates.Attack;
                    break;
                }

                if ((FacingLeft && AttackHitbox.Left >= focusedPlayer.Character.Hitbox.Right) ||
                    (!FacingLeft && AttackHitbox.Left >= focusedPlayer.Character.Hitbox.Right))
                {
                    Velocity.X = -2;
                }
                else if ((!FacingLeft && AttackHitbox.Right <= focusedPlayer.Character.Hitbox.Left) ||
                         (FacingLeft && AttackHitbox.Right <= focusedPlayer.Character.Hitbox.Left))
                {
                    Velocity.X = 2;
                }

                if (Hitbox.Bottom >= focusedPlayer.Character.Hitbox.Bottom + 50)
                {
                    Velocity.Y = -2;
                }
                else if (Hitbox.Bottom <= focusedPlayer.Character.Hitbox.Bottom - 50)
                {
                    Velocity.Y = 2;
                }
                break;

            case EnemyStates.Attack:
                if (!AttackHitbox.Intersects(focusedPlayer.Character.Hitbox))
                {
                    SelectAnimation(RunningAnimation);
                    EnemyState = EnemyStates.Chase;
                }
                else
                {
                    AttackWaitTime -= (int)Math.Ceiling(gameTime.ElapsedGameTime.TotalSeconds * 60F);
                    if (AttackWaitTime <= 0)
                    {
                        Random rnd = new Random();
                        AttackWaitTime = rnd.Next(30, 90);
                        SelectAnimation(AttackingAnimation);
                        EnemyState = EnemyStates.Attacking;
                    }
                }
                break;

            case EnemyStates.Attacking:
                StateTimer += (int)Math.Ceiling(gameTime.ElapsedGameTime.TotalSeconds * 60F);
                if (StateTimer == 20)
                {
                    AttackVisible = true;
                }
                else
                {
                    AttackVisible = false;
                }
                if (StateTimer > AttackingAnimation.NumFrames * AttackingAnimation.Frequency)
                {
                    StateTimer = 0;
                    SelectAnimation(StandingAnimation);
                    EnemyState = EnemyStates.Attack;
                }
                break;

            case EnemyStates.SpecialAttack:

                break;

            case EnemyStates.Retreat:
                /* if( Health <  30)
                 * {
                 *   velocity of enemy is opposite direction of focusedPlayer
                 * }*/
                break;

            case EnemyStates.Damaged:
                StateTimer += (int)Math.Ceiling(gameTime.ElapsedGameTime.TotalSeconds * 60F);
                if (StateTimer > DamagedAnimation.NumFrames * DamagedAnimation.Frequency)
                {
                    StateTimer = 0;
                    SelectAnimation(StandingAnimation);
                    EnemyState = EnemyStates.Chase;
                }
                break;

            case EnemyStates.Dead:
                StateTimer += 1;
                if (StateTimer > DeathAnimation.NumFrames * DeathAnimation.Frequency - 1)
                {
                    StateTimer    = 0;
                    MarkForDelete = true;
                }
                break;
            }
        }
Пример #16
0
        //public void Draw(Point position, CanvasAnimatedDrawEventArgs args)
        //{
        //    args.DrawingSession.DrawImage(CharacterMap, (float)position.X, (float)position.Y, new Rect(CurrentAnimation.CurrentFrame.X * Resolution, CurrentAnimation.CurrentFrame.Y * Resolution, Resolution, Resolution));
        //}

        public void Update(CanvasAnimatedUpdateEventArgs args)
        {
            CurrentAnimation.Update(args);
        }
Пример #17
0
        public override void Update(GameTime gameTime)
        {
            // really just 1?
            //int framesPassed = (int)Math.Ceiling(gameTime.ElapsedGameTime.TotalSeconds * 60F);
            int framesPassed = 1;

            Hitbox.X           = (int)Position.X + HitboxXDisplacement;
            Hitbox.Y           = (int)Position.Y + HitboxYDisplacement - (int)PositionZ;
            PickAggroBox.X     = (int)Hitbox.X - 50;
            PickAggroBox.Y     = (int)Hitbox.Y - 50;
            PickDefendingBox.X = (int)Hitbox.X - 25;
            PickDefendingBox.Y = (int)Hitbox.Y - 25;
            if (PassEffectTimer > 0 && (PassEffectTimer -= framesPassed) <= 0)
            {
                PassEffectTimer = 0;
                ShootAttack    /= 5;
            }
            if (!(CharacterState == CharacterStates.PickState || CharacterState == CharacterStates.StunnedState) && PickHealth < MaxPickHealth)
            {
                PickHealthRegenerationTimer -= framesPassed;
            }
            if (PickHealthRegenerationTimer <= 0)
            {
                PickHealthRegenerationTimer = 60;
                PickHealth += PickHealthRegenerationRate;
                if (PickHealth > MaxPickHealth)
                {
                    PickHealth = MaxPickHealth;
                }
            }
            CheckCollision();
            if (CharacterState != CharacterStates.DamagedState)
            {
                ProcessIncomingDamage();
            }
            if (FacingLeft)
            {
                AttackHitbox.X = (int)(Hitbox.X - AttackRange.X);
            }
            else
            {
                AttackHitbox.X = (int)Position.X + HitboxXDisplacement + Hitbox.Width;
            }
            AttackHitbox.Y = (int)Position.Y + 70;
            CurrentAnimation.Update(gameTime);
            switch (CharacterState)
            {
            case CharacterStates.ShootState:
                if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.ShootMode) != ActionStates.Held)
                {
                    CharacterState = CharacterStates.DefaultState;
                    PlayerManager.GetPlayer(Player.PlayerIndex).Target.Visible = false;
                    break;
                }
                if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Attack) == ActionStates.Pressed)
                {
                    PlayerManager.GetPlayer(Player.PlayerIndex).Target.Visible = false;
                    SelectAnimation(ShootingAnimation);
                    CharacterState = CharacterStates.ShootingState;
                }
                break;

            case CharacterStates.ShootingState:
                StateTimer += framesPassed;
                if (StateTimer == (ShootingAnimation.NumFrames - 1) * ShootingAnimation.Frequency)
                {
                    ShootBall shootBall = new ShootBall(Tint);
                    int       disp      = 150;
                    if (FacingLeft)
                    {
                        disp = 50;
                    }
                    shootBall.SourcePosition      = new Vector2(Position.X + disp, Hitbox.Top);
                    shootBall.DestinationPosition = new Vector2(PlayerManager.GetPlayer(Player.PlayerIndex).Target.Hitbox.Center.X, PlayerManager.GetPlayer(Player.PlayerIndex).Target.Hitbox.Center.Y);
                    shootBall.Velocity.X          = (shootBall.DestinationPosition.X - shootBall.SourcePosition.X) / 60;
                    shootBall.Velocity.Y          = -(shootBall.DestinationPosition.Y - .5F * 60 * 60 / 2 - shootBall.SourcePosition.Y) / 60;
                    shootBall.ReleaseTime         = gameTime.TotalGameTime;
                    PlayerManager.EntityManager.Entities.Add(shootBall);
                }
                if (StateTimer >= ShootingAnimation.NumFrames * ShootingAnimation.Frequency - 1)
                {
                    StateTimer     = 0;
                    CharacterState = CharacterStates.DefaultState;
                }
                break;

            case CharacterStates.PickState:
                Defending = false;
                if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Pick) != ActionStates.Held)
                {
                    CharacterState = CharacterStates.DefaultState;
                    break;
                }

                foreach (Player player in PlayerManager.Players)
                {
                    if (player.Character.Hitbox.Intersects(PickDefendingBox))
                    {
                        Defending = true;
                        break;
                    }
                }
                break;

            case CharacterStates.PassState:
                ProcessMovement(Speed);
                Position += Velocity;
                if (Velocity.X < 0)
                {
                    FacingLeft = true;
                }
                else if (Velocity.X > 0)
                {
                    FacingLeft = false;
                }
                if (Velocity.X != 0 || Velocity.Y != 0)
                {
                    SelectAnimation(RunningAnimation);
                }
                else
                {
                    SelectAnimation(StandingAnimation);
                }
                if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Pass) != ActionStates.Held)
                {
                    CharacterState = CharacterStates.DefaultState;
                    break;
                }

                LinkedListNode <Buttons> passButtonNode = InputManager.PassButtons.First;
                foreach (Player targetPlayer in PlayerManager.Players)
                {
                    if (targetPlayer.PlayerIndex == Player.PlayerIndex)
                    {
                        continue;
                    }
                    if (targetPlayer.Character.CharacterState == CharacterStates.StunnedState)
                    {
                        passButtonNode = passButtonNode.Next;
                        continue;
                    }
                    if (InputManager.GetButtonActionState(Player.PlayerIndex, passButtonNode.Value) == ActionStates.Pressed)
                    {
                        PassBall ball = new PassBall(Tint);
                        ball.Position     = new Vector2(Hitbox.Center.X, Hitbox.Center.Y);
                        ball.SourcePlayer = Player;
                        ball.TargetPlayer = targetPlayer;
                        ball.ReleaseTime  = gameTime.TotalGameTime;
                        PlayerManager.EntityManager.Entities.Add(ball);
                        HasBall = false;
                        //SelectAnimation(StandingAnimation);
                        CharacterState = CharacterStates.DefaultState;
                        passButtonNode = passButtonNode.Next;
                    }
                }
                break;

            case CharacterStates.AttackState:
                StateTimer += framesPassed;
                if (StateTimer >= AttackingAnimation.NumFrames * AttackingAnimation.Frequency)
                {
                    StateTimer     = 0;
                    CharacterState = CharacterStates.DefaultState;
                }
                break;

            case CharacterStates.DamagedState:
                StateTimer += framesPassed;
                //if (StateTimer >= DamagedAnimation.NumFrames * DamagedAnimation.Frequency - 1)
                if (StateTimer >= 20)
                {
                    StateTimer     = 0;
                    CharacterState = CharacterStates.DefaultState;
                }
                break;

            case CharacterStates.StunnedState:
                StateTimer += framesPassed;
                if (StateTimer >= AttackingAnimation.NumFrames * AttackingAnimation.Frequency)
                {
                    StateTimer     = 0;
                    CharacterState = CharacterStates.DefaultState;
                }
                break;

            case CharacterStates.JumpingState:
                StateTimer += framesPassed;
                ProcessMovement(Speed);
                Position.X += Velocity.X;
                PositionZ  += VelocityZ;
                VelocityZ  -= 1F;
                if (PassEffectTimer > 180 - JumpingAnimation.NumFrames * JumpingAnimation.Frequency * (2 / 3) &&
                    InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.ShootMode) == ActionStates.Pressed)
                {
                    // alley oop or dunk or some crazy thing
                }
                if (StateTimer > JumpingAnimation.NumFrames * JumpingAnimation.Frequency)
                {
                    PositionZ      = 0;
                    StateTimer     = 0;
                    CharacterState = CharacterStates.DefaultState;
                }
                break;

            case CharacterStates.DeadState:
                MarkForDelete = true;
                break;

            case CharacterStates.DefaultState:
                ProcessMovement(Speed);
                Position += Velocity;
                if (Velocity.X < 0)
                {
                    FacingLeft = true;
                }
                else if (Velocity.X > 0)
                {
                    FacingLeft = false;
                }
                if (Velocity.X != 0 || Velocity.Y != 0)
                {
                    SelectAnimation(RunningAnimation);
                }
                else
                {
                    SelectAnimation(StandingAnimation);
                }
                if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Pass) == ActionStates.Pressed &&
                    PlayerManager.Players.Count > 1 && HasBall)
                {
                    //SelectAnimation(PassAnimation);
                    CharacterState = CharacterStates.PassState;
                }
                else if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.ShootMode) == ActionStates.Pressed)
                {
                    CharacterState = CharacterStates.ShootState;
                    SelectAnimation(PrimeShotAnimation);
                    int disp;
                    if (FacingLeft)
                    {
                        disp = -5;
                    }
                    else
                    {
                        disp = 5;
                    }
                    PlayerManager.GetPlayer(Player.PlayerIndex).Target.Position = new Vector2(Hitbox.Center.X - 100 / 2 + disp, Hitbox.Center.Y - 100 / 2);
                    PlayerManager.GetPlayer(Player.PlayerIndex).Target.Visible  = true;
                }
                else if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Attack) == ActionStates.Pressed)
                {
                    SelectAnimation(AttackingAnimation);
                    CharacterState = CharacterStates.AttackState;
                }
                else if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Pick) == ActionStates.Pressed)
                {
                    SelectAnimation(PickingAnimation);
                    CharacterState = CharacterStates.PickState;
                }
                else if (InputManager.GetCharacterActionState(Player.PlayerIndex, CharacterActions.Jump) == ActionStates.Pressed)
                {
                    SelectAnimation(JumpingAnimation);
                    VelocityZ      = 1F * JumpingAnimation.NumFrames * JumpingAnimation.Frequency / 2;
                    CharacterState = CharacterStates.JumpingState;
                }
                break;
            }
        }
Пример #18
0
        public override void Update(GameTime gameTime)
        {
            Position.X += Velocity.X;
            Position.Y += Velocity.Y;
            Hitbox.X    = (int)Position.X + HitboxDisplacement;
            Hitbox.Y    = (int)Position.Y;
            if (focusedPlayer == null)
            {
                FacingLeft = true;
            }
            else if (focusedPlayer.Character.Hitbox.Center.X < Hitbox.Center.X)
            {
                FacingLeft = true;
            }
            else if (focusedPlayer.Character.Hitbox.Center.X > Hitbox.Center.X)
            {
                FacingLeft = false;
            }

            if (FacingLeft)
            {
                AttackHitbox.X = (int)(Hitbox.X - AttackRange.X);
            }
            else
            {
                // 72 is the width that the image actually takes up in the frame
                AttackHitbox.X = (int)Position.X + HitboxDisplacement + 72;
            }
            AttackHitbox.Y = Hitbox.Y;
            CurrentAnimation.Update(gameTime);
            if (EnemyState != EnemyStates.Damaged)
            {
                ProcessDamage();
            }
            switch (EnemyState)
            {
            case EnemyStates.Idle:
                foreach (Player player in PlayerManager.Players)
                {
                    if (Math.Abs(player.Character.Hitbox.Center.X - Hitbox.Center.X) <= 200 &&
                        Math.Abs(player.Character.Hitbox.Center.Y - player.Character.Hitbox.Center.Y) <= 200)
                    {
                        focusedPlayer = player;
                        //animation will be changed
                        //animatedSprite.SelectAnimation(4, 1);
                        EnemyState = EnemyStates.SeePlayer;
                    }
                }
                break;

            case EnemyStates.SeePlayer:
                //input delay from SeePlayer state to Chase state
                StateTimer += 1;
                if (StateTimer >= 120)
                {
                    //animatedSprite.SelectAnimation(3, 1);
                    EnemyState = EnemyStates.Chase;
                }
                break;

            case EnemyStates.Chase:
                float distance = float.MaxValue;
                foreach (Player player in PlayerManager.Players)
                {
                    float playerDistance = Vector2.Distance(player.Character.Position, Position);
                    if (distance > playerDistance)
                    {
                        distance      = playerDistance;
                        focusedPlayer = player;
                    }
                }

                if (AttackHitbox.Intersects(focusedPlayer.Character.Hitbox))
                {
                    Velocity.X = 0;
                    Velocity.Y = 0;
                    //animatedSprite.SelectAnimation(1, 2);
                    EnemyState = EnemyStates.Attack;
                    break;
                }

                if (FacingLeft && AttackHitbox.Left >= focusedPlayer.Character.Hitbox.Right)
                {
                    Velocity.X = -2;
                }
                else if (!FacingLeft && AttackHitbox.Right <= focusedPlayer.Character.Hitbox.Left)
                {
                    Velocity.X = 2;
                }

                if (AttackHitbox.Top >= focusedPlayer.Character.Hitbox.Bottom)
                {
                    Velocity.Y = -2;
                    if (Position.Y == focusedPlayer.Character.Position.Y)
                    {
                        Velocity.Y = 0;
                    }
                }
                else if (AttackHitbox.Bottom <= focusedPlayer.Character.Hitbox.Top)
                {
                    Velocity.Y = 2;
                    if (Position.Y == focusedPlayer.Character.Position.Y)
                    {
                        Velocity.Y = 0;
                    }
                }
                break;

            case EnemyStates.Attack:
                if (!AttackHitbox.Intersects(focusedPlayer.Character.Hitbox))
                {
                    //animatedSprite.SelectAnimation(3, 1);
                    EnemyState = EnemyStates.Chase;
                }
                else
                {
                    // attack here
                }

                break;

            /*case EnemyStates.Swat:
             *  if ( )
             *  {
             *      ball.SourcePosition = Position;
             *          ball.DestinationPosition = PlayerManager.GetPlayer(Player.PlayerIndex).Target.Position;
             *          ball.Velocity.X = (PlayerManager.GetPlayer(Player.PlayerIndex.get()).Target.Position.X - Position.X) / 60;
             *          ball.Velocity.Y = -(PlayerManager.GetPlayer(Player.PlayerIndex).Target.Position.Y - .5F * 60 * 60 / 2 - Position.Y) / 60;
             *  }
             *
             *  break;*/

            case EnemyStates.Retreat:
                /* if( Health <  30)
                 * {
                 *   velocity of enemy is opposite direction of focusedPlayer
                 * }*/
                break;

            case EnemyStates.Damaged:
                StateTimer += (int)Math.Ceiling(gameTime.ElapsedGameTime.TotalSeconds * 60F);
                if (FacingLeft)
                {
                    Position.X += 5;
                }
                else
                {
                    Position.X -= 5;
                }
                if (StateTimer > 20)
                {
                    StateTimer = 0;
                    //animatedSprite.SelectAnimation(3, 1);
                    EnemyState = EnemyStates.Chase;
                }
                break;

            case EnemyStates.Dead:
                //input animation
                //animatedSprite.SelectAnimation(x, x);
                MarkForDelete = true;
                break;

                /* case CharacterStates.DefaultState:
                 *  ProcessMovement(Speed);
                 *   if (InputManager.GetCharacterActionState(PlayerIndex, CharacterActions.Pass) == ActionStates.Pressed
                 *       && PlayerManager.Players.Count > 1 && HasBall)
                 *   {
                 *       CharacterState = CharacterStates.PassState;
                 *   }
                 *   break;
                 */
            }
        }
Пример #19
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (gameTime.TotalGameTime.TotalMilliseconds - _lastAnimationUpdate.TotalMilliseconds > AnimationDelay)
            {
                if (jumpKey && Keyboard.GetState().IsKeyUp(Keys.Up))
                {
                    jumpKey = false;
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Up))
                {
                    if (CanJump)
                    {
                        fallspeed = 12;
                        JumpsCount++;
                        SetJumpAnimation();
                        JumpPower           = 25;
                        JumpPowerIncrement  = 25;
                        isAnimationUpdating = true;
                        jumpKey             = true;
                    }
                    else if (jumpKey)
                    {
                        if (JumpPowerIncrement < MaxJumpPower)
                        {
                            var increment = JumpPowerIncrement + 20 < MaxJumpPower
                                                ? 20
                                                : MaxJumpPower - JumpPowerIncrement;
                            JumpPower          += increment;
                            JumpPowerIncrement += increment;
                        }
                    }
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Left))
                {
                    if (!IsCurrentAnimationJump())
                    {
                        CurrentAnimation = Animations["left"];
                    }
                    isAnimationUpdating = true;
                    CurrentAction       = Actions.MoveLeft;
                    Direction           = Direction.Left;
                }
                else if (Keyboard.GetState().IsKeyDown(Keys.Right))
                {
                    if (!IsCurrentAnimationJump())
                    {
                        CurrentAnimation = Animations["right"];
                    }
                    isAnimationUpdating = true;
                    CurrentAction       = Actions.MoveRight;
                    Direction           = Direction.Right;
                }
                else
                {
                    isAnimationUpdating = false;
                }

                if (isAnimationUpdating)
                {
                    CurrentAnimation.Update();
                    Texture = CurrentAnimation.Frame;
                }
                else
                {
                    CurrentAnimation.SetZeroFrame();
                    Texture       = CurrentAnimation.Frame;
                    CurrentAction = Actions.StandStill;
                    SetWaitAnimation();
                }

                _lastAnimationUpdate = gameTime.TotalGameTime;
            }

            DoAction();
        }
Пример #20
0
 /// <summary>
 /// Update de enemy
 /// </summary>
 /// <param name="gameTime">GameTime object die we kunnen gebruiken om de tijd te meten</param>
 /// <param name="collider">Collider object dat we gebruiken of er collision gebeurt bij de enemy</param>
 /// <param name="collisionObjects">Lijst met alle objecten die kunnen colliden</param>
 public void Update(GameTime gameTime, Collider collider, List <ICollide> collisionObjects)
 {
     collider.CollisionDetect(collisionObjects, this);
     if (TouchingGround)
     {
         ChangeVelocity(MovingSpeed, 0);
     }
     if (TouchingLeft && Velocity.Y == 0)
     {
         IsLookingLeft = false;
         ChangeVelocity(MovingSpeed, null);
     }
     if (TouchingRight && Velocity.Y == 0)
     {
         IsLookingLeft = true;
         ChangeVelocity(-MovingSpeed, null);
     }
     if (IsHit)
     {
         AmountOfHitsEnemyCanTake--;
         IsHit = false;
         ChangeVelocity(0, null);
         if (AmountOfHitsEnemyCanTake <= 0)
         {
             CurrentAnimation = DeathAnimation;
         }
         else
         {
             CurrentAnimation = HurtAnimation;
         }
     }
     if (HurtAnimation != null && CurrentAnimation.CurrentFrame == HurtAnimation.frames[HurtAnimation.frames.Count - 1])
     {
         CurrentAnimation = RunAnimation;
         if (IsLookingLeft)
         {
             ChangeVelocity(-MovingSpeed, null);
         }
         else
         {
             ChangeVelocity(MovingSpeed, null);
         }
         HurtAnimation.Reset();
     }
     if (Attack)
     {
         CurrentAnimation = AttackAnimation;
         ChangeVelocity(0, null);
         if (CurrentAnimation.CurrentFrame == AttackAnimation.frames[AttackAnimation.frames.Count - 1])
         {
             Attack           = false;
             CurrentAnimation = RunAnimation;
             if (IsLookingLeft)
             {
                 ChangeVelocity(-MovingSpeed, null);
             }
             else
             {
                 ChangeVelocity(MovingSpeed, null);
             }
         }
     }
     else
     {
         AttackAnimation.Reset();
     }
     Position += Velocity;
     if (CurrentAnimation.CurrentFrame == DeathAnimation.frames[DeathAnimation.frames.Count - 1])
     {
         collisionObjects.Remove(this);
     }
     widthOfFrame  = CurrentAnimation.CurrentFrame.scale * CurrentAnimation.CurrentFrame.RectangleSelector.Width;
     heightOfFrame = CurrentAnimation.CurrentFrame.scale * CurrentAnimation.CurrentFrame.RectangleSelector.Height;
     CurrentAnimation.Update(gameTime);
 }
Пример #21
0
        public override void Update(GameTime gameTime)
        {
            CurrentAnimation.Update(gameTime);
            if (!(EnemyState == EnemyStates.Damaged || EnemyState == EnemyStates.Dead))
            {
                ProcessDamage();
            }
            foreach (Player player in PlayerManager.Players)
            {
                if (player.Character.PickAggroBox.Intersects(Hitbox) && player.Character.Defending)
                {
                    focusedPlayer = player;
                }
            }
            if (focusedPlayer == null)
            {
                FacingLeft = true;
            }
            else if (focusedPlayer.Character.Hitbox.Center.X < Hitbox.Center.X)
            {
                FacingLeft = true;
            }
            else if (focusedPlayer.Character.Hitbox.Center.X > Hitbox.Center.X)
            {
                FacingLeft = false;
            }

            Hitbox.X = (int)Position.X + HitboxXDisplacement;
            Hitbox.Y = (int)Position.Y + HitboxYDisplacement - (int)PositionZ;
            if (FacingLeft)
            {
                AttackHitbox.X = (int)(Hitbox.X - AttackRange.X);
            }
            else
            {
                AttackHitbox.X = (int)Position.X + HitboxXDisplacement + Hitbox.Width;
            }
            AttackHitbox.Y = (int)Position.Y + 35 * (int)scale;
            switch (EnemyState)
            {
            case EnemyStates.Chase:
                if (Velocity.X != 0 || Velocity.Y != 0)
                {
                    inGoodPositionTimer = 0;
                    SelectAnimation(RunningAnimation);
                }
                else if (inGoodPositionTimer <= 3)
                {
                    inGoodPositionTimer++;
                }
                else
                {
                    SelectAnimation(StandingAnimation);
                }
                if (waitTime > 0)
                {
                    waitTime--;
                    return;
                }
                if (Position.X + Velocity.X >= 0 && Position.X + Hitbox.Width + Velocity.X <= 1280)
                {
                    Position.X += Velocity.X;
                }
                if (Position.Y + Hitbox.Height + Velocity.Y >= 720 / 2 && Position.Y + Hitbox.Height + Velocity.Y <= 720)
                {
                    Position.Y += Velocity.Y;
                }
                float distance = float.MaxValue;
                foreach (Player player in PlayerManager.Players)
                {
                    if (player.Character.PickAggroBox.Intersects(Hitbox) && player.Character.Defending)
                    {
                        focusedPlayer = player;
                        break;
                    }

                    float playerDistance = Vector2.Distance(player.Character.Position, Position);
                    if (distance > playerDistance)
                    {
                        distance      = playerDistance;
                        focusedPlayer = player;
                    }
                }

                if (StateTimer > 0)
                {
                    StateTimer -= 1;
                    if (StateTimer <= 0)
                    {
                        waitFlag = true;
                    }
                    MoveTowardsPlayer(Speed);
                }
                else if (attackFlag)
                {
                    if (AttackHitbox.Intersects(focusedPlayer.Character.Hitbox) && focusedPlayer.Character.Hitbox.Bottom >= Hitbox.Bottom - 50 &&
                        focusedPlayer.Character.Hitbox.Bottom < Hitbox.Bottom + 50)
                    {
                        Velocity.X = 0;
                        Velocity.Y = 0;
                        attackFlag = false;
                        EnemyState = EnemyStates.Attack;
                        break;
                    }
                    MoveTowardsPlayer(Speed);
                }
                else if (waitFlag)
                {
                    waitTime   = GetRandomInt(80, 160);
                    Velocity.X = 0;
                    Velocity.Y = 0;
                    waitFlag   = false;
                    return;
                }
                else if (Vector2.Distance(Position, focusedPlayer.Character.Position) <= surroundDistance)
                {
                    if (GetRandomInt(0, 120) == 1)
                    {
                        attackFlag = true;
                    }
                    else
                    {
                        bool    enemyTooClose      = false;
                        Vector2 distanceFromPlayer = new Vector2(Position.X - focusedPlayer.Character.Position.X, Position.Y - focusedPlayer.Character.Position.Y);
                        float   xSpeedFactor       = (surroundDistance - distanceFromPlayer.X) / (surroundDistance * 2);
                        float   ySpeedFactor       = (surroundDistance - distanceFromPlayer.Y) / (surroundDistance * 2);
                        foreach (Enemy enemy in PlayerManager.EnemyManager.Enemies)
                        {
                            if (!enemy.Equals(this) && Vector2.Distance(enemy.Position, Position) <= 200)
                            {
                                enemyTooClose = true;
                                if ((distanceFromPlayer.X > 0 && distanceFromPlayer.Y > 0) ||
                                    (distanceFromPlayer.X < 0 && distanceFromPlayer.Y < 0))
                                {
                                    Velocity.Y = Math.Sign(Position.Y - enemy.Position.Y) * Speed * ySpeedFactor;
                                    Velocity.X = Math.Sign(Velocity.Y) * Speed * xSpeedFactor;
                                }
                                else if ((distanceFromPlayer.X > 0 && distanceFromPlayer.Y < 0) ||
                                         (distanceFromPlayer.X < 0 && distanceFromPlayer.Y > 0))
                                {
                                    Velocity.Y = Math.Sign(Position.Y - enemy.Position.Y) * Speed * ySpeedFactor;
                                    Velocity.X = -Math.Sign(Velocity.Y) * Speed * xSpeedFactor;
                                }
                                else if (distanceFromPlayer.X == 0)
                                {
                                    if (GetRandomInt(0, 1) == 1)
                                    {
                                        Velocity.X = -Speed * xSpeedFactor;
                                    }
                                    else
                                    {
                                        Velocity.X = Speed * xSpeedFactor;
                                    }
                                }
                                else if (distanceFromPlayer.Y == 0)
                                {
                                    if (GetRandomInt(0, 1) == 1)
                                    {
                                        Velocity.Y = -Speed * ySpeedFactor;
                                    }
                                    else
                                    {
                                        Velocity.Y = Speed * ySpeedFactor;
                                    }
                                }
                                break;
                            }
                        }
                        if (!enemyTooClose)
                        {
                            if (Vector2.Distance(Position, focusedPlayer.Character.Position) <= surroundDistance / 2)
                            {
                                Velocity.X = Math.Sign(distanceFromPlayer.X) * Speed * xSpeedFactor;
                                Velocity.Y = Math.Sign(distanceFromPlayer.Y) * Speed * ySpeedFactor;
                            }
                            else
                            {
                                inGoodPositionTimer++;
                                Velocity.X = 0;
                                Velocity.Y = 0;
                            }
                        }
                    }
                }
                else if (AttackHitbox.Intersects(focusedPlayer.Character.Hitbox) && focusedPlayer.Character.Hitbox.Bottom >= Hitbox.Bottom - 50 &&
                         focusedPlayer.Character.Hitbox.Bottom < Hitbox.Bottom + 50)
                {
                    Velocity.X = 0;
                    Velocity.Y = 0;
                    attackFlag = false;
                    EnemyState = EnemyStates.Attack;
                    break;
                }
                else
                {
                    StateTimer = GetRandomInt(45, 90);
                }
                break;

            case EnemyStates.Attack:
                if (!AttackHitbox.Intersects(focusedPlayer.Character.Hitbox))
                {
                    EnemyState = EnemyStates.Chase;
                }
                else
                {
                    AttackWaitTime -= (int)Math.Ceiling(gameTime.ElapsedGameTime.TotalSeconds * 60F);
                    if (AttackWaitTime <= 0)
                    {
                        AttackWaitTime = PlayerManager.EnemyManager.RandomGen.Next(30, 90);
                        SelectAnimation(AttackingAnimation);
                        EnemyState = EnemyStates.Attacking;
                    }
                }
                break;

            case EnemyStates.Attacking:
                StateTimer += (int)Math.Ceiling(gameTime.ElapsedGameTime.TotalSeconds * 60F);
                if (StateTimer == (AttackingAnimation.NumFrames - 1) * AttackingAnimation.Frequency + 2)
                {
                    AttackVisible = true;
                }
                else
                {
                    AttackVisible = false;
                }
                if (StateTimer > AttackingAnimation.NumFrames * AttackingAnimation.Frequency)
                {
                    StateTimer = 0;
                    if (GetRandomInt(0, 60) == 1)
                    {
                        SelectAnimation(StandingAnimation);
                        EnemyState = EnemyStates.Attack;
                    }
                    {
                        EnemyState = EnemyStates.Chase;
                    }
                }
                break;

            case EnemyStates.SpecialAttack:

                break;

            case EnemyStates.Retreat:
                /* if( Health <  30)
                 * {
                 *   velocity of enemy is opposite direction of focusedPlayer
                 * }*/
                break;

            case EnemyStates.Damaged:
                StateTimer += 1;
                if (StateTimer > DamagedAnimation.NumFrames * DamagedAnimation.Frequency)
                {
                    StateTimer = 0;
                    EnemyState = EnemyStates.Chase;
                }
                break;

            case EnemyStates.Dead:
                StateTimer += 1;
                if (StateTimer > DeathAnimation.NumFrames * DeathAnimation.Frequency - 1)
                {
                    StateTimer    = 0;
                    MarkForDelete = true;
                }
                break;
            }
        }
Пример #22
0
 private void UpdateAnimation(GameTime gameTime)
 {
     CurrentAnimation.Update(gameTime);
 }
Пример #23
0
 protected override void UpdateThis(GameTime t)
 {
     CurrentAnimation.Update(t);
 }