Bueno resulta que ando trabajando en un juego roguelike y quisiera saber como hacen los patrones en "the legend of zelda" para que los enemigos se muevan a su bola pero siempre llegan hasta ati
El mas simple de todos que es el que te persigue si te ve lo tengo programado:
if (type == "murcielago")
{
roc = new Rectangle((int)Position.X - 200, (int)Position.Y - 200, 400, 400);
if (roc.Intersects(world.player.rectangle()))
{
if (world.player.Position.X > Position.X)
{
Position.X += speed;
}
if (world.player.Position.X < Position.X)
{
Position.X -= speed;
}
if (world.player.Position.Y > Position.Y)
{
Position.Y += speed;
}
if (world.player.Position.Y < Position.Y)
{
Position.Y -= speed;
}
if (world.player.num11 == 0)
{
if (rectangle().Intersects(world.player.rectangle()))
{
world.player.life--;
world.player.num11 = 1;
}
}
time20 += time.ElapsedGameTime.Milliseconds;
if (time20 > 180)
{
time20 = 0;
if (rec == new Rectangle(1, 87, 8, 10))
{
Position.X -= 10;
rec = new Rectangle(14, 87, 16, 10);
}
else
{
rec = new Rectangle(1, 87, 8, 10);
Position.X += 10;
}
}
}
else
{
rec = new Rectangle(1, 87, 8, 10);
}
}
pero claro luego cuando intento un enemigo que se mueva a su bola como las bolas rojas que te tiran pelotas pues no tengo ni idea de como hacerlo e intentado esto :
if (type == "bola")
{
if (world.player.num11 == 0)
{
if (rectangle().Intersects(world.player.rectangle()))
{
world.player.life--;
world.player.num11 = 1;
}
}
time20 += time.ElapsedGameTime.Milliseconds;
if (time20 > 50)
{
time20 = 0;
direccion = random.Next(1,5);
}
if (direccion == 1)
{
foreach (tile t in world.WorldTiles)
{
if (new Rectangle((int)(Position.X + speed), (int)Position.Y, width, height).Intersects(t.rectangle()))
{
speed = 0;
}
}
Position.X += speed;
speed = 4;
}
if (direccion == 2)
{
foreach (tile t in world.WorldTiles)
{
if (new Rectangle((int)(Position.X - speed), (int)Position.Y, width, height).Intersects(t.rectangle()))
{
speed = 0;
}
}
Position.X -= speed;
speed = 4;
}
if (direccion == 3)
{
foreach (tile t in world.WorldTiles)
{
if (new Rectangle((int)(Position.X), (int)(Position.Y + speed), width, height).Intersects(t.rectangle()))
{
speed = 0;
}
}
Position.Y += speed;
speed = 4;
}
if (direccion == 4)
{
foreach (tile t in world.WorldTiles)
{
if (new Rectangle((int)(Position.X), (int)(Position.Y - speed), width, height).Intersects(t.rectangle()))
{
speed = 0;
}
}
Position.Y += speed;
Position.Y -= speed;
speed = 4;
}
time201 += time.ElapsedGameTime.Milliseconds;
if (time201 > 180)
{
time201 = 0;
if (rec == new Rectangle(132, 142, 16, 15))
{
Position.X -= 2;
rec = new Rectangle(116, 141, 14, 16);
}
else
{
rec = new Rectangle(132, 142, 16, 15);
Position.X += 2;
}
}
}
pero el enemigo lo único que hace es moverse de un lado pa otro y ya esta y el colmo es que si pongo dos o tres hacen exactamente lo mismo y eso es lo que no quiero.
E buscado por google pero nada .
El tema es que me falla para que se mueva totalmente libre?
Gracias de antemano.