bool Bullet::bullethit(Image b)
{
if((centerx > b.left && centerx < b.right) && (centery > b.top && centery < b.bottom))
return true;
else
return false;
}
11 replies to this topic
#1
Posted 04 June 2010 - 05:52 AM
Why won't this return true?
|
|
|
#2
Posted 04 June 2010 - 07:34 AM
If this is supposed to be a normal (x,y) coordinate type, then your inequalities are backwards. (centery > b.top) means that the center is ABOVE the top. (centery < b.bottom) means that it's BELOW the bottom. It's quite impossible for it to be both simultaneously. Just flip all of the signs around and you should be fine.
#3
Posted 04 June 2010 - 07:52 AM
The x,y coordinates are in allegro, and in allegro, the higher you go, the smaller the y gets.
Think of it as, x = 0; y = 0; are the coordinates of the top left corner of the screen.
Think of it as, x = 0; y = 0; are the coordinates of the top left corner of the screen.
#4
Posted 04 June 2010 - 08:28 AM
Thats weird, the code looks right.
You should try to breakpoint the function and see the values.
My best guess is that you are passing a wrong image in to the function.
You should try to breakpoint the function and see the values.
My best guess is that you are passing a wrong image in to the function.
std::string s("oberq zhpu?");std::for_each(s.begin(),s.end(),[&](char&c){c=~c;c=~c-0x01/(~(c|0x20)/0x0D*0x02-0x0B)*0x0D;});std::cout<<s;
#6
Posted 04 June 2010 - 01:29 PM
Equality didn't do the trick.
And unfortunately, I am passing the right image to the function. I wish it was wrong :P
And unfortunately, I am passing the right image to the function. I wish it was wrong :P
#7
Posted 04 June 2010 - 02:42 PM
Check the values of centerx and centery during runtime. Perhaps they're not initializing correctly.
#8
Posted 04 June 2010 - 03:15 PM
They are updating correctly. Which probably means that they initialize correctly, right?
#10
Posted 05 June 2010 - 09:30 AM
Rei_NERV said:
They are updating correctly. Which probably means that they initialize correctly, right?
Yep, that would probably mean that. Have you tried stepping into the if statement with a debugger to find out exactly what's going on here?
Alternatively, some more code would be helpful, something we can execute to test it.
#11
Posted 09 July 2010 - 05:41 AM
Is Image custom type that you coded? If so, then did you check left, right, top and bottom fields as they may be calculated wrong?
#12
Posted 09 July 2010 - 02:34 PM
When I'm at a loss, I can sometimes easily debug my code by printing out the values of some variables. I have applied the concept to your code, it may help. Note that %d may have to be changed to %f or something else depending on your variable type.
bool Bullet::bullethit(Image b)
{
printf("centerx=%d, b.left=%d, b.right=%d\n", centerx, b.left, b.right);
printf("centery=%d, b.top=%d, b.bottom=%d\n", centery, b.top, b.bottom);
if((centerx > b.left && centerx < b.right) && (centery > b.top && centery < b.bottom))
return true;
else
return false;
}[FONT=Tahoma][/FONT]
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)
Download the new operating system programming kit! (some assembly required)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









