Trying to make enemies behave

I have tried getting enemies to behave like you are playing against a person. It's been trickier than I thought it would be. I haven't even made a code check in this week because I haven't gotten anything that I wanted done yet. I am tempted to move onto one of the other 7 tasks ahead of me like more sprite work and getting that in the game.

I have been going through some tutorials and studying coding to learn more and see if any ideas present themselves.

So far I've got something like:
public void UpdateEnemyAction(GameTime gameTime) {
           //TODO: AI stuff here
            float badguyChaseThreshold = BadGuyChaseDistance;
            distanceFromPlayer = player2position.X - player1position.X  ;
            if (distanceFromPlayer > 100 ){
                testBadGuy.AnimateLeft(gameTime);
                if ( distanceFromPlayer < badguyChaseThreshold ) {

                    velocityPlayer2.X = -moveSpeed * ( float )gameTime.ElapsedGameTime.TotalSeconds;
                }
            }
             if ( distanceFromPlayer < -100 ) {
                testBadGuy.AnimateRight(gameTime);
               
                    velocityPlayer2.X = moveSpeed * ( float )gameTime.ElapsedGameTime.TotalSeconds;
                }
            }
        }

The bad guy bounces around in between 100 and - 100 distance now. It just doesn't feel like you are playing against a person yet so I'm trying to figure it out. I have tried using -badguyChaseThreshold but it seems about the same. Hopefully I'll come up with some ideas soon.

Comments

Popular Posts