예제 #1
0
        /// <summary>
        /// Get where the gun of the player's ship is
        /// </summary>
        /// <param name="playerIndex"></param>
        /// <returns></returns>
        public static Vector2 GetGunLocationForPlayer(Player player)
        {
            switch (player.Index)
            {
                case PlayerIndex.One:
                    return new Vector2(player.Location.X + (280 * player.Scale.X), player.Location.Y + (230 * player.Scale.Y));

                case PlayerIndex.Two:
                    return new Vector2(player.Location.X + (170 * player.Scale.X), player.Location.Y + (220 * player.Scale.Y));
            }

            return player.Location;
        }
        /// <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)
        {
            context.IsActive = this.IsActive;
            context.InputManager.StartUpdate();

            PlayerIndex disconnectedIndex = PlayerIndex.Four;

            if (context.Player1 != null)
            {
                padsOk = context.InputManager.CheckIfPadIsConnectedForPlayer(context.Player1);
                disconnectedIndex = context.Player1.Index;
            }
            else
            {
                padsOk = true;
            }
            if (context.Player2 != null)
            {
                padsOk &= context.InputManager.CheckIfPadIsConnectedForPlayer(context.Player2);
                disconnectedIndex = context.Player1.Index;
            }

            if (!padsOk)
            {
                darkening = 0.95f;

                if (TGPAContext.Instance.CurrentGameState == GameState.Game)
                {
                    if (TGPAContext.Instance.Map.Ended == Map.EndMode.None)
                    {
                        paused = true;
                    }

                }
                context.PausingPlayerIndex = disconnectedIndex;
            }

            #if WINDOWS
            //Get mouse location
            mouseXY = new Point(Mouse.GetState().X, Mouse.GetState().Y);
            #endif

            #if XBOX
            CheckSignedOut();
            #endif
            if (context.CurrentGameState == GameState.None)
            {
                splashScreen.Update(gameTime);
            }
            //*********************************************************************************
            // Device selection screen
            //*********************************************************************************
            else
            {
                context.SongInfo.Update();

                //*********************************************************************************
                // Title screen
                //*********************************************************************************
                if (context.CurrentGameState == GameState.TitleScreen)
                {
                    context.ParticleManager.Clear();

                    GamePad.SetVibration(PlayerIndex.One, 0f, 0f);
                    GamePad.SetVibration(PlayerIndex.Two, 0f, 0f);

                    titleScreen.Update(gameTime);
                }
                //*********************************************************************************
                // Level Selection screen
                //*********************************************************************************
                else if (context.CurrentGameState == GameState.LevelSelectionScreen)
                {
                    GamePad.SetVibration(PlayerIndex.One, 0f, 0f);
                    GamePad.SetVibration(PlayerIndex.Two, 0f, 0f);

                    levelSelectionScreen.Update(gameTime);
                }
                //*********************************************************************************
                // Loading screen
                //*********************************************************************************
                else if (context.CurrentGameState == GameState.Loading)
                {
                    GamePad.SetVibration(PlayerIndex.One, 0f, 0f);
                    GamePad.SetVibration(PlayerIndex.Two, 0f, 0f);

                    loadingLayer.Update(gameTime);
                }
                //*********************************************************************************
                // Credit screen
                //*********************************************************************************
                else if (context.CurrentGameState == GameState.Credits)
                {
                    GamePad.SetVibration(PlayerIndex.One, 0f, 0f);
                    GamePad.SetVibration(PlayerIndex.Two, 0f, 0f);

                    creditScreen.Update(gameTime);
                }
                //*********************************************************************************
                // End demo screen
                //*********************************************************************************
                else if (context.CurrentGameState == GameState.DemoEnd)
                {
                    GamePad.SetVibration(PlayerIndex.One, 0f, 0f);
                    GamePad.SetVibration(PlayerIndex.Two, 0f, 0f);

                    demoEndScreen.Update(gameTime);
                }
                //*********************************************************************************
                // The game
                //*********************************************************************************
                else if (context.CurrentGameState == GameState.Game)
                {
                    //If the game isn't on focus or if gamepad is disconnected the code far below will not be executed
                    if (!IsActive)
                    {
                        if (context.Player1 != null)
                        {
                            context.InputManager.SetVibrations(PlayerIndex.One, Vector2.Zero);
                            context.Player1.UpdateRumbles(gameTime);
                        }
                        if (context.Player2 != null)
                        {
                            context.InputManager.SetVibrations(PlayerIndex.Two, Vector2.Zero);
                            context.Player2.UpdateRumbles(gameTime);
                        }

                        //Put game in pause
                        if (this.context.CurrentGameState == GameState.Game)
                        {
                            if (context.Map.Ended == Map.EndMode.None)
                            {
                                this.paused = true;
                            }
                        }
                    }

                    if (context.Map.StartTime <= 0)
                        context.Map.StartTime = gameTime.TotalGameTime.TotalMilliseconds;

                    if (paused)
                    {
                        darkening += 0.05f;
                        if (darkening > 0.8f) darkening = 0.8f;

                        UpdatePlayerPause(gameTime, context.PausingPlayerIndex);

                        if (context.Cheatcodes.Active)
                        {
                            context.Cheatcodes.Update(gameTime);
                        }
                    }
                    else
                    {
                        //Particles
                        context.ParticleManager.UpdateParticles((float)gameTime.ElapsedGameTime.TotalSeconds);

                        UpdateMap(context.Map.Background1, gameTime);
                        UpdateMap(context.Map.Background2, gameTime);
                        UpdateMap(context.Map.Background3, gameTime);

                        if (context.Map.Ended != Map.EndMode.Lose)
                        {
                            UpdatePlayer(gameTime, PlayerIndex.One);

                            if (context.Player2 != null)
                            {
                                UpdatePlayer(gameTime, PlayerIndex.Two);
                            }
                            else
                            {
                                if (tmpPlayer2 != null)
                                {
            #if XBOX
                                    if (Gamer.SignedInGamers.Count >= 2)
                                    {
            #endif
                                        Logger.Log(LogLevel.Info, "Adding player 2 on device " + tmpPlayer2.Device);

                                        context.Player2 = new Player(PlayerIndex.Two, tmpPlayer2.Device);
                                        this.tmpPlayer2 = null;
                                        InitializeP2();
            #if XBOX
                                        context.Player2.Name = context.Player2.XboxProfile.Gamertag;
            #else
                                    context.Player2.Name = LocalizedStrings.GetString("Guest");
            #endif
                                        //Take one live to player 1
                                        int initLives = context.Player1.Lives;
                                        context.Player1.Lives -= 1;
                                        context.Player2.Lives = context.Player1.Lives;
            #if XBOX
                                    }
                                    else
                                    {
                                        if (!Guide.IsVisible)
                                        {
                                            tmpPlayer2 = null;
                                        }
                                    }
            #endif
                                }
                                else if (context.Player1.Lives > 1)
                                {
                                    //Scan if P2 pressed Start Button
                                    Device newPlayerDevice = context.InputManager.Player2JoinedTheGame(context.Player1);

                                    //Player 2 joined the game !
                                    if (newPlayerDevice != null)
                                    {
                                        //Create variable
                                        this.tmpPlayer2 = new Player(PlayerIndex.Two, newPlayerDevice);
            #if XBOX
                                        //Force sign in on XBOX
                                        if ((!this.paused) && (Device.DeviceHasProfile(newPlayerDevice) == false))
                                        {
                                            this.paused = true;
                                            this.context.PausingPlayerIndex = PlayerIndex.One;
                                            Guide.ShowSignIn(2, false);
                                        }
            #endif
                                    }
                                }
                            }
                        }
                        else
                        {//Rumble update
                            context.Player1.Update(gameTime);

                            if (context.Player2 != null)
                                context.Player2.Update(gameTime);
                        }

                        UpdateShots(gameTime);

                        //Scripts
                        List<Event> eventsToDelete = new List<Event>();

                        for (int i = 0; i < context.Map.Events.Count; i++)
                        {
                            //Run
                            if ((Math.Abs(context.Map.Events[i].ScrollValue.X) - Math.Abs(context.Map.Scroll.X) <= 0)
                             && (Math.Abs(context.Map.Events[i].ScrollValue.Y) - Math.Abs(context.Map.Scroll.Y) <= 0))
                            {
                                context.Map.Events[i].PlayEvent(gameTime);
                            }

                            //Delete ended scripts
                            if (context.Map.Events[i].IsEnded)
                            {
                                eventsToDelete.Add(context.Map.Events[i]);
                            }

                        }

                        foreach (Event e in eventsToDelete)
                            context.Map.Events.Remove(e);

                        UpdateEnemies(gameTime);

                        UpdateBonuses(gameTime);

                        //Scores
                        foreach (FlyingScores fs in flyScores)
                        {
                            fs.Update(gameTime);
                        }

                        //End level ?
                        if (context.Map.Ended != Map.EndMode.None)
                        {
                            endLevelScreen.Update(gameTime);
                        }

                        if (darkening > 0.0f)
                        {
                            darkening -= 0.2f;
                            if (darkening < 0.0f) darkening = 0f;
                        }

                        //HUD
                        context.Hud.Update(gameTime);

                        //Clear lists every 5 sec
                        if (true)
                        {
                            foreach (BadGuy bg in enemiesToDelete)
                            {
                                context.Enemies.Remove(bg);
                            }
                            enemiesToDelete.Clear();

                            foreach (Shot shiot in shotsToDelete)
                            {
                                context.Shots.Remove(shiot);
                            }
                            shotsToDelete.Clear();
                        }
                    }
                }
                else if (context.CurrentGameState == GameState.Exit)
                {
                    this.Exit();
                }

                SoundEngine.Instance.Update(gameTime);
            }
            base.Update(gameTime);

            context.InputManager.EndUpdate();
        }