Ejemplo n.º 1
0
        public void ResetLevelCommand()
        {
            Player1Camera.Limits = level.LevelAreas[0];
            _backgroundP1        = new Background(spriteBatch, Player1Camera, BackgroundType.Overworld);

            if (Mode == GameMode.MultiPlayer)
            {
                Player2Camera.Limits = level.LevelAreas[0];
                _backgroundP2        = new Background(spriteBatch, Player2Camera, BackgroundType.Overworld);
            }

            gameGrid.ClearGrid();
            SoundPool.Instance.Reset();
            foreach (HUD hud in HUDs)
            {
                hud.Dispose();
            }
            HUDs.Clear();
            level.Grid = gameGrid;
            level.Create();

            Player1Camera.LookAt(Player1.Position);

            if (Mode == GameMode.MultiPlayer)
            {
                Player2Camera.LookAt(Player2.Position);
            }

            State = GameState.Playing;
        }
Ejemplo n.º 2
0
        public void StartSinglePlayerRun()
        {
            Mode = GameMode.SinglePlayer;
            player2Controller.Clear();

            SetupSingleplayerViewport();
            _backgroundP1 = new Background(spriteBatch, Player1Camera, BackgroundType.Overworld);

            gameGrid.ClearGrid();
            SoundPool.Instance.Reset();
            foreach (HUD hud in HUDs)
            {
                hud.Dispose();
            }
            HUDs.Clear();
            level.Grid = gameGrid;
            level.Create();

            Player1Camera.LookAt(Player1.Position);

            Player2       = Player1;
            Player2Camera = Player1Camera;

            State = GameState.Playing;
        }
Ejemplo n.º 3
0
        public void StartMultiPlayerRun(MultiplayerType type)
        {
            Mode            = GameMode.MultiPlayer;
            MultiplayerMode = type;
            player2Controller.Clear();
            Player2 = null;

            SetupMultiplayerViewports();
            _backgroundP1 = new Background(spriteBatch, Player1Camera, BackgroundType.Overworld);
            _backgroundP2 = new Background(spriteBatch, Player2Camera, BackgroundType.Overworld);

            gameGrid.ClearGrid();
            SoundPool.Instance.Reset();
            foreach (HUD hud in HUDs)
            {
                hud.Dispose();
            }
            HUDs.Clear();
            level.Grid = gameGrid;
            level.Create();

            MapPlayer2Controller();

            Player1Camera.LookAt(Player1.Position);
            Player2Camera.LookAt(Player2.Position);

            State = GameState.Playing;
        }
Ejemplo n.º 4
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)
        {
            if (State == GameState.GameStart)
            {
                mainMenu.Update(gameTime);
            }
            else if (State == GameState.Paused)
            {
                pauseMenu.Update(gameTime);
            }
            else if (State == GameState.Playing)
            {
                generalController.UpdateAndExecuteInputs();

                List <AbstractGameObject> collidables = new List <AbstractGameObject>();
                if (!Player1.LevelCompleted)
                {
                    player1Controller.UpdateAndExecuteInputs();
                    Player1Camera.LookAt(Player1.Position);
                    if (!transitioningAreaP1)
                    {
                        gameGrid.CurrentLeftSideViewPort = Player1Camera.Position.X;
                        gameGrid.CurrentTopSideViewPort  = Player1Camera.Position.Y;
                        collidables = gameGrid.GetCurrentMovingAndPlayerGameObjects;
                    }
                }
                else
                {
                    player1CompletedMenu.Update(gameTime);
                }

                if (Mode == GameMode.MultiPlayer && !Player2.LevelCompleted)
                {
                    player2Controller.UpdateAndExecuteInputs();
                    Player2Camera.LookAt(Player2.Position);
                    if (!transitioningAreaP2)
                    {
                        gameGrid.CurrentLeftSideViewPort = Player2Camera.Position.X;
                        gameGrid.CurrentTopSideViewPort  = Player2Camera.Position.Y;
                        collidables = collidables.Union(gameGrid.GetCurrentMovingAndPlayerGameObjects).ToList();
                    }
                }
                else
                {
                    player2CompletedMenu.Update(gameTime);
                }


                if (transitioningAreaP1 || Player1.LevelCompleted)
                {
                    collidables.RemoveAll((x) => ReferenceEquals(x, Player1));
                }

                if ((transitioningAreaP2 || Player2.LevelCompleted) && (Mode == GameMode.MultiPlayer))
                {
                    collidables.RemoveAll((x) => ReferenceEquals(x, Player2));
                }


                List <AbstractGameObject> removed = CollisionManager.ProcessFrame(gameTime, collidables, gameGrid);

                Player1Camera.LookAt(Player1.Position);
                List <AbstractGameObject> otherObjects = new List <AbstractGameObject>();
                if (!transitioningAreaP1 && !Player1.LevelCompleted)
                {
                    gameGrid.CurrentLeftSideViewPort = Player1Camera.Position.X;
                    gameGrid.CurrentTopSideViewPort  = Player1Camera.Position.Y;
                    otherObjects = gameGrid.GetAllCurrentStaticGameObjects;
                }


                if (Mode == GameMode.MultiPlayer)
                {
                    Player2Camera.LookAt(Player2.Position);
                    if (!transitioningAreaP2 && !Player2.LevelCompleted)
                    {
                        gameGrid.CurrentLeftSideViewPort = Player2Camera.Position.X;
                        gameGrid.CurrentTopSideViewPort  = Player2Camera.Position.Y;
                        otherObjects = otherObjects.Union(gameGrid.GetAllCurrentStaticGameObjects).ToList();
                    }
                }

                foreach (AbstractGameObject obj in otherObjects)
                {
                    if (obj.Update(gameTime, 1))
                    {
                        removed.Add(obj);
                    }
                }

                foreach (AbstractGameObject obj in removed)
                {
                    gameGrid.Remove(obj);
                }


                foreach (HUD hud in HUDs)
                {
                    hud.Update(gameTime);
                }
            }
            else if (State == GameState.GameOver)
            {
                gameOverScreen.Update(gameTime);
            }

            SoundPool.Instance.Update();
            base.Update(gameTime);
        }