So, what I'm having trouble with is a simple ai that runs from the player. There are walls scattered about the level that the enemy has to get by, but each time he collides with the wall, he gets stuck. I would greatly appreciate some help, here is the relevent code:

 public bool EnemyCollision()
        {
            Rectangle hWallRect = new Rectangle(
               (int)hWallPos.X,
               (int)hWallPos.Y,
               hWallWidth ,
               hWallHeight);

            Rectangle enemyRect = new Rectangle(
                (int)enemy.enemyPosition.X,
                (int)enemy.enemyPosition.Y,
                enemy.enemyWidth,
                enemy.enemyHeight);

            return hWallRect.Intersects(enemyRect);
        }

        if (EnemyCollision())
            {
                if (enemy.enemyPosition.X <= hWallPos.X)
                    enemy.enemyPosition.X += enemy.enemySpeed;

                if (enemy.enemyPosition.Y <= hWallPos.Y)
                    enemy.enemyPosition.Y += enemy.enemySpeed;

                if (enemy.enemyPosition.X >= hWallPos.X)
                    enemy.enemyPosition.X -= enemy.enemySpeed;

                if (enemy.enemyPosition.Y >= hWallPos.Y)
                    enemy.enemyPosition.Y -= enemy.enemySpeed;
            }

Why not use a direction property, then if collision() is true, you can change direction and decrease the x /y away from the wall?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.