Ejemplo n.º 1
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>
        protected override void Initialize()
        {
            //set up content
            Content.RootDirectory = "Content";
            // Now with static constuctor so auto initalized on first access.
            //Viewports.setupViewports();

            SimpleRNG.SetSeedFromSystemTime();

#if DEBUG
            DebugSystem.Initialize(this, "FontA");
            //DebugSystem.Instance.FpsCounter.Visible = false;
            //DebugSystem.Instance.TimeRuler.Visible = false;
            DebugSystem.Instance.TimeRuler.ShowLog = true;
#endif

            MenuManager.Initialize();

            // MapManager.Initialize();

            shipSelect = new ShipSelect();

            //networkedGame = new NetworkedGame(this);
            //networkedGame.Enabled = false;
            //networkedGame.Visible = false;
            //networkedGame.Initialize();

            LiveServices.initializeGamerServices(this);

            Physics.Initialize();

            GameLoop.setGameStateAndResetPlayers(GameState.Menu);
            engine            = new AudioEngine("Content/XACT/BeatShift.xgs");
            GameLoop.menuBank = new SoundBank(engine, "Content\\XACT\\MusicTracks.xsb");
            GameLoop.wavBank  = new WaveBank(engine, "Content\\XACT\\SpaceMap.xwb");
            GameLoop.playTitle();
            bgm = new SoundTrack(140);
            bgm.LoadContent(Content, "bgm2");
            sfx = new SoundManager();
            sfx.LoadContent(Content);

            base.Initialize();

            LiveServices.gamerServices         = new GamerServicesComponent((Game)this);
            LiveServices.gamerServices.Enabled = false; //Updating manually
            Components.Add(LiveServices.gamerServices);

            //Disable bloom on Reach as it causes a texture-clamp/powerOfTwo error
            if (graphics.GraphicsProfile.Equals(GraphicsProfile.Reach))
            {
                Globals.PostProcess = false;
            }

            GC.Collect();
            //gamerServices.Initialize();

            //base.Initialize();
        }
Ejemplo n.º 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)
        {
            //DO NOT ADD CODE HERE
            currentTime = gameTime;
            GameLoop.Update(gameTime);
//#if DEBUG
            base.Update(gameTime); //Updates Game components. These should not be used. Currently used by DebugSystem and GamerServices.
//#endif
        }
Ejemplo n.º 3
0
 void returnToMenu()
 {
     if (networkSession != null)
     {
         networkSession.Dispose();
     }
     networkSession = null;
     started        = false;
     sessionType    = SessionType.None;
     GameLoop.setGameStateAndResetPlayers(GameState.Menu);
 }
Ejemplo n.º 4
0
        private void respondToButtonA(int i)
        {
            if (ssarea[i].input.actionTapped(InputAction.MenuAccept))
            {
                ssarea[i].setActive(true);
#if XBOX
                if (signedInPlayers[i] == 0)
                {
                    Guide.ShowSignIn(4, false);
                }
#endif
#if WINDOWS
                Race.humanRacers[i].shipDrawing.isVisible = true;
#endif
                GameLoop.setActiveControllers(true, i);
            }
        }
Ejemplo n.º 5
0
 private void respondToMenuBack(int i)
 {
     if (ssarea[i].input.actionTapped(InputAction.MenuBack))
     {
         if (ssarea[i].isActive)
         {
             ssarea[i].setActive(false);
             Race.humanRacers[i].shipDrawing.isVisible = false;
         }
         else if (!ssarea[0].isActive && !ssarea[1].isActive && !ssarea[2].isActive && !ssarea[3].isActive)
         {
             //Back button presed on inactive window, go back to main menu.
             GameLoop.setGameStateAndResetPlayers(GameState.Menu);
         }
         GameLoop.setActiveControllers(false, i);
     }
 }
Ejemplo n.º 6
0
        private void setupGameAndChangeState(GameTime gameTime)
        {
            //make sure physics loads
            //while (MapManager.currentMap.physicsLoadingThread.IsAlive) { }
            Race.isPrimed = false;
            //set input managers
            for (int k = 0; k < 4; k++)
            {
                Race.humanRacers[k].setupRacingControls(ssarea[k].input);
            }


            //Race.getFullListOfRacerIDsFromSignedInPeople();

            //If controller was not plugged-in/selected remove that player
            Race.removeNonVisibleRacers();

            GameLoop.setGameState(GameState.Menu);
            MenuManager.mainMenuSystem.setCurrentMenu(MenuPage.Loading);
        }
Ejemplo n.º 7
0
        protected void runStandardCountdown(GameTime gameTime, bool startOfRace, int countdownLength)
        {
            if (startOfRace == true)
            {
                countDownInt = countdownLength - countDownTimer.Elapsed.Seconds;
                switch (countDownInt)
                {
                case 3:
                    if (countdownState != GameTextures.Countdown3)
                    {
                        SoundManager.RaceStart(3);
                    }
                    countdownState = GameTextures.Countdown3;
                    break;

                case 2:
                    if (countdownState != GameTextures.Countdown2)
                    {
                        SoundManager.RaceStart(2);
                    }
                    countdownState = GameTextures.Countdown2;
                    break;

                case 1:
                    if (countdownState != GameTextures.Countdown1)
                    {
                        SoundManager.RaceStart(1);
                    }
                    countdownState = GameTextures.Countdown1;
                    break;
                }
            }
            else
            {
                countDownInt = countdownLength - endRaceTimer.Elapsed.Seconds;
            }

            if (countDownInt < 1)
            {
                if (startOfRace == true)
                {
                    if (countdownState != GameTextures.CountdownGo)
                    {
                        SoundManager.RaceStart(0);
                        SoundManager.raceBegan = true;
                    }
                    countDownRunning = false;
                    countDownTimer.Reset();
                    countdownState = GameTextures.CountdownGo;
                    // Call GO sound effect
                    // Call music sound effect

                    startRace();
                }
                else
                {
                    //SoundManager.RaceComplete();
                    GameLoop.endGame(gameTime);
                    endRaceTimer.Reset();
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// This is called when the game should draw itself.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 protected override void Draw(GameTime gameTime)
 {
     //DO NOT ADD CODE HERE
     GameLoop.Draw(gameTime);
     base.Draw(gameTime);
 }
Ejemplo n.º 9
0
        public void Draw(GameTime gameTime, CameraWrapper camera, Boolean isThisTheCamerasShip)
        {
            //TODO:
            //if playerType == PlayerType.None and this is not the camera belonging to this ship
            //Then return, we only want to draw ship selection ships to thier own camera


            Matrix viewMatrix       = camera.View;
            Matrix projectionMatrix = camera.Projection;

            BeatShift.graphics.GraphicsDevice.Viewport = camera.Viewport;

            //Set light to colour
            //shipClasses[(int)currentShip].shipRenderer.DiffuseColor = shipColour.ToVector3();
            //shipClasses[(int)currentShip].shipRenderer.DirectionalLight0.DiffuseColor = shipColour.ToVector3();

            //shipClasses[(int)currentShip].shipRenderer.View = viewMatrix;
            //shipClasses[(int)currentShip].shipRenderer.Projection = projectionMatrix;

            //world uses SRT matrix for scale rotation and translation of ship
            Matrix worldMatrix = getShipDrawOrientationMatrix();

            worldMatrix.Translation = getShipPosition();
            //shipClasses[(int)currentShip].shipRenderer.World = worldMatrix;

            if (((camera.ShouldDrawOwnShip || !isThisTheCamerasShip) && GameLoop.getCurrentState() == GameState.LocalGame) || isThisTheCamerasShip)
            {
                //Use high reflectivity when racer at lvl5
                if (parentRacer.beatQueue.getLayer() == 4)
                {
                    reflectOverride = MathHelper.Lerp(reflectOverride, 1.0f, 0.05f);
                }
                else
                {
                    reflectOverride = MathHelper.Lerp(reflectOverride, 0.0f, 0.2f);
                }

                //Draw ship using bShiftEffect.fx as instructed by the fbx file
                ShipFbx shipFbx = shipClasses[(int)currentShip];
                BeatShift.graphics.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
                foreach (ModelMesh mesh in shipFbx.model.Meshes)
                {
                    foreach (Effect effect in mesh.Effects)
                    {
                        if (shipFbx.isAnimated)
                        {
                            effect.CurrentTechnique = effect.Techniques["SkinnedShip"];
                            effect.Parameters["Bones"].SetValue(shipFbx.Bones);
                        }

                        effect.Parameters["world_Mx"].SetValue(worldMatrix);
                        effect.Parameters["wvp_Mx"].SetValue(worldMatrix * viewMatrix * projectionMatrix);

                        //Matrix worldInverseTranspose = Matrix.Transpose(Matrix.Invert(worldTransform));
                        //effect.Parameters["wit_Mx"].SetValue(worldInverseTranspose);

                        Matrix viewInverse = Matrix.Invert(viewMatrix);
                        effect.Parameters["viewInv_Mx"].SetValue(viewInverse);


                        effect.Parameters["useAmbient"].SetValue(Globals.useAmbient);
                        effect.Parameters["useLambert"].SetValue(Globals.useLambert);
                        effect.Parameters["useSpecular"].SetValue(Globals.useSpecular);
                        effect.Parameters["drawNormals"].SetValue(Globals.drawNormals);
                        effect.Parameters["reflectOverride"].SetValue(reflectOverride);
                    }
                    mesh.Draw();
                }
            }

            //if (Options.DrawShipBoundingBoxes)
            //{

            //    BeatShift.graphics.GraphicsDevice.BlendState = BlendState.AlphaBlend;
            //    shipPhysicsModelEffect.View = viewMatrix;
            //    shipPhysicsModelEffect.Projection = projectionMatrix;
            //    shipPhysicsModelEffect.World = worldMatrix;
            //    foreach (ModelMesh mesh in shipPhysicsModel.Meshes)
            //    {
            //        mesh.Draw();
            //    }
            //}

            if (Options.DrawShipBoundingBoxes)
            {
                foreach (D_Arrow arrow in drawArrowListRays)
                {
                    DrawVector.drawArrow(camera, arrow.pos, arrow.dir, arrow.col);
                }
                drawArrowListRays.Clear();
            }

            if (Globals.EnableParticles)
            {
                if (engineGlow != null)
                {
                    parentRacer.globalSystems.SetWorldViewProjectionMatricesForAllParticleSystems(Matrix.Identity, viewMatrix, projectionMatrix);
                    parentRacer.globalSystems.SetCameraPositionForAllParticleSystems(camera.cameraPosition());
                    parentRacer.globalSystems.DrawAllParticleSystems();
                    if (isThisTheCamerasShip && !parentRacer.raceTiming.hasCompletedRace)
                    {
                        //Draw visualizations with camera's view matrix, but with the visualization projection matrix
                        parentRacer.visualizationSystems.SetWorldViewProjectionMatricesForAllParticleSystems(Matrix.Identity, camera.VisualizationViewM, camera.VisualizationProjection);
                        parentRacer.visualizationSystems.SetCameraPositionForAllParticleSystems(camera.cameraPosition());
                        parentRacer.visualizationSystems.DrawAllParticleSystems();
                    }
                }
            }
            //if (Options.DrawCollisionPoints)
            {
                foreach (D_Arrow arrow in drawArrowListPermanent)
                {
                    DrawVector.drawArrow(camera, arrow.pos, arrow.dir, arrow.col);
                }
            }
            if (isThisTheCamerasShip && AiInputManager.testAI)
            {
                DrawVector.drawArrow(camera, getShipPosition(), aiWallRayArrow, aiWallRayHit ? new Vector3(255, 0, 0) : new Vector3(0, 0, 255));
                DrawVector.drawArrow(camera, getShipPosition(), aiFrontRayArrow, aiFrontRayHit ? new Vector3(200, 0, 50) : new Vector3(0, 50, 200));
            }
        }
Ejemplo n.º 10
0
        public static void Update(GameTime gameTime)
        {
#if DEBUG
            DebugSystem.Instance.TimeRuler.StartFrame();
#endif
            using (new ProfileSection("Background", Color.Blue))
            {
                // Check to see if the user has paused or unpaused
                BeatShift.bgm.Update();
                // Task music = Parallel.Start();
                if (currentState == GameState.LocalGame || currentState == GameState.NetworkedGame)
                {
                    checkPauseKey(gameTime);
                }

                checkPauseGuide();

#if XBOX
                checkControllers(gameTime);
#endif

                // If the user hasn't paused, Update normally

                LiveServices.Update(gameTime);

                //Update mainGameInput
                if (!LiveServices.GuideIsVisible())
                {
                    mainGameinput.Update(gameTime);
                }
            }

            if (!pausedForGuide)
            {
                MenuManager.Update(gameTime);
            }

            if (!paused)
            {
                Boolean raceUpdated = false;
                if (GameLoop.getCurrentState() == GameState.LocalGame)
                {
                    //IWork pudate = new IWork();
                    //particles = Parallel.Start(()=>BeatShift.particleManager.UpdateAllParticleSystems((float)gameTime.ElapsedGameTime.TotalSeconds));
                    //BeatShift.particleManager.UpdateAllParticleSystems((float)gameTime.ElapsedGameTime.TotalSeconds);
                }

                //Update all managed timers.
                RunningTimer.Update(gameTime);

                if (BeatShift.shipSelect.Enabled)
                {
                    BeatShift.shipSelect.Update(gameTime);
                }

                //if (networkedGame.Enabled) networkedGame.Update(gameTime);

                using (new ProfileSection("Physics", Color.Red))
                {
                    if (Physics.Enabled)
                    {
                        Physics.Update(gameTime);
                    }
                }


                using (new ProfileSection("Race", Color.Yellow))
                {
                    if (Race.Enabled)
                    {
                        Race.Update(gameTime);
                        raceUpdated = true;
                        HeadsUpDisplay.Update(gameTime);
                    }
                }


                //What??
                if (MapManager.Enabled && !raceUpdated)
                {
                    Race.Update(gameTime);
                }
            }


            //full screen option
#if WINDOWS
            //F4 press triggers fullscreen
            if (Keyboard.GetState().IsKeyDown(Keys.F4))
            {
                wasF4pressed = true;
            }
            if (wasF4pressed)
            {
                if (Keyboard.GetState().IsKeyUp(Keys.F4))
                {
                    wasF4pressed = false;
                    BeatShift.graphics.ToggleFullScreen();
                }
            }
#endif

#if DEBUG
            //Insert repeats last debug command if debug window shut
            if (DebugSystem.Instance.DebugCommandUI.isClosed())
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Insert))
                {
                    wasInsertPressed = true;
                }

                if (wasInsertPressed)
                {
                    if (Keyboard.GetState().IsKeyUp(Keys.Insert))
                    {
                        wasInsertPressed = false;
                        DebugSystem.Instance.DebugCommandUI.RepeatLastCommand();
                    }
                }
            }
#endif
            //music.Wait();


            BeatShift.engine.Update();
        }