Would it be better if the enemy ships did the hittests?

Subscribe to Would it be better if the enemy ships did the hittests? 3 posts

Sign in to reply


 
avatar for Hb_Sukima Hb_Sukima 173 posts
Flag Post

Well, in the shootorials the missile checks the enemy array to see if there is collision. Would it be more efficient if the enemy ships checks a missile array for collision instead? Or would it be the same?

 
avatar for Rameares Rameares 330 posts
Flag Post

Either way your going to see very little diffrence by plaing it in the missile there is no checks carried out if there is no missile fired. it depends on to many factors to give a straight answer as to whats the best way. I think it’s just standard to have the projectile do the test.

Performance wise i wouldn’t bother giving it much thought. focus more on what additions you may add to the game at a latter time how you decide to program at the start may effect what is viable to add later you don’t want to completely rewrite code.

It’s hard to give straight answers becuase slight design changes can mean diffrent code might produce better results. Human productivity is the most important factor when programming intodays world that is why we have all these high level languages. we just design faster computers to deal with the performance hits.

 
avatar for Haelix Haelix 201 posts
Flag Post

Something I like doing when collision testing… say you have 2 arrays, Missiles and Enemies… generally you’re going to look for the most efficient way to run your loops. Missiles are the more dynamic quantity… you know how many enemies will be on a level or on the screen… but the missiles are controlled by the player. Also, your hit testing loop doesn’t even need to run if your Missile array is empty (player hasn’t fired any missiles). As Missiles are your first limiting factor, in your game loop:


if( missile_array.length > 0 )
{
if( enemy_array.length > 0 )
{
// then your hit test loops
}
}

Also, since the gameplay mechanic is “Missiles blow up and are removed from play upon hitting One enemy” it means that when your missile Does hit an enemy, you can break out of your loop, thus saving you any remaining hittests and remove it from the array, the stage, and from play.

This is also the most efficient way because if you did it in reverse, enemies checking against missiles, since missile code removes itself once hit, you would constantly need to check, upon every iteration of the loop, if all of the missiles were still in play.

Sign in to reply