/// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Move to the previous menu entry?
            if (input.IsMenuUp(ControllingPlayer))
            {
                sounds.playSoundEffect("move", 1);
                selectedEntry = (selectedEntry - 1 + menuEntries.Count) % menuEntries.Count; //Modulus FTW.
            }

            // Move to the next menu entry?
            if (input.IsMenuDown(ControllingPlayer))
            {
                sounds.playSoundEffect("move", 1);
                selectedEntry = (selectedEntry + 1) % menuEntries.Count;
            }

            // Accept or cancel the menu? We pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.
            PlayerIndex playerIndex;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                sounds.playSoundEffect("cancel", 1);
                OnCancel(playerIndex);
            }
        }
예제 #2
0
 /// <summary>
 /// Event handler for when the Play Game menu entry is selected.
 /// </summary>
 void PlayGameMenuEntrySelected(object sender, PlayerIndexEventArgs e)
 {
     MediaPlayer.Stop();
     sounds.playSoundEffect("playgame", 1);
     LoadingScreen.Load(ScreenManager, true, e.PlayerIndex, new GameplayScreen());
 }
예제 #3
0
        public override void Update(GameTime gameTime)
        {
            currentWeapon.Update(gameTime, position, rotation);
            if (currentWeapon is Shield)
            {
                Shield s = currentWeapon as Shield;
                s.UpdateWeapFirePosition(Position, Rotation);
            }
            currFireTime       = currFireTime.Subtract(gameTime.ElapsedGameTime);
            betweenDodge       = betweenDodge.Subtract(gameTime.ElapsedGameTime);
            invincibleTime     = invincibleTime.Subtract(gameTime.ElapsedGameTime);
            pressedPowerUpTime = pressedPowerUpTime.Subtract(gameTime.ElapsedGameTime);
            if (isInvincible)
            {
                flickerTime = flickerTime.Subtract(gameTime.ElapsedGameTime);
            }
            if (invincibleTime.TotalSeconds <= 0)
            {
                isInvincible = false;
            }
            if (isPoweredUp)
            {
                powerUpTime = powerUpTime.Subtract(gameTime.ElapsedGameTime);
            }
            if (powerUpTime.TotalSeconds <= 0)
            {
                isPoweredUp = false;
                currentWeapon.CurrentLevel = 0;
            }
            if (cameraEnabled)
            {
                if (!bossMode)
                {
                    Camera.Instance.UpdateCamera(CameraStaticPosition, Vector3.Zero);
                }
                else
                {
                    Camera.Instance.UpdateCamera(position, Vector3.UnitY * rotation.Y);
                }
            }
            sphere   = new BoundingSphere(position, 6);
            worldMat = Matrix.CreateScale(0.1f) * Matrix.CreateRotationY(rotation.Y) * Matrix.CreateRotationZ(rotation.Z) * Matrix.CreateTranslation(position);

            if (!controls.Locked)
            {
                velocity = controls.UpdatePlayerMovement(position, rotation);
            }
            else
            {
                if (initialLock)
                {
                    velocity = new Vector3(0, 0, 1.3f);
                    if (position.Z > 0)
                    {
                        // controls.Locked = false;
                        velocity    = Vector3.Zero;
                        initialLock = false;
                    }
                }
            }

            if (velocity.X != 0.0f && velocity.Z != 0.0f)
            {
                velocity /= (float)Math.Sqrt(2); // don't want diagonal speed to be faster
            }

            if (bossMode)
            {
                oldPos = position;
            }

            if (bossMode && !controls.Locked) //move around the boss when going left/right
            {
                if (velocity.X != 0)
                {
                    velocity = getRotationVelocityAroundPoint(velocity, bossCenter);
                }
            }
            #region Player dodge logic
            if (controls.isPlayerDodgingLeft())
            {
                pressedDodgeLeft  = true;
                pressedDodgeRight = false;
            }
            if (controls.isPlayerDodgingRight())
            {
                pressedDodgeRight = true;
                pressedDodgeLeft  = false;
            }

            if (pressedDodgeLeft && !pressedDodgeRight)
            {
                if (betweenDodge.TotalSeconds <= 0)
                {
                    dodgeTime = dodgeTime.Subtract(gameTime.ElapsedGameTime);
                    if (dodgeTime.TotalSeconds > 0)
                    {
                        velocity = Vector3.UnitX * 5;
                    }
                    else
                    {
                        pressedDodgeLeft = false;
                        dodgeTime        = TimeSpan.FromSeconds(dodgeTimeSeconds);
                        betweenDodge     = TimeSpan.FromSeconds(betweenDodgeSeconds);
                    }
                }
            }

            if (pressedDodgeRight && !pressedDodgeLeft)
            {
                if (betweenDodge.TotalSeconds <= 0)
                {
                    dodgeTime = dodgeTime.Subtract(gameTime.ElapsedGameTime);
                    if (dodgeTime.TotalSeconds > 0)
                    {
                        velocity = -Vector3.UnitX * 5;
                    }
                    else
                    {
                        pressedDodgeRight = false;
                        dodgeTime         = TimeSpan.FromSeconds(dodgeTimeSeconds);
                        betweenDodge      = TimeSpan.FromSeconds(betweenDodgeSeconds);
                    }
                }
            }
            #endregion

            position += velocity;
            #region Player rotation while moving
            if (velocity.X < 0)
            {
                if (rotation.Z == 0 || rotation.Z > MathHelper.ToRadians(180))
                {
                    rotate(new Vector3(0, 0, MathHelper.ToRadians(3)));
                }
                else
                {
                    if (rotation.Z > 0 && rotation.Z <= MathHelper.ToRadians(180))
                    {
                        if (rotation.Z < MathHelper.ToRadians(30))
                        {
                            rotate(new Vector3(0, 0, MathHelper.ToRadians(3)));
                        }
                    }
                }
            }
            else if (velocity.X > 0)
            {
                if (rotation.Z == 0 || rotation.Z > 0 && rotation.Z <= MathHelper.ToRadians(180))
                {
                    rotate(new Vector3(0, 0, -MathHelper.ToRadians(3)));
                }
                else
                {
                    if (rotation.Z > MathHelper.ToRadians(180))
                    {
                        if (rotation.Z > MathHelper.ToRadians(330))
                        {
                            rotate(new Vector3(0, 0, -MathHelper.ToRadians(3)));
                        }
                    }
                }
            }
            else
            {
                if (rotation.Z > 0 && rotation.Z <= MathHelper.ToRadians(180))
                {
                    rotate(new Vector3(0, 0, -MathHelper.ToRadians(3)));
                }
                else if (rotation.Z > MathHelper.ToRadians(180))
                {
                    rotate(new Vector3(0, 0, MathHelper.ToRadians(3)));
                }
                if (MathHelper.ToDegrees(rotation.Z) < 3)
                {
                    rotation.Z = 0;
                }
            }
            #endregion

            if (position.X > 60)
            {
                position.X = 60;
            }
            if (position.X < -60)
            {
                position.X = -60;
            }

            if (!controls.Locked)
            {
                if (position.Z < -40)
                {
                    position.Z = -40;
                }
                if (position.Z > 40)
                {
                    position.Z = 40;
                }
            }

            if (controls.isPlayerFiring())
            {
                //is the player allowed to fire again since his last fire?
                if (currFireTime.TotalSeconds <= 0)
                {
                    //Reset current time
                    currFireTime = TimeSpan.FromTicks(currentWeapon.FireTime.Ticks);
                    fire();
                }
            }

            if (controls.isPlayerUsingPowerup())
            {
                if (pressedPowerUpTime.TotalSeconds <= 0)
                {
                    if (!isPoweredUp)
                    {
                        if (powerup < 394)
                        {
                            playerAVC.playSoundEffect("cancel", 1);
                        }
                        else
                        {
                            isPoweredUp = true;
                            powerUpTime = TimeSpan.FromSeconds(powerupTimeSeconds);
                            if (powerup >= 394 && powerup < 788)
                            {
                                currentWeapon.CurrentLevel = 1;
                                powerup -= 394;
                            }
                            else if (powerup >= 788 && powerup < 1182)
                            {
                                currentWeapon.CurrentLevel = 2;
                                powerup -= 788;
                            }
                            else
                            {
                                currentWeapon.CurrentLevel = 3;
                                powerup -= 1182;
                            }
                        }
                    }
                    pressedPowerUpTime = TimeSpan.FromSeconds(pressedPowerUpTimeSeconds);
                }
            }
            if (Game1.debug)
            {
                if (controls.isPlayerPowering(gameTime))
                {
                    if (currentWeapon.CurrentLevel < 3)
                    {
                        currentWeapon.CurrentLevel++;
                    }
                    else
                    {
                        currentWeapon.CurrentLevel = 0;
                    }
                }

                if (controls.isPlayerSwitching(gameTime))
                {
                    int loc = Array.IndexOf(weapList, currentWeapon.Name.ToString());
                    if (loc < weapList.Length - 1)
                    {
                        changeWeapon((PlayerWeaponName)Enum.Parse(typeof(PlayerWeaponName), weapList[loc + 1], true));
                    }
                    else
                    {
                        changeWeapon((PlayerWeaponName)Enum.Parse(typeof(PlayerWeaponName), weapList[0], true));
                    }
                }
            }
        }