Ejemplo n.º 1
0
        // Update asteroid state including position and laser hit status.
        protected void UpdateAsteroids(object inputContext)
        {
            if (asteroids == null | asteroids.Count == 0)
                return;

            for (int i = (asteroids.Count - 1); i >= 0; i--) {
                Asteroid asteroid = asteroids[i];

                // If the asteroid is within laser range but not already missed
                // check if the key was pressed close enough to the beat to make a hit
                if (asteroid.DrawX <= mAsteroidMoveLimitX + 20 && !asteroid.Missed) {
                    // If the laser was fired on the beat destroy the asteroid
                    if (mLaserOn) {
                        // Track hit streak for adjusting music
                        scores.HitStreak++;
                        scores.HitTotal++;

                        // Replace the asteroid with an explosion
                        Explosion ex = new Explosion ();

                        ex.AnimationIndex = 0;
                        ex.DrawX = asteroid.DrawX;
                        ex.DrawY = asteroid.DrawY;

                        explosions.Add (ex);

                        mJet.SetMuteFlag (24, false, false);

                        asteroids.RemoveAt (i);

                        // This asteroid has been removed process the next one
                        continue;
                    } else {
                        // Sorry, timing was not good enough, mark the asteroid
                        // as missed so on next frame it cannot be hit even if it is still
                        // within range
                        asteroid.Missed = true;

                        scores.HitStreak = scores.HitStreak - 1;

                        if (scores.HitStreak < 0)
                            scores.HitStreak = 0;
                    }
                }

                // Update the asteroids position, even missed ones keep moving
                asteroid.DrawX -= mPixelMoveX;

                // Update asteroid animation frame
                asteroid.AnimationIndex = (asteroid.AnimationIndex + ANIMATION_FRAMES_PER_BEAT)
                    % mAsteroids.Length;

                // if we have scrolled off the screen
                if (asteroid.DrawX < 0)
                    asteroids.RemoveAt (i);
            }
        }
Ejemplo n.º 2
0
        // Update asteroid state including position and laser hit status.
        protected void UpdateAsteroids(object inputContext)
        {
            if (asteroids == null | asteroids.Count == 0)
            {
                return;
            }

            for (int i = (asteroids.Count - 1); i >= 0; i--)
            {
                Asteroid asteroid = asteroids[i];

                // If the asteroid is within laser range but not already missed
                // check if the key was pressed close enough to the beat to make a hit
                if (asteroid.DrawX <= mAsteroidMoveLimitX + 20 && !asteroid.Missed)
                {
                    // If the laser was fired on the beat destroy the asteroid
                    if (mLaserOn)
                    {
                        // Track hit streak for adjusting music
                        scores.HitStreak++;
                        scores.HitTotal++;

                        // Replace the asteroid with an explosion
                        Explosion ex = new Explosion();

                        ex.AnimationIndex = 0;
                        ex.DrawX          = asteroid.DrawX;
                        ex.DrawY          = asteroid.DrawY;

                        explosions.Add(ex);

                        mJet.SetMuteFlag(24, false, false);

                        asteroids.RemoveAt(i);

                        // This asteroid has been removed process the next one
                        continue;
                    }
                    else
                    {
                        // Sorry, timing was not good enough, mark the asteroid
                        // as missed so on next frame it cannot be hit even if it is still
                        // within range
                        asteroid.Missed = true;

                        scores.HitStreak = scores.HitStreak - 1;

                        if (scores.HitStreak < 0)
                        {
                            scores.HitStreak = 0;
                        }
                    }
                }

                // Update the asteroids position, even missed ones keep moving
                asteroid.DrawX -= mPixelMoveX;

                // Update asteroid animation frame
                asteroid.AnimationIndex = (asteroid.AnimationIndex + ANIMATION_FRAMES_PER_BEAT)
                                          % mAsteroids.Length;

                // if we have scrolled off the screen
                if (asteroid.DrawX < 0)
                {
                    asteroids.RemoveAt(i);
                }
            }
        }