Пример #1
0
        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, false);

            // Gradually fade in or out depending on whether we are covered by the pause screen.
            if (coveredByOtherScreen)
                pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1);
            else
                pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0);

            if (IsActive)
            {
                // HANDLE GAME OVER LOGIC HERE
                if (cowboy.Health <= 0 && cowboy.Revives <= 0 && world.SpeedCoeff == 1)
                    ScreenManager.AddScreen(new GameOverScreen((PlayerIndex)ControllingPlayer, null, cowboy, null, actionBgm), ControllingPlayer);

                // Update world and its elements
                world.Update(gameTime);
                // Update inputC (circular dead zone input state)
                inputC.Update(GamePadDeadZone.Circular);
                // Update player1 camera
                if (cowboy.CarDriving == null && cowboy.Health > 0)
                {
                    // normal cam
                    p1Cam.Update(gameTime, p1CamFocus, ScreenManager.Viewport);
                    p1Cam.Rotation = 0;
                    p1Cam.Zoom = 1;
                    // clamp camera within world
                    p1Cam.Pos = Vector2.Clamp(p1Cam.Pos,
                        Vector2.Zero + new Vector2(ScreenManager.Viewport.Width, ScreenManager.Viewport.Height) / 2 - new Vector2(100, 100),
                        world.WorldSize - new Vector2(ScreenManager.Viewport.Width, ScreenManager.Viewport.Height) / 2 + new Vector2(100, 100));
                }
                else if (cowboy.Health > 0)
                {
                    // driving cam
                    p1Cam.Update(gameTime, cowboy.CarDriving.Position + cowboy.CarDriving.CarDirection * ((cowboy.CarDriving.Gear == FAZEngine.Vehicles.Gearbox.D) ? 750 : -750), ScreenManager.Viewport);
                    p1Cam.Rotation = -cowboy.CarDriving.CarRotation;
                    p1Cam.Zoom = 0.5f;
                }
                else
                {
                    // death cam
                    p1Cam.Update(gameTime, cowboy.Position, ScreenManager.Viewport);
                    p1Cam.Zoom = 1.5f;
                    p1Cam.Rotation = 0.2f;
                }

                // Update status display
                statusDisplay.Update(gameTime, p1Cam);

                // TEMPORARY SPAWNERS
                if (cowboy.Health > 0)
                    timeSinceLastZombie += (int)(gameTime.ElapsedGameTime.Milliseconds * world.SpeedCoeff);
                if (timeSinceLastZombie > timeToSpawnZombie || world.enemyList.Count < 12)
                {
                    timeSinceLastZombie -= timeToSpawnZombie;
                    if (world.enemyList.Count < 120)
                    {
                        int numZombieSpawns = Math.Max(3, (cowboy.KillCount) / 100 % 30);
                        for (int i = 0; i < numZombieSpawns; i++)
                        {
                            Texture2D textureToUse = random.Next(2) == 0 ? zombieSheetTexture : zombieSheetTexture2;
                            Zombie zom = new Zombie(cowboy.Position + Vector2Extensions.RotateVector(cowboy.Direction, (float)random.NextDouble() * MathHelper.TwoPi) * 1700, random.Next(90, 180), textureToUse, world);
                            zom.ChangeMaxHealth(100 + (cowboy.KillCount) / 15);
                            world.enemyList.Add(zom);
                        }
                        if (random.Next(11) == 0)
                        {
                            // check if there are evil cowboys in enemylist
                            int evilCowboysInWorld = 0;
                            foreach (Enemy e in world.enemyList)
                            {
                                EvilCowboy ec = e as EvilCowboy;
                                if (ec != null) evilCowboysInWorld++;
                            }
                            if (evilCowboysInWorld < 2)
                            {
                                EvilCowboy evilCowboy = new EvilCowboy(cowboy.Position + Vector2Extensions.RotateVector(cowboy.Direction, (float)random.NextDouble() * MathHelper.TwoPi) * 1700, evilCowboySheetTexture, world);
                                evilCowboy.ChangeMaxHealth(evilCowboy.MaxHealth + (cowboy.KillCount) / 3);
                                world.enemyList.Add(evilCowboy);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, false);

            // Gradually fade in or out depending on whether we are covered by the pause screen.
            if (coveredByOtherScreen)
                pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1);
            else
                pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0);

            if (IsActive)
            {
                // HANDLE GAME OVER LOGIC HERE
                if (p1.Health <= 0 && p1.Revives <= 0 && p2.Health <= 0 && p2.Revives <= 0 && world.SpeedCoeff == 1)
                    ScreenManager.AddScreen(new GameOverScreen(p1Index, p2Index, p1, p2, actionBgm), null);

                // Update world and its elements
                world.Update(gameTime);
                // Update inputC (circular dead zone input state)
                inputC.Update(GamePadDeadZone.Circular);

                // Update playerCameras
                for (int i = 0; i < 2; i++)
                {
                    Player playerActive = (i == 0) ? p1 : p2;
                    ChasingCamera2D playerCam = (i == 0) ? p1Cam : p2Cam;
                    Viewport playerViewport = (i == 0) ? p1Viewport : p2Viewport;
                    if (playerActive.CarDriving == null && playerActive.Health > 0)
                    {
                        // normal cam
                        playerCam.Update(gameTime, (i == 0) ? p1CamFocus : p2CamFocus, (i == 0) ? p1Viewport : p2Viewport);
                        playerCam.Rotation = 0;
                        playerCam.Zoom = 0.8f;
                        // clamp the camera within world
                        playerCam.Pos = Vector2.Clamp(playerCam.Pos,
                            Vector2.Zero + new Vector2(playerViewport.Width, playerViewport.Height) / playerCam.Zoom / 2 - new Vector2(100, 100),
                            world.WorldSize - new Vector2(playerViewport.Width, playerViewport.Height) / playerCam.Zoom / 2 + new Vector2(100, 100));

                    }
                    else if (playerActive.Health > 0)
                    {
                        // driving cam
                        playerCam.Update(gameTime, playerActive.CarDriving.Position + playerActive.CarDriving.CarDirection * ((playerActive.CarDriving.Gear == FAZEngine.Vehicles.Gearbox.D) ? 600 : -600), (i == 0) ? p1Viewport : p2Viewport);
                        playerCam.Rotation = -playerActive.CarDriving.CarRotation;
                        playerCam.Zoom = 0.4f;
                    }
                    else
                    {
                        // death cam
                        playerCam.Update(gameTime, playerActive.Position, (i == 0) ? p1Viewport : p2Viewport);
                        playerCam.Zoom = 1.4f;
                        if (playerActive.Revives <= 0) playerCam.Rotation += 0.001f;
                        else playerCam.Rotation = 0.2f;
                    }

                    // Update status display
                    if (i == 0) p1StatDisplay.Update(gameTime, p1Cam);
                    else p2StatDisplay.Update(gameTime, p2Cam);
                }

                // Updates Revive Timer if they are out of revives
                if ((p1.Health <= 0 && p1.Revives <= 0) || (p2.Health <= 0 && p2.Revives <= 0))
                {
                    if (p1.Health > 0 || p2.Health > 0)
                        reviveTimer += (int)(gameTime.ElapsedGameTime.Milliseconds * world.SpeedCoeff);
                    if (reviveTimer > timeToRevive)
                    {
                        reviveTimer = 0;
                        if (p1.Health <= 0 && p1.Revives <= 0) p1.Gain1Revive();
                        else p2.Gain1Revive();
                    }
                }

                // SHARE LIVES?
                if (OptionsMenuScreen.shareRevives)
                {
                    if (p1.Revives + p2.Revives >= 1)
                    {
                        if (p1.Revives <= 0 && p2.Revives > 0 && p1.Health <= 0 && p2.Health > 0) { p1.Gain1Revive(); p2.Lost1Revive(); }
                        else if (p2.Revives <= 0 && p1.Revives > 0 && p2.Health <= 0 && p1.Health > 0) { p2.Gain1Revive(); p1.Lost1Revive(); }
                    }
                }

                // TEMPORARY SPAWNERS
                if (p1.Health > 0 || p2.Health > 0)
                    timeSinceLastZombie += (int)(gameTime.ElapsedGameTime.Milliseconds * world.SpeedCoeff);
                if (timeSinceLastZombie > timeToSpawnZombie || world.enemyList.Count < 16)
                {
                    timeSinceLastZombie -= timeToSpawnZombie;
                    if (world.enemyList.Count < 200)
                    {
                        int numZombieSpawns = Math.Max(3, (p1.KillCount + p2.KillCount) / 100 % 30);
                        for (int i = 0; i < numZombieSpawns; i++)
                        {
                            Texture2D textureToUse = random.Next(2) == 0 ? zombieSheetTexture : zombieSheetTexture2;
                            Zombie zom = new Zombie(p1.Position + Vector2Extensions.RotateVector(p1.Direction, (float)random.NextDouble() * MathHelper.TwoPi) * 5000, random.Next(90, 180), textureToUse, world);
                            zom.ChangeMaxHealth(100 + (p1.KillCount + p2.KillCount) / 10);
                            world.enemyList.Add(zom);
                        }
                        if (random.Next(11) == 0)
                        {
                            int evilCowboysInWorld = 0;
                            foreach (Enemy e in world.enemyList)
                            {
                                EvilCowboy ec = e as EvilCowboy;
                                if (ec != null) evilCowboysInWorld++;
                            }
                            if (evilCowboysInWorld < 3)
                            {
                                EvilCowboy evilCowboy = new EvilCowboy(p1.Position + Vector2Extensions.RotateVector(p1.Direction, (float)random.NextDouble() * MathHelper.TwoPi) * 5000, evilCowboySheetTexture, world);
                                evilCowboy.ChangeMaxHealth(evilCowboy.MaxHealth + (p1.KillCount + p2.KillCount) / 3);
                                world.enemyList.Add(evilCowboy);
                            }
                        }
                    }
                }
            }
        }