Bullet* bullet = (Bullet*)units[i];
//if it's not one of yoshi's bullets.. die :|
if( bullet->getOwner() != this) {
//do something
}
units is an array that contains unit objects
Bullet inherits from unit.. so this cast should work...
I don't get why it says that 'bullet' is not declared..
error C2065: 'bullet' : undeclared identifier
error C2227: left of '->getOwner' must point to class/struct/union/generic type
And yes... "Bullet.h" is included.. #include "Bullet.h"
Not sure if this is the problem but is units an array of unit or an array of unit*, if it's the later that could be a problem. More code would be very helpful.
Figured it out... It was just a minor problem actually ... I just forgot to put some {} on if(units[i]->getType() == TYPE_BULLET)
Need to clean my glasses I guess..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Bullet* current;
//step through all the units you collided with
for(int i=0; i < (int)units.size(); i++) {
//if it's a bullet
if(units[i]->getType() == TYPE_BULLET) {
current = (Bullet*)units[i];
//if it's not one of yoshi's bullets.. die :|
if(current->getOwner() != this && current->isActive()) {
alive = false;
Singleton<Log>::getInstance()->print("Yoshi has been hit... he died :( !");
}
} else {
//other things
}
}
}