# 2D Ennemies mouvement

Hi guys,

This is my first post. I began my first game long time ago, however, I’m amateur and I’m doing it only for hobby.

I began doing a SpaceInvaders based game, however, now I want add something different like a intelligent Enemy movement, There is some place where I could find different examples of enemies moves to test?

Here my code for Space Invaders movement.

``````        private static Boolean IsBorderX(int positionX, int limitWidth)
{
return (positionX >= limitWidth) || (positionX <= 0);
}

private static Boolean IsBorderY(int positionY, int limitHeight)
{
return (positionY >= limitHeight);
}

public static Vector2 SpaceInvadersMovement(GameTime gameTime, Vector2 _position, ref int _directionX, int limitX, int limitY)
{

float time = (float)gameTime.TotalGameTime.TotalSeconds;

//Center origin position x,y
if (IsBorderY((int)_position.Y, limitY))
{
_position.Y = 0;
}

if (IsBorderX((int)_position.X, limitX))
{
//Change movement to back (-1) or forward (1) if the Enemi is in the border X
_directionX *= -1;
}

_position.Y += 0.1f;

Vector2 _position2 = new Vector2(_position.X + _directionX, _position.Y);

return new Vector2(
_position2.X,
(float)(Math.Sin(time * 5) * 2 + _position2.Y)
);
}
``````

and of course I added it in my Update() method of the DrawableGameComponent Enemy class

``````    public override void Update (GameTime gameTime)
{
Position = Common.SpaceInvadersMovement(gameTime, Position, ref _directionX, LimitWidth, LimitHeight);
}
``````