所以我创建了一个基本游戏,它的级别基本上是太空入侵者。我有一个针对坏蛋的课程,也有一个关于子弹的课程,但是有时候我在游戏中遇到一个问题,子弹只是直接穿过敌人而不是直接击中敌人。这不会一直发生,所以我知道子弹类以及子弹与敌人之间的接触确实有效
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;
}
}
}
那是代码ive为碰撞检测而准备的,任何建议将不胜感激
敌人的大小/速度
e.Width = 42;
e.Height = 24;
speed = random.Next(2, 5);
子弹大小/速度
d.Width = 3;
d.Height = 20;
yPos -= 27;