rowlandsfc
Active member
so i created a basic game and it has a level that is basically space invaders. i have a class for the bad guys, and a class for the bullets, but sometimes i have an issue in game where the bullet just goes straight through the enemy rather than actually hitting it. this doesnt happen all the time so i know the the bullet class and the contact between bullet and enemy does work bu t just dont understand why sometimes it would go straight through?
thats the code i have for the collision between the 2 objects
bullet collision with enemy:
bullet.RemoveAll(bullets => bullets.isDisposed); // check for collicion between enemies and bullets
foreach(JetBullet b in bullet)
{
b.MoveBullet(this.panel1);
foreach(EnemyShips enemy in enemies)
{
if (b.d.Bounds.IntersectsWith(enemy.e.Bounds))
{
b.isDisposed = true;
b.d.Dispose();
enemy.isDisposed = true;
enemy.e.Dispose();
enemyNumber--;
enemyTimer.Enabled = true;
score = score + 5;
enemiesKilled = enemiesKilled + 1;
lblKilled.Text = "Enemies Kileed: " + enemiesKilled;
lblScore.Text = "Score: " + score;
enemiesKilled = enemiesKilled + 1;
}
}
}
thats the code i have for the collision between the 2 objects