Beispiel #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Random r = new Random(DateTime.Now.Second);

            // TODO: Add your initialization logic here
            for (int i = 0; i < numCities; i++)
            {
                cities[i]              = new City();
                cities[i].color        = CityColors[r.Next(CityColors.Length - 1)];
                cities[i].shield.color = ShieldColors[r.Next(ShieldColors.Length - 1)];
            }

            missileInitialPosition = new Vector2(100, 100);
            missileFinalPosition   = new Vector2(groundLevel, 100);
            tmpMissile             = new BallisticMissile(0, missileInitialPosition, missileFinalPosition);

            base.Initialize();

            missilePlayArea = new Rectangle(-BUFFER_MISSILE_SIDE, -BUFFER_MISSILE_TOP, graphics.PreferredBackBufferWidth + (2 * BUFFER_MISSILE_SIDE), graphics.PreferredBackBufferHeight + BUFFER_MISSILE_TOP - BUFFER_GROUND_LEVEL_BOTTOM);
            tmpMissile.setMisslePlayArea(missilePlayArea);
        }
Beispiel #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.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            {
                for (int i = 0; i < numCities; i++)
                {
                    cities[i].Draww(this.spriteBatch, cities[i].color);
                }

                for (int i = 0; i < missiles.Count; i++)
                {
                    tmpMissile = (BallisticMissile)missiles[i];
                    tmpMissile.Draw(this.spriteBatch, missileColor);
                }
            }
            //missiles[i].Draw(this.spriteBatch, missileColor); //, missiles.slope);
            spriteBatch.End();

            base.Draw(gameTime);
        }
Beispiel #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here
            if (numMissiles < maxNumMissiles)
            {
                tmpMissile = new BallisticMissile(missileSpeedTotal, missileInitialPosition, missileFinalPosition);
                tmpMissile.setMisslePlayArea(missilePlayArea);
                missiles.Add(tmpMissile);
            }

            for (int i = 0; i < missiles.Count; i++)
            {
                tmpMissile = (BallisticMissile)missiles[i];
                tmpMissile.Update(gameTime);
            }

            base.Update(gameTime);
        }