예제 #1
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            // 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)
                return;

            if (ShouldPauseGame())
            {
                ScreenManager.ShowScreen<PauseMenuScreen>();
                soundManager.PauseSong();
                soundManager.StopAllSounds();

                for (int i = 0; i < Cars.Count; i++)
                {
                    Cars[i].stopSteeringSound();
                }

                    return;
            }

            if (Logic.isGameOver() && RankScreen != null)
            {
                soundManager.StopAllSounds();
                for (int i = 0; i < Cars.Count; i++)
                {
                    Cars[i].stopSteeringSound();
                }

                RankScreen.UpdateRankings(Cars);
                ScreenManager.ShowScreen<RankingScreen>();
                RankScreen = null;
                return;
            }

            if (cameraFollowing.raceCanStart && readyToStart)
            {
                readyToStart = false;
                for (int i = 0; i < Cars.Count; i++)
                {
                    Cars[i].isActive = true;
                    Cars[i]._compound.IsStatic = false;
                }
            }

            UpdateCars(gameTime);

            UpdateObstacles();

            UpdateGameLogic();

            UpdateCamera(gameTime);

            world.Step(Math.Min((float)gameTime.ElapsedGameTime.TotalSeconds, (1f / 30f)));

            updateFluidParameters(gameTime);

            mySneezesManager.Update(gameTime,Cars);

            if (Keyboard.GetState().IsKeyDown(Keys.F)) fluid.saveDensity();

            if (Keyboard.GetState().IsKeyDown(Keys.D0)) Cars[0].setPowerup(0);
            if (Keyboard.GetState().IsKeyDown(Keys.D1)) Cars[0].setPowerup(1);
            if (Keyboard.GetState().IsKeyDown(Keys.D2)) Cars[0].setPowerup(2);
            if (Keyboard.GetState().IsKeyDown(Keys.D3)) Cars[0].setPowerup(3);
            if (Keyboard.GetState().IsKeyDown(Keys.D4)) Cars[0].setPowerup(4);
            if (Keyboard.GetState().IsKeyDown(Keys.D5)) Cars[0].setPowerup(5);
            if (Keyboard.GetState().IsKeyDown(Keys.D6)) Cars[0].setPowerup(6);
        }
예제 #2
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>
        public GameScreen()
        {
            firstTime = true;

            TransitionOnTime = TimeSpan.FromSeconds(1.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);

            RankScreen = new RankingScreen();
            RankScreen.Accepted += RankScreenAccepted;
            PauseScreen = new PauseMenuScreen();

            polygonsList = new List<PolygonPhysicsObject>();
            Cars = new List<Car>();
            playerIndexes = new List<PlayerIndex>();
            playerIndexes.Add(PlayerIndex.One); playerIndexes.Add(PlayerIndex.Two);
            playerIndexes.Add(PlayerIndex.Three); playerIndexes.Add(PlayerIndex.Four);
            Random = new Random(DateTime.Now.Millisecond);

            PlayersCount = 4;
            startingPos = new Vertices();

            readyToStart = false;
            aabbVerts = new Vector2[4];
            activeBodiesCount = 0;
            startingPosAabbVerts = new Vector2[4];

            particleComponent = GameServices.GetService<ParticleComponent>();

            collisionsQuotes = collisionsQuotesNormal;

            dummyTexture = new Texture2D(GameServices.GetService<GraphicsDevice>(), 1, 1);
            byte whiteAlpha = 50;
            Color dummyTextureColor = new Color(whiteAlpha, whiteAlpha, whiteAlpha);
            dummyTexture.SetData(new Color[] { dummyTextureColor });

            mySneezesManager = new SneezesManager();

            obstaclesLoop = 0;
        }