jonathang wrote:Hm, this doesn't work, doing if(temp_bomb->cloneindex!=-1 && yscreen< view.height) also doesn't work.
First off, do you know what and (&&) is? If you want an if statement to be dependent on two things, you should use the and operator instead of nesting if statements.
- Code: Select all
if(this==0 && that==1)
{
// only runs with this is 0 and that is 1
}
Now, that condition is not the one that I mentioned.
- Code: Select all
int dist = distance(x, y, bomb.x, bomb.y); // this sets the distance to the lowest indexed bomb
int target = bomb.cloneindex; // for now assume the lowest indexed is the target
int i;
Actor* closest;
for(i=bomb.cloneindex; i<highest_bomb; i++)
{
Actor* temp_bomb = getclone2("bomb", i);
if(temp_bomb->cloneindex!=-1) // <-- this is the line you want to change
{
int temp_dist = distance(x, y, temp_bomb->x, temp_bomb->y);
if(temp_dist < dist)
{
dist = temp_dist;
target = i;
}
}
}
closest = getclone2("bomb", target);
if(closest->cloneindex!=-1)
{
}
The above code has the line you want to change commented. That if statement acts as a filter, in this case it filters out all invalid bomb actors.What you want it to do is ignore all of the bombs that are targeted and in the danger zone. You know a bomb is tarted if temp_bomb->targeted is equal to one. You know a bomb is in the safe zone if temp_bomb->yscreen < view.height - 50 (or however big the danger zone is). That code you added about target!=i doesn't do anything you want it to do. The only other time you use targeted is in the last if statement of the code I provided. At that point you want to set closest->targeted equal to one, so no other computer will target it.