Example #1
0
        // Checks the current node for a shadow copy and sets it's entity node according to the centre of its image.
        public void SetEntityPosition(Node node, ShadowCopy shadowCopy)
        {
            // Stores the centre of the shadow copy based on its rectangle.
            Vector2 v2CopyCentre = shadowCopy.EntityPosition + new Vector2(shadowCopy.RectEntity.Width / 2, shadowCopy.RectEntity.Height / 2);

            if (v2CopyCentre != null)
            {
                if (node.Tile.Contains(new Point((int)v2CopyCentre.X, (int)v2CopyCentre.Y)))
                {
                    shadowCopy.EntityNode = node;
                }
            }
        }
Example #2
0
        private Texture2D tx2ShadowCopy;       // Stores the texture of shadow copies to spawn them.
        #endregion

        // Instantiates objects and initializes the game grid (creates the grid of nodes).
        // Provides the input keys for each player and sets every entity's
        // starting position.
        public override void Initialize()
        {
            base.Initialize();
            layerGameGrid = new GridLayer(true);
            player        = new Player[4];
            shadowCopy    = new ShadowCopy[4];
            switch (ScreenManager.Instance.Difficulty)
            {
            case "easy":
                addShadowCopy = new AddShadowCopy[0];
                break;

            case "intermediate":
                addShadowCopy = new AddShadowCopy[2];
                break;

            case "hard":
                addShadowCopy = new AddShadowCopy[4];
                break;

            case "impossible":
                addShadowCopy = new AddShadowCopy[6];
                break;
            }
            InputKeys = new Keys[4, 4];

            // four players are instantiated and each has their starting node set by the InitPos function.
            for (int intPlayerIndex = 0; intPlayerIndex <= 3; intPlayerIndex++)
            {
                player[intPlayerIndex] = new Player();
                player[intPlayerIndex].Initialize(InitPos(intPlayerIndex, layerGameGrid.Nodes));
            }
            // Sets the colour of players.
            player[0].Colour = Color.Blue;
            player[1].Colour = Color.ForestGreen;
            player[2].Colour = Color.Gold;
            player[3].Colour = Color.Red;

            // four shadow copies are instantiated and each has their starting node set by the InitPos function.
            for (int intCopyIndex = 0; intCopyIndex <= 3; intCopyIndex++)
            {
                shadowCopy[intCopyIndex] = new ShadowCopy();
                shadowCopy[intCopyIndex].Initialize(InitCopyPos(intCopyIndex, layerGameGrid.Nodes));
            }

            #region setKeys
            InputKeys[0, 0] = Keys.D;
            InputKeys[0, 1] = Keys.S;
            InputKeys[0, 2] = Keys.A;
            InputKeys[0, 3] = Keys.W;

            InputKeys[1, 0] = Keys.H;
            InputKeys[1, 1] = Keys.G;
            InputKeys[1, 2] = Keys.F;
            InputKeys[1, 3] = Keys.T;

            InputKeys[2, 0] = Keys.L;
            InputKeys[2, 1] = Keys.K;
            InputKeys[2, 2] = Keys.J;
            InputKeys[2, 3] = Keys.I;

            InputKeys[3, 0] = Keys.Right;
            InputKeys[3, 1] = Keys.Down;
            InputKeys[3, 2] = Keys.Left;
            InputKeys[3, 3] = Keys.Up;
            #endregion
        }
Example #3
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);
            }
        }