Пример #1
0
        public override void Update(GameTime gameTime)
        {
            if (IsAlive)
            {
                if (SpawnState == RublixSpawnState.Spawning)
                {
                    SpawnTexture.Update(gameTime);
                }
                else if (SpawnState == RublixSpawnState.Positioning)
                {
                    if (MathHelper.Distance(Location.X, TargetBrick.X) > 2 &&
                        MathHelper.Distance(Location.Y, TargetBrick.Y) > 2)
                    {
                        Location               = new Vector2(TargetBrick.X, TargetBrick.Y);
                        SpawnState             = RublixSpawnState.Spawning;
                        SpawnTexture.Animation = AnimationState.Play;
                        SpawnTexture.OnFinish  = () =>
                        {
                            TargetBrick.Life = TargetBrick.InitialLife;
                            Life             = 0;
                        };
                    }
                    else
                    {
                        if (TargetBrick.X > Location.X)
                        {
                            Location = new Vector2(Location.X - 0.1f, Location.Y);
                        }
                        else
                        {
                            Location = new Vector2(Location.X + 0.1f, Location.Y);
                        }
                        if (TargetBrick.Y > Location.Y)
                        {
                            Location = new Vector2(Location.X, Location.Y - 0.1f);
                        }
                        else
                        {
                            Location = new Vector2(Location.X, Location.Y + 0.1f);
                        }
                    }
                }
                else if (SpawnState == RublixSpawnState.Normal)
                {
                    CheckEnemyVausCollision();
                    CheckEnemyVausTwinCollision();
                    CheckEnemyBrickCollision();
                    CheckEnemyWallCollision();
                    Texture.Update(gameTime);
                    TimeToChangeDirection += gameTime.ElapsedGameTime;
                    if (TimeToChangeDirection >= ChangeDirection)
                    {
                        TimeToChangeDirection = TimeSpan.Zero;
                        Direction             = GetRandomDirection();

                        var max = 5;
                        switch (Direction)
                        {
                        case Direction.Down:
                        {
                            max = 8;
                            break;
                        }

                        case Direction.Up:
                        {
                            max = 3;
                            break;
                        }

                        default:
                        {
                            break;
                        }
                        }
                        ChangeDirection = new TimeSpan(0, 0, Arkanoid.Random.Next(1, max));
                    }
                    switch (Direction)
                    {
                    case Direction.Down:
                    {
                        Location = new Vector2(Location.X, Location.Y + 1);
                        break;
                    }

                    case Direction.Up:
                    {
                        Location = new Vector2(Location.X, Location.Y - 1);
                        break;
                    }

                    case Direction.Left:
                    {
                        Location = new Vector2(Location.X - 1, Location.Y);
                        break;
                    }

                    default:
                    {
                        Location = new Vector2(Location.X + 1, Location.Y);
                        break;
                    }
                    }
                }
                if (IsExploding)
                {
                    DieTexture.Update(gameTime);
                }
            }
        }
Пример #2
0
        public override void Update(GameTime gameTime)
        {
            if (IsAlive)
            {
                CheckEnemyVausCollision();
                CheckEnemyVausTwinCollision();
                CheckEnemyBrickCollision();
                CheckEnemyWallCollision();
                Texture.Update(gameTime);
                TimeToChangeDirection += gameTime.ElapsedGameTime;
                TimeToMove            -= gameTime.ElapsedGameTime;
                if (TimeToChangeDirection >= ChangeDirection)
                {
                    TimeToChangeDirection = TimeSpan.Zero;
                    TimeToMove            = new TimeSpan(0, 0, 1);
                    Direction             = GetRandomDirection();
                    ChangeDirection       = new TimeSpan(0, 0, 5);
                }
                if (TimeToMove > TimeSpan.Zero)
                {
                    switch (Direction)
                    {
                    case Direction.Down:
                    {
                        Location = new Vector2(Location.X, Location.Y + 2);
                        break;
                    }

                    case Direction.Up:
                    {
                        Location = new Vector2(Location.X, Location.Y - 2);
                        break;
                    }

                    case Direction.Left:
                    {
                        Location = new Vector2(Location.X - 2, Location.Y);
                        break;
                    }

                    case Direction.Right:
                        Location = new Vector2(Location.X + 2, Location.Y);
                        break;

                    case Direction.DownLeft:
                        Location = new Vector2(Location.X - 2, Location.Y + 2);
                        break;

                    case Direction.DownRight:
                        Location = new Vector2(Location.X + 2, Location.Y + 2);
                        break;

                    case Direction.UpLeft:
                        Location = new Vector2(Location.X - 2, Location.Y - 2);
                        break;

                    case Direction.UpRight:
                        Location = new Vector2(Location.X + 2, Location.Y - 2);
                        break;

                    case Direction.Stop:
                        break;

                    default:
                    {
                        Location = new Vector2(Location.X + 2, Location.Y);
                        break;
                    }
                    }
                }
            }
            if (IsExploding)
            {
                DieTexture.Update(gameTime);
            }
        }