Пример #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            //Initialize cannon . Need 5 of this.

            background = Content.Load <Texture2D>("background");

            //smallBall.velocity = new Vector2(10.1f, 10.1f);
            //Draw cannon
            cannon = new cannon(Content.Load <Texture2D>("cannon"),
                                new Vector2(graphics.GraphicsDevice.Viewport.Width / 10, graphics.GraphicsDevice.Viewport.Height / 1.15f));
            //Draw small ball
            for (int i = 0; i < maxBullet; i++)
            {
                Bullet[i] = new ball(Content.Load <Texture2D>("cannonball"),
                                     new Vector2(cannon.position.X, cannon.position.Y - 20f), new Vector2(54f, 54f),
                                     graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            }
            //Draw Alien
            float height = 0f;
            int   column = 0;

            for (int i = 0; i < maxAlien; i++)
            {
                AlienArmy[i] = new alien(Content.Load <Texture2D>("enemy"),
                                         new Vector2(graphics.PreferredBackBufferWidth / 2 - 150 * (column + 1), graphics.PreferredBackBufferHeight / 5 + height), new Vector2(121f, 40f),
                                         graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
                Console.WriteLine("{0},{1}", graphics.PreferredBackBufferWidth / 2 - 150 * (column + 1),
                                  graphics.PreferredBackBufferHeight / 5 + height);
                //Set up grid for alien ship
                if (i >= 4 && column >= 4)
                {
                    column = 0;
                    height = 80f;
                    continue;
                }
                column++;
            }
            //Load sound effect
            missleLaunch = Content.Load <SoundEffect>("missilelaunch");
            explosion    = Content.Load <SoundEffect>("explosion");
        }
Пример #2
0
 public void FireBall(ball objectBall)
 {
     if (!objectBall.ballAlive)
     {
         //Set ball alive
         objectBall.ballAlive = true;
         //This allows the cannonball to be shot from the middle of the cannon.
         objectBall.position = position - objectBall.center;
         //Set velocity and direction of the ball
         objectBall.velocity = new Vector2(
             (float)Math.Cos(rotation),
             (float)Math.Sin(rotation)) * 10f;
     }
     //Move ball when alive
     if (objectBall.ballAlive)
     {
         objectBall.Move(objectBall.velocity);
     }
 }