C++ AI
Posted in Help the coder! on Dec 19, 2009 at 17:58 IST (7 months ago). Subscribe to this post
Email
Showing comments 1 to 2 of total 2 on page 1 of 1
Post replyShowing comments 1 to 2 of total 2 on page 1 of 1
« Previous1Next »
death_2_...Rank: 92
I recently dug up an old C++ game I was making, and decided to continue development. I implemented an AI, intended on moving the NPCs towards the player, provided they are within a 20 square radius (it is a roguelike). However, instead of doing that, some NPCs disappear, while others will just freeze. What have I done wrong?
SeedRand();
short NewX, NewY;
if (player.getx()-this->Loc.X <= 20 && player.gety()-this->Loc.Y <= 20 && player.getx()-this->Loc.X >= -20 && player.gety()-this->Loc.Y >= -20)
{
short Num = GetRandomNumber(0, 100);
if (player.getx()-this->Loc.X >= player.gety()-this->Loc.Y)
{
if (Num < 80)
{
if (Num > 75)
{
if (player.getx()-this->Loc.X <= 0)
{
NewX = 1;
} else {
NewX = -1;
}
} else {
if (player.getx()-this->Loc.X <= 0)
{
NewX = -1;
} else {
NewX = 1;
}
}
} else {
if (Num > 95)
{
if (player.gety()-this->Loc.Y <= 0)
{
NewY = 1;
} else {
NewY = -1;
}
} else {
if (player.gety()-this->Loc.Y <= 0)
{
NewY = -1;
} else {
NewY = 1;
}
}
}
} else {
if (Num < 80)
{
if (Num > 75)
{
if (player.gety()-this->Loc.Y <= 0)
{
NewY = 1;
} else {
NewY = -1;
}
} else {
if (player.gety()-this->Loc.Y <= 0)
{
NewY = -1;
} else {
NewY = 1;
}
}
} else {
if (Num > 95)
{
if (player.getx()-this->Loc.X <= 0)
{
NewX = 1;
} else {
NewX = -1;
}
} else {
if (player.getx()-this->Loc.X <= 0)
{
NewX = -1;
} else {
NewX = 1;
}
}
}
}
} else {
NewX = GetRandomNumber(0, 2);
NewY = GetRandomNumber(0, 2);
if(NewX == 2)
{
NewX = -1;
}
if(NewY == 2)
{
NewY = -1;
}
}
this->walk(NewX, NewY);
seedrand() seeds the random function to the system time, and this->walk adds on the x and y parameters to the current x and y variables.
Thanks.
Posted by death_2_all on Saturday, December 19, 2009, 5:58 pm
death_2_...Rank: 92
and I am still waiting for some help
Posted by death_2_all on Saturday, March 27, 2010, 2:21 am
Pages: « Previous1Next »