Example #1
0
 public void LoadContent(ContentManager content, Ufo ufo)
 {
     texture       = content.Load <Texture2D>("Shield");
     shieldSound   = content.Load <SoundEffect>("shieldsound");
     bounds.Width  = 65;
     bounds.Height = 70;
     bounds.X      = ufo.bounds.X - 7;
     bounds.Y      = ufo.bounds.Y - 10;
 }
Example #2
0
 protected void Restart()
 {
     numberOfAsteroids = 3;
     lost      = false;
     ufo       = new Ufo(this);
     shield    = new Shield(this);
     asteroids = new Asteroid[] { new Asteroid(this, random), new Asteroid(this, random), new Asteroid(this, random) };
     score     = 0;
     LoadContent();
 }
Example #3
0
 public Game1()
 {
     graphics = new GraphicsDeviceManager(this);
     Content.RootDirectory = "Content";
     //paddle = new Paddle(this);
     ufo               = new Ufo(this);
     shield            = new Shield(this);
     numberOfAsteroids = 3;
     asteroids         = new Asteroid[] { new Asteroid(this, random), new Asteroid(this, random), new Asteroid(this, random) };
     score             = 0;
 }
Example #4
0
        public void Update(GameTime gameTime, Ufo ufo)
        {
            var   keyboardState = Keyboard.GetState();
            float delta         = (float)gameTime.ElapsedGameTime.TotalSeconds;
            bool  keyflag       = false;

            bounds.X = ufo.bounds.X - 7;
            bounds.Y = ufo.bounds.Y - 10;

            if (keyboardState.IsKeyDown(Keys.Space))
            {
                // use shield
                if (!used)
                {
                    shieldSound.Play();
                }
                used   = true;
                timer2 = new TimeSpan(0);
            }

            if (used == true)
            {
                timer2 += gameTime.ElapsedGameTime;
            }


            timer += gameTime.ElapsedGameTime;
            if (timer2.TotalMilliseconds > ANIMATION_FRAME_RATE * 10)
            {
                used = false;
            }

            while (timer.TotalMilliseconds > ANIMATION_FRAME_RATE)
            {
                // increase by one frame
                frame++;
                // reduce the timer by one frame duration
                timer -= new TimeSpan(0, 0, 0, 0, ANIMATION_FRAME_RATE);
            }

            // Keep the frame within bounds (there are four frames)
            frame %= 4;
        }