Esempio n. 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()
        {
            // Set Some Variables
            float padX  = 24; // Paddle Width
            float padY  = 64; // Paddle Height
            float ballD = 32; // Ball Diameter
            Random rnd = new Random();

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load the SoundEffect resource
            walls = Content.Load<SoundEffect>("VOLTAGE");
            miss  = Content.Load<SoundEffect>("neat");
            win   = Content.Load<SoundEffect>("score");
            lose  = Content.Load<SoundEffect>("miss");
            killshot = Content.Load<SoundEffect>("killshot");

            // Load files built from XACT project
            audioEngine = new AudioEngine("Content\\Lab3Sounds.xgs");
            waveBank    = new WaveBank(audioEngine, "Content\\Wave Bank.xwb");
            soundBank   = new SoundBank(audioEngine, "Content\\Sound Bank.xsb");

            // Load streaming wave bank
            streamingWaveBank = new WaveBank(audioEngine, "Content\\Music.xwb", 0, 4);
            // The audio engine must be updated before the streaming cue is ready
            audioEngine.Update();
            // Get cue for streaming music
            musicCue = soundBank.GetCue("EricJordan_2012_30sec");
            // Start the background music
            musicCue.Play();

            // Load Font
            Font1 = Content.Load<SpriteFont>("Courier New");

            // Load a 2D texture sprite
            ball     = new clsSprite(Content.Load<Texture2D>("volt-ball-final"),
                            new Vector2(winX/2, winY/2), new Vector2(ballD, ballD),
                            winX, winY);
            opponent = new clsSprite(Content.Load<Texture2D>("vt_left_paddle"),
                            new Vector2(10, winY/2 - padY), new Vector2(padX, padY),
                            winX, winY);
            player   = new clsSprite(Content.Load<Texture2D>("vt_right_paddle"),
                            new Vector2(winX - (10+padX), winY / 2 - padY), new Vector2(padX, padY),
                            winX, winY);
            // Create a SpriteBatch to render the sprite
            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);

            // Set the velocity of the ball sprites will move
            ball.velocity = new Vector2(rnd.Next(3,6), rnd.Next(-5, 6));
        }
Esempio n. 2
0
 public bool CircleCollides(clsSprite otherSprite)
 {
     //  Check if two circle sprites collided
     return (Vector2.Distance(this.center, otherSprite.center) < this.radius +
     otherSprite.radius);
 }
Esempio n. 3
0
 public int Collides(clsSprite otherSprite)
 {
     int hit = 0;
     // check if two sprites intersect
     if (this.position.X + this.size.X > otherSprite.position.X &&
         this.position.X < otherSprite.position.X + otherSprite.size.X &&
         this.position.Y + this.size.Y > otherSprite.position.Y &&
         this.position.Y < otherSprite.position.Y + otherSprite.size.Y) {
         if (this.position.Y < otherSprite.position.Y + 6 ||
             this.position.Y > otherSprite.position.Y + otherSprite.size.Y - 6)
             hit = 2;
         else
             hit = 1;
     }
     return hit;
 }
Esempio n. 4
0
 public Vector2 Midpoint(clsSprite other)
 {
     return new Vector2((this.position.X + other.position.X) / 2,
         (this.position.Y + other.position.Y) / 2);
 }