예제 #1
0
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            //Load the game font and HUD font
            gameFont = content.Load<SpriteFont>("gamefont");
            HUDfont = content.Load<SpriteFont>("HUDFont");
            //Load background music
            BGM[0] = soundBank.GetCue("BGM1");
            BGM[1] = soundBank.GetCue("BGM2");
            BGM[2] = soundBank.GetCue("BGM3");
            BGM[3] = soundBank.GetCue("BGM4");
            BGM[4] = soundBank.GetCue("BGM5");
            BGM[5] = soundBank.GetCue("BGM6");
            BGM[6] = soundBank.GetCue("BGM7");
            BGM[7] = soundBank.GetCue("BGM8");
            BGM[8] = soundBank.GetCue("BGM9");
            //Set Powerup Textures and Music Player Textures
            Expander = content.Load<Texture2D>("Expander");
            Decreaser = content.Load<Texture2D>("Decreaser");
            AcidBall = content.Load<Texture2D>("AcidBall");
            GoldenBall = content.Load<Texture2D>("GoldenBall");
            BiggerBall = content.Load<Texture2D>("BigBall");
            SmallerBall = content.Load<Texture2D>("SmallBall");
            AddLife = content.Load<Texture2D>("AddLife");

            tMusicPlayer = content.Load<Texture2D>("MusicPlayer");
            tMusicPlayerOff = content.Load<Texture2D>("MusicPlayerOff");
            //Instantiate multiple models for Ball,Block and Player model arrays
            mBall = new Model[5];
            mBlock = new Model[4];
            mPlayer = new Model[3];
            //Load the afformentioned models into content
            mPlayer[0] = content.Load<Model>("Models/Player");
            mPlayer[1] = content.Load<Model>("Models/BigPlayer");
            mPlayer[2] = content.Load<Model>("Models/SmallPlayer");

            mArena = content.Load<Model>("Models/Arena");
            mKillZone = content.Load <Model>("Models/KillZone");

            mBall[0] = content.Load<Model>("Models/NormalBall");
            mBall[1] = content.Load <Model>("Models/AcidBall");
            mBall[2] = content.Load<Model>("Models/GoldBall");
            mBall[3] = content.Load<Model>("Models/BigBall");
            mBall[4] = content.Load<Model>("Models/SmallBall");

            mBlock[0] = content.Load<Model>("Models/BlockLvl1");
            mBlock[1] = content.Load<Model>("Models/BlockLvl2");
            mBlock[2] = content.Load<Model>("Models/BlockLvl3");
            mBlock[3] = content.Load<Model>("Models/BlockUnbreakable");

            //Create 30 blocks to be destroyed
            Blocks = new cls3DObject[30];
            //Create a new arena
            Arena = new cls3DObject(1, new Vector3(20f, 2f, 40f), true, graphicsDevice, WorldMatrix);
            //Create the music player animation
            MusicPlayer = new clsDrops(15, tMusicPlayer, new Vector2(435, 133), new Vector2(155, 24), Vector2.Zero, 4);
            MusicPlayer.Show();

            //Add models to various instantiated objects
            Arena.AddModel(ref mArena, 0);

            for (int i = 0; i < Blocks.Length; i++)
            {
                Blocks[i] = new cls3DObject(4, new Vector3(2, 1, 1), true, graphicsDevice, WorldMatrix);
                Blocks[i].AddModel(ref mBlock[0], 0);
                Blocks[i].AddModel(ref mBlock[1], 1);
                Blocks[i].AddModel(ref mBlock[2], 2);
                Blocks[i].AddModel(ref mBlock[3], 3);
            }

            Player = new cls3DObject(3, new Vector3(2.5f, 2, 2), true, graphicsDevice, WorldMatrix);
            Player.AddModel(ref mPlayer[0], 0);
            Player.AddModel(ref mPlayer[1], 1);
            Player.AddModel(ref mPlayer[2], 2);

            Ball = new cls3DObject(5, new Vector3(0.5f, 0.5f, 0.5f), true, graphicsDevice, WorldMatrix);
            Ball.AddModel(ref mBall[0], 0);
            Ball.AddModel(ref mBall[1], 1);
            Ball.AddModel(ref mBall[2], 2);
            Ball.AddModel(ref mBall[3], 3);
            Ball.AddModel(ref mBall[4], 4);

            KillZone = new cls3DObject(1, new Vector3(20f, 1, 3f), true, graphicsDevice, WorldMatrix);
            KillZone.AddModel(ref mKillZone, 0);
            HealthViewer = new cls3DObject(1, new Vector3(3f, 2, 2), true, graphicsDevice, WorldMatrix);
            HealthViewer.AddModel(ref mPlayer[0], 0);

            //Prepare game for first play
            Arena.SetPosition(new Vector3(-10, 0, -20));
            Arena.SetRotation(new Vector3(0, 0, 0));

            if (GameType <= 0)
            {
                Level = 0;
                Player.SetHealth(3);
                GetLevelLayout();
            }
            else
            {
                for (int i = 0; i < Blocks.Length; i++)
                Blocks[i].Hide();
                numtoshow = Blocks.Length -1;
                Player.SetHealth(0);
                GetAssaultLayout();
            }

            Player.SetPosition(new Vector3(-1,0,16));
            SetPlayerCarry = true; Ball.SetPosition(new Vector3(Player.GetPosition().X + (Player.GetSize().X / 2), Ball.GetPosition().Y, 14.5f));
            KillZone.SetPosition(new Vector3(-10,-1,20));
            HealthViewer.SetScale(0.5f);

               Thread.Sleep(1000);
            ScreenManager.Game.ResetElapsedTime();
        }
예제 #2
0
        public override void HandleInput(InputState input)
        {
            //if no input, throw exception
            if (input == null)
                throw new ArgumentNullException("input");
            //playerindex is the controlling player
            int playerIndex = (int)ControllingPlayer.Value;
            //set new keyboard and controller state objects
            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];
            //set a new boolean as the current connection state of the game pad
            bool gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected[playerIndex];
            //of the gamepad is disconnected or the game is paused then then
            //pause the game
            if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected)
                ScreenManager.AddScreen(PauseMenu, ControllingPlayer);
            //if game is not paused
            else
            {
                //Check if controller should be vibrating, vibrate it
                //Otherwise remove vibration
                if (Vibrate)
                    GamePad.SetVibration(ControllingPlayer.Value, 0.5f, 0.5f);
                else
                    GamePad.SetVibration(ControllingPlayer.Value, 0, 0);

                //if the left trigger or left alt key is held down then switch to top
                //down view
                if (gamePadState.Triggers.Left > 0 || keyboardState.IsKeyDown(Keys.LeftAlt))
                {
                    if (!CamPressed)
                    {
                        if (isTopDown)
                        {
                            Cam.MainCam();
                            isTopDown = false;
                        }
                        else
                        {
                            Cam.TopDown();
                            isTopDown = true;
                        }
                        CamPressed = true;
                    }
                }
                else
                    CamPressed = false;
                //update the camera
                Cam.Update();

                //Set the player velocity to either the X value of the left
                //thumbstick or the left or right key
                Player.SetVelocity(new Vector3(0.2f * gamePadState.ThumbSticks.Left.X, 0, 0));

                if (keyboardState.IsKeyDown(Keys.Left))
                    Player.SetVelocity(new Vector3(-0.2f, 0, 0));
                if (keyboardState.IsKeyDown(Keys.Right))
                    Player.SetVelocity(new Vector3(0.2f, 0, 0));

                //if the player collides with the arena or the player collides with
                //the ball with a velocity*2 then stop the player
                if (Player.InternalCollision(Arena) || Player.ExternalCollision(Ball, 2))
                    Player.SetVelocity(Vector3.Zero);

                //if the player is carrying the ball and either the A button or
                //space bar is pressed then the ball is released
                if (SetPlayerCarry && gamePadState.IsButtonDown(Buttons.A) || SetPlayerCarry && keyboardState.IsKeyDown(Keys.Space))
                {
                    if (Ball.GetPosition() == new Vector3(Player.GetPosition().X + (Player.GetSize().X / 2), Ball.GetPosition().Y, 14.5f))
                    {
                        Ball.SetVelocity(new Vector3(0.15f, 0, -0.15f));
                        Ball.SetSpeed(Ball.GetVelocity().X + -Ball.GetVelocity().Z);
                        SetPlayerCarry = false;
                    }
                }

                //if the background music is not being changed and the right shoulder
                //button or the W key is pressed then pause the current song, and
                //go to the next one. set the background music to being changed.
                //also check if the song is at the end in which case set to first
                //song again
                if (!SwitchCue)
                {
                    if (gamePadState.IsButtonDown(Buttons.RightShoulder)||keyboardState.IsKeyDown(Keys.W))
                    {
                        if (!PauseCue)
                        {
                            SwitchCue = true;
                            BGM[currentcue].Pause();
                            if (currentcue < BGM.Length - 1)
                                currentcue++;
                            else
                                currentcue = 0;
                        }
                    }
                    //if the background music is not being changed and the left shoulder
                    //button or the Q key is pressed then pause the current song, and
                    //go to the previous one. set the background music to being changed.
                    //also check if the song is at the beginning in which case set to the
                    //last song again
                    if (gamePadState.IsButtonDown(Buttons.LeftShoulder) || keyboardState.IsKeyDown(Keys.Q))
                    {
                        if (!PauseCue)
                        {
                            SwitchCue = true;
                            BGM[currentcue].Pause();
                            if (currentcue != 0)
                                currentcue--;
                            else
                                currentcue = BGM.Length - 1;
                        }
                    }
                }
                    //if the song is being changed and all song modifier buttons are released
                    //then set the song to not being changed
                else
                    if (gamePadState.IsButtonUp(Buttons.RightShoulder) && gamePadState.IsButtonUp(Buttons.LeftShoulder) && keyboardState.IsKeyUp(Keys.Q) && keyboardState.IsKeyUp(Keys.W))
                        SwitchCue = false;

                //if the music is not off and down on the dpad or the A key is pressed
                //then turn off the music and change the music animation to something that looks off
                if (!PauseCue)
                {
                    if (gamePadState.IsButtonDown(Buttons.DPadDown) || keyboardState.IsKeyDown(Keys.A))
                    {
                        PauseCue = true;
                        MusicPlayer = new clsDrops(15, tMusicPlayerOff, new Vector2(435, 133), new Vector2(155, 24), Vector2.Zero, 0);
                        MusicPlayer.Show();
                    }
                }
                //if the music is turned off and up on the dpad or the S key is press
                 //then turn on the music and change the music animation to something that looks on
                else
                {
                    if (gamePadState.IsButtonDown(Buttons.DPadUp) || keyboardState.IsKeyDown(Keys.S))
                    {
                        PauseCue = false;
                        MusicPlayer = new clsDrops(15, tMusicPlayer, new Vector2(435, 133), new Vector2(155, 24), Vector2.Zero, 4);
                        MusicPlayer.Show();
                    }
                }

            }
        }