Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualCC Ricers

Posted 31 July 2012 - 08:23 AM


Hello

collision=false;
for(int i = 0; i< Map.CollisionPosition.Count; i++)
		 if (MousePosition * 32 == Map.CollisionPosition[i])
		  {
			   collision = true;
			   break;
		  }
Isn'it what you're trying to do ?


sir you are a genius Posted Image.

just one last question. can you tell me why my for loop didn't work and yours did?

thank you so much


The second loop works because of the "break" statement. In your loop, you kept resetting collision to false when it found the next tile to check against. It will not return true unless the collision happened in the very last tile. The break statement tells the program to exit the loop, basically saying "we found a collision, looping further isn't necessary."

#1CC Ricers

Posted 31 July 2012 - 08:22 AM


Hello

collision=false;
for(int i = 0; i< Map.CollisionPosition.Count; i++)
		 if (MousePosition * 32 == Map.CollisionPosition[i])
		  {
			   collision = true;
			   break;
		  }
Isn'it what you're trying to do ?


sir you are a genius Posted Image.

just one last question. can you tell me why my for loop didn't work and yours did?

thank you so much


The second loop works because of the "break" statement. In your loop, you kept resetting collision to false when it found the next tile to check against. It will not return false unless the collision happened in the very last tile. The break statement tells the program to exit the loop, basically saying "we found a collision, nothing more to do here."

PARTNERS