public void Update(Game game,ContentManager content, SpriteBatch spriteBatch, SpriteFont font, Player playerOne, List<Sprite> enemies, EnemyShots enemyShots, PlayerShots playerShots, List<Sprite> randomObjects, List<HealthBar> healthBars, Sprite playerOneSprite, GraphicsDeviceManager graphics, Player playerTwo = null, Sprite playerTwoSprite = null)
        {
            this.enemies = enemies;
            this.enemyShots = enemyShots;
            this.playerShots = playerShots;
            this.playerOneSprite = playerOneSprite;
            this.dinosaurOne = playerOne;
            this.playerTwoSprite = playerTwoSprite;
            this.dinosaurTwo = playerTwo;
            _halfScreenHeight = graphics.PreferredBackBufferHeight / 1.5f;

            gdm = graphics;
            sb = spriteBatch;
            cm = content;

            explosionSound = cm.Load<SoundEffect>("Sounds/explosion");
            laserPowerupSound = cm.Load<SoundEffect>("Sounds/Few");
            healthPowerupSound = cm.Load<SoundEffect>("Sounds/Few");
            enemyHit = cm.Load<SoundEffect>("Sounds/Few");
            playerHit = cm.Load<SoundEffect>("sounds/Punch");

            if (!playerOneSprite.IsInvincible)
            {
                CheckIfEnemyHitsPlayer();
            }

            CheckIfPowerupHitsPlayer();

            CheckIfPlayerHitSomething(game, spriteBatch, content, healthBars);

            checkIfPlayerIsHitByGroundItem(randomObjects);
        }
        public void Update(KeyboardState state, Sprite player, Player dino, PlayerShots playerShots, GraphicsDeviceManager graphics, GameTime gameTime, GameState gameState)
        {
            _oldKeyPressed = _currentKeyPressed;
            _currentKeyPressed = state;

            _movement = Vector2.Zero;

            if (dino.PlayerIndex == PlayerIndex.One)
            {
                if ((_currentKeyPressed.IsKeyDown(Keys.A) || _currentKeyPressed.IsKeyDown(Keys.Left)) && player.Position.X > 50)
                {
                    _movement -= Vector2.UnitX * .7f;
                }
                if ((_currentKeyPressed.IsKeyDown(Keys.D) || _currentKeyPressed.IsKeyDown(Keys.Right)) && player.Position.X < graphics.PreferredBackBufferWidth - 50)
                {
                    _movement += Vector2.UnitX * .7f;
                }
                if ((_currentKeyPressed.IsKeyDown(Keys.W) || _currentKeyPressed.IsKeyDown(Keys.Up)) && player.Position.Y > (graphics.PreferredBackBufferHeight / 2) + 100)
                {
                    _movement -= Vector2.UnitY * .5f;
                }
                if ((_currentKeyPressed.IsKeyDown(Keys.S) || _currentKeyPressed.IsKeyDown(Keys.Down)) && player.Position.Y < graphics.PreferredBackBufferHeight - player.Texture.Height)
                {
                    _movement += Vector2.UnitY * .5f;
                }
            }
            else if (dino.PlayerIndex == PlayerIndex.Two)
            {
                if (_currentKeyPressed.IsKeyDown(Keys.L) && player.Position.X > 50)
                {
                    _movement -= Vector2.UnitX * .7f;
                }
                if (_currentKeyPressed.IsKeyDown(Keys.OemQuotes)&& player.Position.X < graphics.PreferredBackBufferWidth - 50)
                {
                    _movement += Vector2.UnitX * .7f;
                }
                if (_currentKeyPressed.IsKeyDown(Keys.P) && player.Position.Y > (graphics.PreferredBackBufferHeight / 2) + 100)
                {
                    _movement -= Vector2.UnitY * .5f;
                }
                if (_currentKeyPressed.IsKeyDown(Keys.OemSemicolon) && player.Position.Y < graphics.PreferredBackBufferHeight - player.Texture.Height)
                {
                    _movement += Vector2.UnitY * .5f;
                }
            }

            // Jamie Key
            if(_currentKeyPressed.IsKeyDown(Keys.J) && !_oldKeyPressed.IsKeyDown(Keys.J))
            {
                if (dino._laserPowerLevel < 5)
                    dino._laserPowerLevel += 1;
                else
                    dino._laserPowerLevel = 1;
            }

            if (_currentKeyPressed.IsKeyDown(Keys.Space) || _currentKeyPressed.IsKeyDown(Keys.F) || _currentKeyPressed.IsKeyDown(Keys.Enter))
            {
                if (dino.LaserCharge > 0)
                {

                    if (dino.PlayerIndex == PlayerIndex.One)
                    {
                        if (_currentKeyPressed.IsKeyDown(Keys.F) || _currentKeyPressed.IsKeyDown(Keys.Space))
                        {
                            playerShots.FireOne(dino);
                            dino._currentCharge -= 1;
                        }
                    }
                    else if (dino.PlayerIndex == PlayerIndex.Two)
                    {
                        if (_currentKeyPressed.IsKeyDown(Keys.Enter))
                        {
                            playerShots.FireTwo(dino);
                            dino._currentCharge -= 1;
                        }
                    }
                }
            }

            if (player.IsInMarsh)
            {
                player.Movement += _movement / 3;
            }
            else
            {
                player.Movement += _movement;
            }
            player.Update(gameTime);
            _movement.X = 0f;
            _movement.Y = 0f;
            player.Movement = _movement;
            player.Update(gameTime);
        }
示例#3
0
        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            gameState = GameState.TitleScreen;
            previousState = gameState;

            upgradeScreen = null;
            startScreen = null;
            characterScreen = null;
            multiplayerLobby = null;
            deathScreen = null;
            levelBeginning = null;
            pauseScreen = null;
            loadingScreen = null;

            levelCreator = null;

            Random rand = new Random();
            currentLevel = null;

            enemies = null;
            explosions = null;
            shotBehavior = null;
            enemyShots = null;
            playerShots = null;
            hbOne = null;
            hbTwo = null;
            bossLifeBar = null;
            cbOne = null;
            cbTwo = null;
            backGroundMusic = null;
            playerOneMeterTitle = null;
            playerTwoMeterTitle = null;
            meterLabel = null;
            playerOneMarker = null;
            playerTwoMarker = null;

            dinosaurOne = null;
            dinosaurTwo = null;
            playerOneSprite = null;
            playerTwoSprite = null;
            collisions = null;
            font = null;

            playerOneCounter = 0;
            playerTwoCounter = 0;
            levelIncrement = 0;

            singlePlayer = false;
            explodedOne = false;
            explodedTwo = false;

            input = null;
            padInput = null;
        }
示例#4
0
        protected void LoadCharacter()
        {
            if (startScreen.SinglePlayer)
            {
                singlePlayer = true;
                dinosaurOne = new Player(Content, graphics, characterScreen.Character, 1);
                dinosaurOne.ControlScheme = startScreen.ControlScheme;

                ValidateCharacter(1);

                playerOneSprite.Position = new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight - 250);
            }
            else if (startScreen.MultiPlayer)
            {
                singlePlayer = false;
                dinosaurOne = new Player(Content, graphics, multiplayerLobby.playerOne, 1);
                dinosaurTwo = new Player(Content, graphics, multiplayerLobby.playerTwo, 2);
                dinosaurOne.ControlScheme = multiplayerLobby.firstPlayerControl;
                dinosaurTwo.ControlScheme = multiplayerLobby.secondPlayerControl;

                ValidateCharacter(1);
                ValidateCharacter(2);

                playerOneSprite.Position = new Vector2(graphics.PreferredBackBufferWidth / 3, graphics.PreferredBackBufferHeight - 250);
                playerTwoSprite.Position = new Vector2(graphics.PreferredBackBufferWidth - (graphics.PreferredBackBufferWidth / 3), graphics.PreferredBackBufferHeight - 250);
            }

            playerShots = new PlayerShots(Content, dinosaurOne, playerOneSprite, dinosaurTwo, playerTwoSprite);
            shotBehavior = new ShotBehavior(Content);
            enemyShots = new EnemyShots(Content);

            CreateScreens();
            GenerateLevel();
        }
        public void Update(GamePadState state, Sprite player, Player dino, PlayerShots playerShots, GraphicsDeviceManager graphics, GameTime gameTime, GameState gameState)
        {
            _oldInput = _currentInput;
            _currentInput = state;

            _movement = Vector2.Zero;

            if ((_currentInput.IsButtonUp(Buttons.LeftThumbstickRight)) && player.Position.X > 50)
            {
                _movement -= Vector2.UnitX * .7f;
            }
            if ((_currentInput.IsButtonUp(Buttons.LeftThumbstickLeft)) && player.Position.X < graphics.PreferredBackBufferWidth - 50)
            {
                _movement += Vector2.UnitX * .7f;
            }
            if ((_currentInput.IsButtonUp(Buttons.LeftThumbstickDown)) && player.Position.Y > (graphics.PreferredBackBufferHeight / 2) + 100)
            {
                _movement -= Vector2.UnitY * .5f;
            }
            if ((_currentInput.IsButtonUp(Buttons.LeftThumbstickUp)) && player.Position.Y < graphics.PreferredBackBufferHeight - player.Texture.Height)
            {
                _movement += Vector2.UnitY * .5f;
            }

            // Jamie Key
            if (_currentInput.IsButtonDown(Buttons.Y) && !_oldInput.IsButtonDown(Buttons.Y))
            {
                if (dino._laserPowerLevel < 5)
                    dino._laserPowerLevel += 1;
                else
                    dino._laserPowerLevel = 1;
            }

            if (_currentInput.Buttons.A  == ButtonState.Pressed)
            {
                if (dino.LaserCharge > 0)
                {
                    dino._currentCharge -= 1;

                    if (dino.PlayerIndex == PlayerIndex.One)
                    {
                        playerShots.FireOne(dino);
                    }
                    else if (dino.PlayerIndex == PlayerIndex.Two)
                    {
                        playerShots.FireTwo(dino);
                    }
                }
            }

            if (player.IsInMarsh)
            {
                player.Movement += _movement / 3;
            }
            else
            {
                player.Movement += _movement;
            }
            player.Update(gameTime);
            _movement.X = 0f;
            _movement.Y = 0f;
            player.Movement = _movement;
            player.Update(gameTime);
        }