I wanna a pattern who move my enemy randomly at all because when i have 3 or 4 enemys they seem like the same enemy movement. this is my code for the random :
int seed = unchecked(System.DateTime.Now.Ticks.GetHashCode());
rand = new Random(seed);
And here the code for process the move:
public void move(GameTime time, WorldScreen screen)
{
timer += (float)time.ElapsedGameTime.TotalMilliseconds;
if (timer > 2000)
{
switch (rand.Next(0, 3))
{
case 0:
base.direction = Enemy.Direction.down;
break;
case 1:
base.direction = Enemy.Direction.right;
break;
case 2:
base.direction = Enemy.Direction.left;
break;
case 3:
base.direction = Enemy.Direction.up;
break;
}
timer = 0;
}
timer1 += (float)time.ElapsedGameTime.TotalMilliseconds;
if (timer1 > 50)
{
timer1 = 0;
if (direction == Enemy.Direction.down)
{
if (!MoveCollision(new Vector2(position.X, position.Y + speed), screen))
{
base.position.Y += speed;
ActualAnimation = getAnimation("rundown");
}
else
{
base.direction = Enemy.Direction.right;
}
}
if (direction == Enemy.Direction.up)
{
if (!MoveCollision(new Vector2(position.X, position.Y - speed), screen))
{
base.position.Y -= speed;
ActualAnimation = getAnimation("runup");
}
else
{
base.direction = Enemy.Direction.down;
}
}
if (direction == Enemy.Direction.right)
{
if (!MoveCollision(new Vector2(position.X + speed, position.Y), screen))
{
base.position.X += speed;
ActualAnimation = getAnimation("runright");
}
else
{
base.direction = Enemy.Direction.left;
}
}
if (direction == Enemy.Direction.left)
{
if (!MoveCollision(new Vector2(position.X - speed, position.Y), screen))
{
base.position.X -= speed;
ActualAnimation = getAnimation("runleft");
}
else
{
base.direction = Enemy.Direction.up;
}
}
}
ActualAnimation.update(time, position);
}
but this code just do the same pattern for all enemys on the room. thx for help me with it .