Basic question
I''m working on a game in c++. I want a collision detection method that looks like this:-
detect_collision(player p, enemy e){
if(one of the enemy''s bullets overlaps with the player)
kill the player;
if(one of the player''s bullets overlaps with the enemy)
kill the enemy;
}
If I write this method and call it from within the main game loop, for the player and each enemy, the collision detection dosen''t work, however, if I cut and paste the code into the main loop (where p and e are directly available) the program works fine. What''s going on?
thanks in advance.
felix.
March 09, 2000 09:06 AM
You passed the parameters in a wrong way!
You should try this ( so just change the function header! ):
detect_collision( player &p,enemy &e ) // &p and &e are
{ // references!
....//your code
}
Your problem was ( is? I don''t hope so! ) that you created two new objects ( enemy and player )in each function call. So you just changed the state of this new objects and not the state of the two ones you passed to the function!
If you have more trouble, call me:
Centum@gmx.net
You should try this ( so just change the function header! ):
detect_collision( player &p,enemy &e ) // &p and &e are
{ // references!
....//your code
}
Your problem was ( is? I don''t hope so! ) that you created two new objects ( enemy and player )in each function call. So you just changed the state of this new objects and not the state of the two ones you passed to the function!
If you have more trouble, call me:
Centum@gmx.net
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement