Exemple #1
0
        // Checks for key presses and processes changes accordingly each update cycle. This deals
        // with a number of things such as AI calculation updates, player movement, player interaction,
        // lamps, door movement and also to detect if the user has pressed escape to show the pause menu.
        public override void Update(GameTime gameTime)
        {
            if (ScreenManager.Instance.SingleKeyPress(Keys.Escape))
            {
                ScreenManager.Instance.PushTranslucentScreen(new PauseScreen());
            }

            for (int intPlayerIndex = 0; intPlayerIndex <= 3; intPlayerIndex++)
            {
                if (player[intPlayerIndex].Dead != true)
                {
                    Keys[] playerKeys = new Keys[4];
                    playerKeys[0] = InputKeys[intPlayerIndex, 0];
                    playerKeys[1] = InputKeys[intPlayerIndex, 1];
                    playerKeys[2] = InputKeys[intPlayerIndex, 2];
                    playerKeys[3] = InputKeys[intPlayerIndex, 3];
                    player[intPlayerIndex].Update(gameTime, playerKeys, layerGameGrid, addShadowCopy, shadowCopy, tx2ShadowCopy);
                }
            }

            if (intProgressionTime > 5) // After 5 seconds, spawn shadow copies.
            // Updates each initial copy.
            {
                foreach (ShadowCopy shadowcopy in shadowCopy)
                {
                    if (shadowcopy != null)
                    {
                        shadowcopy.Update(gameTime, player, layerGameGrid.Nodes);
                    }
                }
            }

            // Updates each additional copy if it has been instantiated.
            foreach (AddShadowCopy shadowcopy in addShadowCopy)
            {
                if (shadowcopy != null)
                {
                    shadowcopy.Update(gameTime, player, layerGameGrid);
                }
            }

            // Every 20 seconds after the start of the game, respawn initial shadow copies if they were erased.
            if (intProgressionTime == 20 || intProgressionTime == 40 || intProgressionTime == 60 || intProgressionTime == 80)
            {
                if (shadowCopy.Count(sc => sc == null) > 0)                // Checks if the number of null shadow copies is greater than 0.
                {
                    int intRespawnIndex = Array.IndexOf(shadowCopy, null); // Stores the index of a null item in the array to respawn a shadow copy.
                    shadowCopy[intRespawnIndex] = new ShadowCopy();        // Respawn a shadow copy at its default spawn point.
                    shadowCopy[intRespawnIndex].Initialize(InitCopyPos(intRespawnIndex, layerGameGrid.Nodes));
                    shadowCopy[intRespawnIndex].EntityImage = tx2ShadowCopy;
                    shadowCopy[intRespawnIndex].Animation.AnimationImage = tx2ShadowCopy;
                }
            }

            layerGameGrid.CheckNodes(player, shadowCopy, addShadowCopy);

            intTimeSinceFrame += gameTime.ElapsedGameTime.Milliseconds; // Adds the number of milliseconds passed each frame
            if (intTimeSinceFrame >= 1000)                              // until a second has passed.
            {
                intProgressionTime += 1;                                // Then a second is added to the progression time and the time since frame is reset.
                intTimeSinceFrame   = 0;
            }
            // After 100 seconds, or if all the players have died, end the game.
            if (intProgressionTime == 100 || (player[0].Dead && player[1].Dead && player[2].Dead && player[3].Dead))
            {
                EndGame(player);
            }
        }