int refx = x + 160;//change to half the width
int refy = y + 120;//change to half the height
if (unpaused)//use whatever conditionals to limit
{
double dir;
double spd;
dir = direction(refx, refy, player.x, player.y);
spd = distance(refx, refy, player.x, player.y) * .1;//adjust this value to suit
if (spd > .2)//adjust this too
{
x += xdist(dir, spd);
y += ydist(dir, spd);
}
}
double xdist(double angsize, double dist)
{
return cos(degtorad(angsize)) * dist;
}
double ydist(double angsize, double dist)
{
return sin(degtorad(angsize)) * -dist;
}
Users browsing this forum: No registered users and 1 guest