Пример #1
0
        public void Update(Microsoft.Xna.Framework.GameTime gameTime, Enemy enemy)
        {
            if (current > 0)
            {
                current -= gameTime.ElapsedGameTime.Milliseconds;
                life -= gameTime.ElapsedGameTime.Milliseconds;
                enemy.Position = enemy.Position + enemy.Velocity;

                if (life < 0)
                    enemy.ActionComplete();
            }
            else
            {
                current = max;
            }
        }
Пример #2
0
        public void Update(GameTime gameTime, Enemy enemy)
        {
            if (currentWalkDistance <= 0)
            {
                int r = RandomGenerator.Random.Next(0, 4);
                currentWalkDistance = randomWalkDistance;

                Vector2 velocityAbsolute = new Vector2(Math.Abs(enemy.Velocity.X), Math.Abs(enemy.Velocity.Y));

                switch (r)
                {
                    case 0:
                        velocity = new Vector2(velocityAbsolute.X, 0);
                        enemy.CurrentSprite.CurrentAnimation = AnimationKey.Right;
                        break;
                    case 1:
                        velocity = new Vector2(-velocityAbsolute.X, 0);
                        enemy.CurrentSprite.CurrentAnimation = AnimationKey.Left;
                        break;
                    case 2:
                        velocity = new Vector2(0, velocityAbsolute.Y);
                        enemy.CurrentSprite.CurrentAnimation = AnimationKey.Down;
                        break;
                    case 3:
                        velocity = new Vector2(0, -velocityAbsolute.Y);
                        enemy.CurrentSprite.CurrentAnimation = AnimationKey.Up;
                        break;
                }
            }
            else
            {
                if (!enemy.HandleCollisions(velocity).IsColliding)
                {
                    enemy.Position = enemy.Position + velocity;
                    currentWalkDistance -= Math.Abs((velocity.X + velocity.Y) / 2);
                }
                else
                {
                    currentWalkDistance = 0;
                }

                if (enemy.HasPlayerInSight)
                    enemy.ActionComplete();
            }
        }