Example #1
0
 private void AddUpgradeObjects()
 {
     // Randomly generate the position of the upgrade object
     Vector2 position = new Vector2(random.Next(250, 750), 10);
     //Vector2 position = new Vector2(random.Next(100, GraphicsDevice.Viewport.Width - 100), GraphicsDevice.Viewport.Height - upgradeObjectTexture.Height / 2); // 50, and -50 represent the area in which they spawn (higher the number the smaller the area, closer to center)
     UpgradeObject upgradeObject = new UpgradeObject();
     upgradeObject.Initialize(GraphicsDevice.Viewport, upgradeObjectTexture, position);
     upgradeObjects.Add(upgradeObject);
     /*
     if (levelUp == true)
     {
         upgradeObject.Value = upgradeObject.Value + 10;
         upgradeObject.upgradeObjectMoveSpeed = upgradeObject.upgradeObjectMoveSpeed + 5;
     }
     */
 }
Example #2
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)
        {
            KeyboardState keys = Keyboard.GetState();

            if(startScreenIsOn == true)
            {
                if (keys.IsKeyDown(Keys.Enter))
                {
                    startScreenIsOn = false;
                    LoadContent();
                }
            }

            if(endScreenIsOn == true)
            {
                if (keys.IsKeyDown(Keys.Escape))
                {
                    Initialize();
                }
            }

            if (startScreenIsOn == false && endScreenIsOn == false)
            {
                // Allows the game to exit
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                    this.Exit();

                // Save the previous state of the keyboard and game pad so we can determinesingle key/button presses
                // previousGamePadState = currentGamePadState;
                previousKeyboardState = currentKeyboardState;

                // Read the current state of the keyboard and gamepad and store it
                currentKeyboardState = Keyboard.GetState();
                //currentGamePadState = GamePad.GetState(PlayerIndex.One);

                UpgradeObject upgradeObject2 = new UpgradeObject();
                Enemy enemy2 = new Enemy();
                Projectile projectile2 = new Projectile();

                UpdateUpgradeSprite(gameTime);

                //Update the player
                UpdatePlayer(gameTime);

                // Update the parallaxing background
                bgLayer1.Update();
                //bgLayer2.Update();

                // Update the enemies
                UpdateEnemies(gameTime);

                if (score >= metScore)
                {
                    levelChange();
                }

                UpdateCollision();

                // Update the projectiles
                UpdateProjectiles();

                UpdateUpgradeObjects(gameTime);

                // Update the explosions
                UpdateExplosions(gameTime);

                base.Update(gameTime);
            }
        }