예제 #1
0
        //########################################################################
        //# Event Handlers
        /// <summary>
        /// Tick event handler of animation timer.
        /// Moves all sprites by calling the Move() method.
        /// </summary>
        private void AnimationTimerTick(object sender, EventArgs e)
        {
            // Move all bombs.
            // Also remove bombs that are off screen, hence the backwards loop.
            for (int index = _bombs.Count - 1; index >= 0; index--)
            {
                Bomb bomb = _bombs[index];
                if (bomb.Y >= Height)
                {
                    _bombs.RemoveAt(index);
                }
                else
                {
                    bomb.Move();
                    if (bomb.CollidedWith(_ship))
                    {
                        Win("Alien");
                    }
                }
            }
            // Move the alien
            _alien.Move();
            // Ask the alien whether it wants to drop another bomb
            Bomb newBomb = _alien.LaunchBomb();

            if (newBomb != null)
            {
                _bombs.Add(newBomb);
            }
            // Force repaint. This triggers the GamePaint() handler below.
            Refresh();
        }