Example #1
0
        /// <summary>
        /// Load the game over screen
        /// </summary>
        public override void Load()
        {
            GridStyle       = GridStyles.Ticks;
            BackgroundColor = Color.Black;
            FontName        = "QuartzMS";

            // Add the score text
            ScoreText = AddText(new Text
            {
                Alignment     = HorizontalAlignments.Left,
                VerticalAlign = VerticalAlignments.Top,
                Scale         = .4f,
                Position      = new Vector2(-100f, 100f),
                Color         = Color.White
            });

            // Add the start key text
            RestartText = AddText(new Text
            {
                Value            = "Press SPACE to Play",
                Position         = new Vector2(0f, -100f),
                Alignment        = HorizontalAlignments.Center,
                VerticalAlign    = VerticalAlignments.Bottom,
                AnimationType    = TextAnimations.Typewriter,
                AnimationSeconds = 0.2,
                Scale            = 0.5f,
                Color            = Color.Lime
            });
            if (Game.Platform == GamePlatforms.XBox)
            {
                RestartText.Value = "Press START to Play";
            }
            else if (Game.Platform == GamePlatforms.WindowsPhone)
            {
                RestartText.Value = "TAP to Play";
            }

            missile = AddSprite <MissileSprite>();
            missile.SetCostume("ufo");
            missile.Costume.YCenter = VerticalAlignments.Center;
            missile.Scale           = 2;
            missile.Show();
            missile.X = 0;
            missile.Y = 50;

            barrier       = AddSprite <BarrierSprite>();
            barrier.Scale = 2.5f;
            barrier.Y     = -70;

            ufo                 = AddSprite <UfoSprite>();
            ufo.Position        = Vector2.Zero;
            ufo.Costume.YCenter = VerticalAlignments.Top;
            ufo.Scale           = 1;
            ufo.Show();
        }
Example #2
0
        /// <summary>
        /// Update the play screen
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime)
        {
            // Use this to use the mouse to rotate the ship
            // ship.RotateTowards(Mouse.Position);

            if (ship.CostumeName != "ShipDeath")
            {
                // Space key to fire a missile
                if (Keyboard.KeyPressed(Keys.Space))
                {
                    missile.Fire(ship.Position, ship.Rotation);
                }
            }

            foreach (AlienMissileSprite AlienMissile in alienMissiles.Where(a => a.State == MissileStates.Destroy).ToList())
            {
                Sprites.Remove(AlienMissile);
                alienMissiles.Remove(AlienMissile);
            }

            AlienMissileCollisions();

            // Missile collisions
            if (missile.State == MissileStates.Flying)
            {
                // Missile collsion with UFO
                if (ufo.State == UfoStates.Flying)
                {
                    if (missile.IsTouching(ufo))
                    {
                        ufo.Explode();
                        missile.Load();
                        Score += 100;
                    }
                }

                Sprite HitBarrier = null;
                if (missile.IsTouching(barrier1))
                {
                    HitBarrier = barrier1;
                }
                if (missile.IsTouching(barrier2))
                {
                    HitBarrier = barrier2;
                }
                if (missile.IsTouching(barrier3))
                {
                    HitBarrier = barrier3;
                }
                if (missile.IsTouching(barrier4))
                {
                    HitBarrier = barrier4;
                }
                if (HitBarrier != null)
                {
                    missile.SetCostume("MissileHitBarrier");
                    missile.Scale = 0.5f;
                    HitBarrier.Stamp(missile, StampMethods.Cutout);
                    missile.Load();
                }

                // Missile collision with each alien
                foreach (AlienSprite alien in aliens)
                {
                    // Only the ones who are alive, not the exploding or dead ones
                    if (alien.State == AlienStates.Alive)
                    {
                        if (missile.IsTouching(alien))
                        {
                            alien.Explode();
                            AlienCount -= 1;
                            missile.Load();
                            MoveWaitSeconds = MoveWaitSeconds * MoveWaitPercent;
                            Score          += alien.ScoreValue;
                            //Checking to see if all the aliens are dead
                            if (AlienCount == 0)
                            {
                                StartLevel();
                                break;
                            }
                        }
                    }
                }
            }

            // Crazy shooting for testing only
            if (Keyboard.KeyPressed(Keys.S))
            {
                AlienShoot();
            }

            // faster alients for testing only
            if (Keyboard.KeyPressed(Keys.F))
            {
                MoveWaitSeconds /= 2;
            }

            // Debug Text
            if (DebugTextVisible)
            {
                ShowShipStatus();
                ShowDebugText();
            }
        }