コード例 #1
0
ファイル: mainPlayer.cs プロジェクト: Gkeane12/Gp3
        public mainPlayer(Vector3 Pos, Vector2 centre, float aspectRatio)
            : base(Pos)
        {
            currentlyEquipped = Weapons.none;

            for (int i = 0; i < bulletlist.Length; i++)
            {
                bulletlist[i] = new Bullet(Pos,100.0f);
                bulletlist[i].Active = false;
            }
            shortRange = new Bullet(Pos, 20.0f);
            LongRange = new Bullet(Pos, 1000.0f);
            shortRange.Active = false;
            LongRange.Active = false;
            available = Weapons.none;

            eyes = new Camera(Pos, Vector3.Zero, Vector3.Up, centre);
            eyes.setPerspectiveProjection(45.0f, aspectRatio, 2.0f, 1000.0f);
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: Gkeane12/Gp3
        /// <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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            keyboardState = Keyboard.GetState();
            mouseState = Mouse.GetState();
            Gamepad = GamePad.GetState(PlayerIndex.One);

            #region Universal userControl

            if (currentcState == controllerState.User)
            {
                if (keyboardState.IsKeyDown(Keys.Down))
                {
                    currentcState = controllerState.Debug;
                }
            }

            #endregion

            #region debug controls
            if (currentcState == controllerState.Debug)
            {
                if (keyboardState.IsKeyDown(Keys.D1))
                {
                    currentState = gameState.StartMenu;
                }

                if (keyboardState.IsKeyDown(Keys.D4))
                {
                    currentState = gameState.Game;
                }

                if (keyboardState.IsKeyDown(Keys.D0))
                {
                    currentcState = controllerState.User;
                }
                if (keyboardState.IsKeyDown(Keys.F))
                {
                    Fog = true;
                }
                if (keyboardState.IsKeyDown(Keys.D))
                {
                    Fog = false;
                }
                if(keyboardState.IsKeyDown(Keys.G))
                {
                    currentSubGame = subGameState.godSpeed;
                }
                if (keyboardState.IsKeyUp(Keys.U))
                {
                    player.available = mainPlayer.Weapons.LongRange;
                }

            }
            #endregion

            #region Difficulty
            if (currentState == gameState.DifficultySelect)
            {
                Hard.Active = true;
                Medium.Active = true;
                Hard.setText("Hard", Button.Width, Button.Height);
                Medium.setText("Medium", Button.Width, Button.Height);

                this.IsMouseVisible = true;
                if (mouseState.LeftButton == ButtonState.Pressed)
                {

                    Hard.CollisionCheck(mouseState, Button.Width, Button.Height);
                    Medium.CollisionCheck(mouseState, Button.Width, Button.Height);

                    if (Hard.Pressed == true)
                    {
                        Fog = true;
                        currentState = gameState.ControllerSelect;
                        Hard.Pressed = false;

                    }
                    if (Medium.Pressed == true)
                    {
                        Fog = false;
                        currentState = gameState.ControllerSelect;
                        Medium.Pressed = false;
                    }
                }
                Hard.Active = false;
                Medium.Active = false;
            }
            #endregion

            #region StartMenu
            if (currentState == gameState.StartMenu)
            {

                StartButton.setText("Start", Button.Width, Button.Height);
                StartButton.Active = true;
                this.IsMouseVisible = true;
                if (mouseState.LeftButton == ButtonState.Pressed)
                {

                    StartButton.CollisionCheck(mouseState, Button.Width, Button.Height);
                    if (StartButton.Pressed == true)
                    {
                        currentState = gameState.DifficultySelect;
                        StartButton.Pressed = false;
                        StartButton.Active = false;
                    }
                }
            }
            #endregion

            #region Controller selectScreen
            if (currentState == gameState.ControllerSelect)
            {

                ScreenSize = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
                if (Gamepad.Buttons.A == ButtonState.Pressed)
                {
                    currentcontroller = GameController.Joypad;
                    currentState = gameState.ControlLesson;

                }

                if (keyboardState.IsKeyDown(Keys.Enter))
                {
                    currentcontroller = GameController.Keyboard;
                    currentState = gameState.ControlLesson;
                }

            }
            #endregion

            #region ControlLesson
            if (currentState == gameState.ControlLesson)
            {

                if (keyboardState.IsKeyDown(Keys.S) || Gamepad.Buttons.B == ButtonState.Pressed)
                {
                    currentState = gameState.Game;
                }

            }

            #endregion

            #region GameState Game
            if (currentState == gameState.Game)
            {
                this.IsMouseVisible = false;
                #region Keyboard stuffs

                if (currentcontroller == GameController.Keyboard)
                {

                    if (keyboardState.IsKeyDown(Keys.B))
                    {
                        currentcamera = newcamera;
                    }

                    if (keyboardState.IsKeyDown(Keys.L))
                    {
                        currentcamera = player.eyes;
                    }

                    if (keyboardState.IsKeyDown(Keys.T))
                    {
                        currentcamera = thirdPerCamera;
                    }

                }
                #endregion

                for (int i = 0; i < redballoon.Length; i++)
                {
                    redballoon[i].update();
                }
                player.shortRange.update(player.Position);
                player.LongRange.update(player.Position);

                if (currentcontroller == GameController.Joypad)
                {
                    player.JoyPadControls(Gamepad);
                }

                if (currentcontroller == GameController.Keyboard)
                {
                    player.eyes.FPSController(mouseState, keyboardState);
                    player.Controls(keyboardState, mouseState);
                }
                player.update();

                //Third Person Camera is set
                thirdPerCamera.cPosition = (player.Position + thirdPerOffset);
                thirdPerCamera.setViewMatrix(thirdPerCamera.cPosition, player.Position, Vector3.Up);
                thirdPerCamera.FPSController(mouseState,  keyboardState);
                thirdPerCamera.Move(player.Position + thirdPerOffset);
                thirdPerCamera.update();

                if (currentSubGame == subGameState.godSpeed)
                {
                    Enemy.update();
                }

                counter = ("Number of Balloons:" + icounter);

                //This is where the Physics is carried out and collision are checked between all objects
                if (player.shortRange.Active == true)
                {
                    physics.addBullets(player.shortRange, 0);
                    for (int b = 0; b < redballoon.Length; b++)
                    {
                        if (redballoon[b].Active == true)
                        {
                            physics.addBalloons(redballoon[b], b);
                            if (physics.Bullets[0].Intersects(physics.balloons[b]))
                            {
                                player.shortRange.Destroy(player.Position);
                                redballoon[b].Active = false;
                                Pop.Play();
                                --icounter;

                            }
                        }
                    }
                    physics.addObject(BlueBalloon);
                    if (physics.Bullets[0].Intersects(physics.Char))
                    {
                        BlueBalloon.Active = false;
                        player.available = mainPlayer.Weapons.bullet;
                    }
                    physics.addObject(GreenBalloon);
                    if (physics.Bullets[0].Intersects(physics.Char))
                    {
                        GreenBalloon.Active = false;
                        player.available = mainPlayer.Weapons.LongRange;
                    }

                }

                if (player.LongRange.Active == true)
                {
                    physics.addBullets(player.LongRange, 0);
                    for (int b = 0; b < redballoon.Length; b++)
                    {
                        if (redballoon[b].Active == true)
                        {
                            physics.addBalloons(redballoon[b], b);
                            if (physics.Bullets[0].Intersects(physics.balloons[b]))
                            {
                                player.LongRange.Destroy(player.Position);
                                Pop.Play();
                                redballoon[b].Active = false;
                                --icounter;

                            }
                        }
                    }
                    physics.addObject(GoldBalloon);
                    if (physics.Bullets[0].Intersects(physics.Char))
                    {
                        GoldBalloon.Active = false; // only the long range gun can pop the gold balloon
                        currentState = gameState.GameEnd;
                    }

                }

                for (int i = 0; i < player.bulletlist.Length; i++)
                {
                    if (player.bulletlist[i].Active == true)
                    {
                        physics.addBullets(player.bulletlist[i], i);
                        for (int b = 0; b < redballoon.Length; b++)
                        {
                            if (redballoon[b].Active == true)
                            {
                                physics.addBalloons(redballoon[b], b);
                                if (physics.Bullets[i].Intersects(physics.balloons[b]))
                                {
                                    player.bulletlist[i].Destroy(player.Position);
                                    redballoon[b].Active = false;
                                    Pop.Play();
                                    --icounter;

                                }
                            }
                        }

                        physics.addObject(GreenBalloon);
                        if (physics.Bullets[i].Intersects(physics.Char))
                        {
                            GreenBalloon.Active = false;
                            player.available = mainPlayer.Weapons.LongRange;
                        }

                    }
                }

            #endregion

                base.Update(gameTime);
            }
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: Gkeane12/Gp3
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            screencentre = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2);

            Pop = Content.Load<SoundEffect>(".\\Sound\\BruitSec");
            Enemy = new Jets();
            for (int i = 0; i < Enemy.jets.Length; i++)
            {
                Enemy.jets[i].charModel = Content.Load<Model>(".\\Models\\balloonRed");
            }
            Jet = Content.Load<Model>(".\\Models\\eurofighter fbx");

            player = new mainPlayer(cameraPosition, screencentre, aspectRatio);
            player.charModel = Content.Load<Model>(".\\Models\\RedBalloon");

            newcamera = new Camera(campos2, Vector3.Zero, Vector3.Up, screencentre);
            newcamera.setPerspectiveProjection(45.0f, aspectRatio, 1.0f, 1000.0f);
            thirdPerCamera = new Camera(player.Position + thirdPerOffset, player.Position,Vector3.Up,screencentre);
            thirdPerCamera.setPerspectiveProjection(45.0f, aspectRatio , 1.0f, 1000.0f);

            physics = new Physics(player.bulletlist.Length, redballoon.Length);

            Font = Content.Load<SpriteFont>(".\\Fonts\\Basic");

            Button = Content.Load<Texture2D>(".\\Textures\\Button");
            StartButton = new GuiElements((screencentre - new Vector2(Button.Width - 100 ,Button.Height + 120)));
            Medium = new GuiElements((screencentre - new Vector2(Button.Width - 100, Button.Height - 120)));
            Hard = new GuiElements((screencentre - new Vector2(Button.Width - 100, Button.Height)));

            //Textures For Weapon Equip Gui
            WeaponGUI[0] = Content.Load<Texture2D>(".\\Textures\\KnifeSelected");
            WeaponGUI[1] = Content.Load<Texture2D>(".\\Textures\\KnifeUnSelected");
            WeaponGUI[2] = Content.Load<Texture2D>(".\\Textures\\GunSlelected");
            WeaponGUI[3] = Content.Load<Texture2D>(".\\Textures\\GunUnslelected");
            WeaponGUI[4] = Content.Load<Texture2D>(".\\Textures\\goldenBulletsel");
            WeaponGUI[5] = Content.Load<Texture2D>(".\\Textures\\goldenBulletUnsel");

            WeaponsState[0] = new GuiElements(new Vector2(screencentre.X - (2.0f * (WeaponGUI[0].Width) / 2), 350.0f));
            WeaponsState[1] = new GuiElements(new Vector2(screencentre.X -  (0.5f * (WeaponGUI[0].Width) / 2), 350.0f));
            WeaponsState[2] = new GuiElements ( new Vector2(screencentre.X +  (2.0f * (WeaponGUI[0].Width) / 2),350.0f));

            crosshair = Content.Load<Texture2D>(".\\Textures\\crosshair");
            crosshairpos = new Vector2((screencentre.X - (crosshair.Width / 2)), (screencentre.Y - (crosshair.Height / 2)));

            XboxController = Content.Load<Texture2D>(".\\Textures\\Contorller");
            controllerSelectScreem = Content.Load<Texture2D>(".\\Textures\\ControllerSelection");
            KeyBoardController = Content.Load<Texture2D>(".\\Textures\\keyboard");

            player.available = mainPlayer.Weapons.shortRange;

            currentcamera = player.eyes;

            icounter = 99;

            for (int i = 0; i < player.bulletlist.Length; i++)
            {
                player.bulletlist[i].charModel = Content.Load<Model>(".\\Models\\Bullet");
                player.bulletlist[i].charRotation += MathHelper.Pi;

            }

            player.shortRange.charModel = Content.Load<Model>(".\\Models\\Short");
            player.LongRange.charModel = Content.Load<Model>(".\\Models\\Untitled");

            for (int i = 0; i < redballoon.Length; i++)
            {

                balloonPos = new Vector3(random.Next(playfield), 0.0f, random.Next(playfield));
                redballoon[i] = new Luft(balloonPos);
                redballoon[i].charModel = Content.Load<Model>(".\\Models\\RedBalloon");

            }
            GreenBalloon = new Character( new Vector3(80.0f,40.0f,120.0f));
            GreenBalloon.charModel = Content.Load<Model>(".\\Models\\balloonGreen");
            BlueBalloon = new Character( new Vector3(120.0f,0.0f,80.0f));
            BlueBalloon.charModel = Content.Load<Model>(".\\Models\\balloonBlue");
            GoldBalloon = new Character(new Vector3( 0.0f, 110.0f, 0.0f));
            GoldBalloon.charModel = Content.Load<Model>(".\\Models\\balloonGold");

            //-------------------------------------------------------------
            // added to load Model
            //-------------------------------------------------------------

            aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;

            // TODO: use this.Content to load your game content here
        }