What's the Best Approach?

Discussion in 'Public Game Developers Forum' started by Joethemonkey101, Oct 23, 2010.

  1. Joethemonkey101

    Oct 23, 2010
    7
    0
    0
    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!
     
  2. Joethemonkey101

    Oct 23, 2010
    7
    0
    0
    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!
     
  3. Joethemonkey101

    Oct 23, 2010
    7
    0
    0
    Does anyone have a solution? I'm not sure what's wrong.
     
  4. 99c_gamer

    99c_gamer Well-Known Member

    Mar 23, 2009
    659
    0
    0
    what's the error?
     
  5. NickFalk

    NickFalk Well-Known Member

    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...
     
  6. Joethemonkey101

    Oct 23, 2010
    7
    0
    0
    #6 Joethemonkey101, Oct 29, 2010
    Last edited: Oct 30, 2010
    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)) {
     
  7. Joethemonkey101

    Oct 23, 2010
    7
    0
    0
    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!
     

Share This Page