Plane:位置、圖片、移動邏輯。Bullet:位置、速度、存活旗標、繪製/更新。Enemy:位置、血量、移動模式、碰撞箱。Timer gameLoop = new Timer { Interval = 16 }; // ~60 FPS
gameLoop.Tick += (s, e) => {
UpdateBullets();
UpdateEnemies();
CheckCollisions();
this.Invalidate();
};
gameLoop.Start();
void UpdateBullets() {
for (int i = bullets.Count - 1; i >= 0; i--) {
Bullet b = bullets[i];
b.Y -= b.Speed;
if (b.Y < 0) { bullets.RemoveAt(i); continue; }
foreach (Enemy en in enemies) {
if (b.Bounds.IntersectsWith(en.Bounds)) {
en.HP -= b.Damage;
bullets.RemoveAt(i);
if (en.HP <= 0) enemies.Remove(en);
break;
}
}
}
}
Rectangle.IntersectsWith 做 AABB 碰撞,簡單高效。this.DoubleBuffered = true 消除閃爍。加入粒子特效、音效、分數、波次系統、Boss 戰,逐步演進為完整射擊遊戲。