예제 #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            //set rendering mode to wireframe if enabled
            if (wireframe)
            {
                GraphicsDevice.Clear(Color.CornflowerBlue);
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
                RasterizerState state = new RasterizerState
                {
                    FillMode = FillMode.WireFrame
                };
                spriteBatch.GraphicsDevice.RasterizerState = state;
            }
            else
            {
                GraphicsDevice.Clear(Color.Black);
                spriteBatch.Begin();
            }

            //draw objects by calling their draw functions
            rock.Draw(spriteBatch);
            foreach (Shot shot in shots)
            {
                shot.Draw(spriteBatch);
            }
            player.Draw(spriteBatch);

            spriteBatch.End();

            base.Draw(gameTime);
        }
예제 #2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin();
            background.Draw(spriteBatch);
            spriteBatch.End();


            spriteBatch.Begin();
            bullets.Draw(spriteBatch);
            asteroids.Draw(spriteBatch);
            player.Draw(spriteBatch);
            alien.Draw(spriteBatch);
            spriteBatch.End();

            spriteBatch.Begin();
            for (int i = 0; i < lives; i++)
            {
                Sprite life = new Sprite(graphics, player.Image);
                life.Rotation = 0;
                life.size     = 0.1f;
                life.position = new Vector2(10 + (i * 20), graphics.PreferredBackBufferHeight - 50);
                life.Draw(spriteBatch);
            }
            spriteBatch.End();

            if (counter > 0)
            {
                spriteBatch.Begin();
                spriteBatch.DrawString(font, "Wave " + wave, new Vector2(graphics.PreferredBackBufferWidth / 2 - 60, 200), Color.White * 0.7f);
                spriteBatch.End();
                counter--;
            }
            spriteBatch.Begin();
            if (lives < 0)
            {
                spriteBatch.DrawString(font, "GAME OVER!", new Vector2(200, graphics.PreferredBackBufferHeight / 2), Color.White);
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }
예제 #3
0
        private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.Clear(Color.Black);

            if (!bStarted)
            {
                String drawString = "Asteroids";
                // Create font and brush.
                Font       drawFont  = new Font("Verdana", 48);
                SolidBrush drawBrush = new SolidBrush(Color.Red);

                PointF drawPoint = new PointF(this.ClientRectangle.Width / 4, this.ClientRectangle.Height - iTextHolder);
                // Draw string to screen.
                e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint);

                drawString = "AURORA";
                // Create font and brush.
                drawFont  = new Font("TIMES NEW ROMAN", 14);
                drawBrush = new SolidBrush(Color.White);

                drawPoint = new PointF(this.ClientRectangle.Width / 4, this.ClientRectangle.Height - (iTextHolder - 90));
                // Draw string to screen.
                e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint);

                if (iTextHolder > this.ClientRectangle.Height + 25)
                {
                    iTextHolder = 25;
                }
                else
                {
                    iTextHolder = iTextHolder + 5;
                }

                return;
            }

            Bullet[] BulletArray = TheShip.BulletArray;
            // Move Ship
            if (TheShip.Active)
            {
                TheShip.Move();
                // check ship is not out of bounds
                TheShip.InRectangle(this.ClientRectangle);
            }
            // Move Bullets
            for (int i = 0; i < BulletArray.Length; i++)
            {
                // check if bullet is still in scope
                if (BulletArray[i] != null)
                {
                    if (BulletArray[i].Active)
                    {
                        BulletArray[i].Move();
                        // trim or reposition bullets
                        if (BulletArray[i].InRectangle(this.ClientRectangle))
                        {
                            BulletArray[i].Active = false;
                        }

                        // test ship & bullet collision
                        if (TheShip.Active)
                        {
                            if (BulletArray[i].IntersectsWith(TheShip.GetBounds(), TheShip.ShipImage))
                            {
                                BulletArray[i].Active = false;
                                TheShip.Active        = false;
                            }
                        }
                    }
                }
            }
            // Move Asteroids
            foreach (Asteroid A in AsteroidList)
            {
                A.Move();
                A.InRectangle(this.ClientRectangle);
            }

            // check for collisions
            for (int j = 0; j < AsteroidList.Count; j++)
            {
                Asteroid A = (Asteroid)AsteroidList[j];
                // if exploding nothing to do
                if (A.Exploding == false)
                {
                    // with bullets
                    for (int i = 0; i < BulletArray.Length; i++)
                    {
                        if (BulletArray[i] != null)
                        {
                            if (BulletArray[i].Active)
                            {
                                if (BulletArray[i].IntersectsWith(A.GetBounds(), A.AsteroidImage))
                                {
                                    A.Exploding = true;
                                    spawnMoreAsteroids(A);
                                    BulletArray[i].Active = false;
                                }
                            }
                        }
                    }

                    // with ship
                    if (TheShip.Active)
                    {
                        if (TheShip.IntersectsWith(A.GetBounds(), A.AsteroidImage))
                        {
                            A.Exploding = true;
                            spawnMoreAsteroids(A);
                            TheShip.Active = false;
                        }
                    }
                }
            }

            // trim any inactive asteroids
            for (int i = 0; i < AsteroidList.Count; i++)
            {
                Asteroid A = (Asteroid)AsteroidList[i];
                if (A.Active)
                {
                    A.Draw(g);
                }
                else
                {
                    AsteroidList.RemoveAt(i);
                }
            }

            for (int i = 0; i < BulletArray.Length; i++)
            {
                if (BulletArray[i] != null)
                {
                    if (BulletArray[i].Active)
                    {
                        BulletArray[i].Draw(g);
                    }
                }
            }

            if (TheShip.Active)
            {
                TheShip.DrawShip(g);
            }
        }