I'm making a collision detection system, and I want to know what the best approach is. When my main character is dead (hp = 0), should I make a separate method that ends the game, or should I do it in that method in my collision detection? The thing is that the endGame method I made is in another class than the collision detection. I could obviously move it to the same class, but I don't know if that's preferred or not, or if I should just do all if it in the same method. I appreciate all replies!
Ok, I decided to just include it all in that method. The only thing is that I noticed I get an error on this line. Code: CGRect bunnyRect = CGRectMake(bunny.position.x - (bunny.contentSize.width/2), bunny.position.y - (bunny.contentSize.height/2), bunny.contentSize.width, bunny.contentSize.height); if (CGRectIntersectsRect(projectileRect, bunnyRect)) { //<---this line has the error "Incompatible type for argument 1 of 'CGRectIntersectsRect' projectileRect is a rect declared in another class. Thanks!
It seems obvious from the error message that the problem is the projectileRect but it's more or less impossible to figure this out with just two lines of code...
Sorry, here's the code containing projectileRect. Code: projectileRect = CGRectMake(projectile.position.x - (projectile.contentSize.width/2), projectile.position.y - (projectile.contentSize.height/2), projectile.contentSize.width, projectile.contentSize.height); moleToDelete = [[NSMutableArray alloc] init]; for (NormalMole *mole in moleArray) { moleRect = CGRectMake(mole.position.x - (mole.contentSize.width/2), mole.position.y - (mole.contentSize.height/2), mole.contentSize.width, mole.contentSize.height); if (CGRectIntersectsRect(projectileRect, moleRect)) {
Ok, I finally got it all sorted out by putting all that code in the same class. The if statement, collision code, and everything else. Thanks for all your help!