示例#1
0
        /// <summary>
        /// Equivalent of items.Remove(), but also works in loops.
        /// </summary>
        /// <param name="item">The item to remove.</param>
        public void RemoveItem(GameObj item)
        {
            List <GameObj> newItems = new List <GameObj>();

            //Creates a shallow copy of the original list by copying all
            //objects except for the specified one.
            foreach (GameObj currentItem in items)
            {
                if (item != currentItem)
                {
                    newItems.Add(currentItem);
                }
            }

            items = newItems;
        }
示例#2
0
        ///<summary>
        ///Loads relevant graphics into memory.
        ///
        /// Dependencies: MainLoop.cs, maze block textures.
        /// </summary>
        public void LoadContent(ContentManager Content)
        {
            //Loads relevant assets.
            sndCheckpoint = Content.Load <SoundEffect>("Content/Sounds/sndCheckpoint");
            sndFinish     = Content.Load <SoundEffect>("Content/Sounds/sndFinish");
            sndHit        = Content.Load <SoundEffect>("Content/Sounds/sndHit");
            sndWin        = Content.Load <SoundEffect>("Content/Sounds/sndWin");
            TexPixel      = new Texture2D(game.GraphicsDevice, 1, 1);
            TexPixel.SetData(new Color[] { Color.White });
            TexMenuHud = game.Content.Load <Texture2D>("Content/Sprites/Gui/sprMenuHud");

            //Sets up hud sprites.
            sprHudOverlay          = new Sprite(true, TexPixel);
            sprHudOverlay.color    = Color.Gray;
            sprHudOverlay.alpha    = 0.5f;
            sprHudOverlay.rectDest = new SmoothRect
                                         (0, game.GetScreenSize().Y - 32, game.GetScreenSize().X, 32);

            sprMenuHud          = new Sprite(true, TexMenuHud);
            sprMenuHud.rectDest = new SmoothRect
                                      (0, game.GetScreenSize().Y - 32, 64, 32);

            //Loads all maze block textures.
            GameObj._LoadContent(game.Content); //base class.
            MazeActor.LoadContent(game.Content);
            MazeBelt.LoadContent(game.Content);
            MazeCoin.LoadContent(game.Content);
            MazeCoinLock.LoadContent(game.Content);
            MazeCrate.LoadContent(game.Content);
            MazeCrateHole.LoadContent(game.Content);
            MazeEnemy.LoadContent(game.Content);
            MazeFilter.LoadContent(game.Content);
            MazeFloor.LoadContent(game.Content);
            MazeFreeze.LoadContent(game.Content);
            MazeGate.LoadContent(game.Content);
            MazeHealth.LoadContent(game.Content);
            MazeIce.LoadContent(game.Content);
            MazeKey.LoadContent(game.Content);
            MazeLaserActuator.LoadContent(game.Content);
            MazeLock.LoadContent(game.Content);
            MazeMultiWay.LoadContent(game.Content);
            MazePanel.LoadContent(game.Content);
            MazeSpawner.LoadContent(game.Content);
            MazeSpike.LoadContent(game.Content);
            MazeStairs.LoadContent(game.Content);
            MazeTeleporter.LoadContent(game.Content);
            MazeThaw.LoadContent(game.Content);
            MazeWall.LoadContent(game.Content);
            MazeCheckpoint.LoadContent(game.Content);
            MazeEPusher.LoadContent(game.Content);
            MazeELight.LoadContent(game.Content);
            MazeEAuto.LoadContent(game.Content);
            MazeGoal.LoadContent(game.Content);
            MazeFinish.LoadContent(game.Content);
            MazeMessage.LoadContent(game.Content);
            MazeClick.LoadContent(game.Content);
            MazeRotate.LoadContent(game.Content);
            MazeTurret.LoadContent(game.Content);
            MazeTurretBullet.LoadContent(game.Content);
            MazeMirror.LoadContent(game.Content);
        }
        /// <summary>
        /// Transfers between senders and receivers on contact if possible.
        /// </summary>
        public override void Update()
        {
            #region Adjusts sprite.
            //Adjusts the sprite frame.
            if (CustInt1 == 0)
            {
                spriteAtlas.frame = 0; //Sender.
            }
            else
            {
                spriteAtlas.frame = 2; //Receiver.
            }
            //Depends on frame positions and texture.
            if (!IsEnabled)
            {
                spriteAtlas.frame++;
            }
            #endregion

            //Sender logic.
            if (IsEnabled && CustInt1 == 0)
            {
                //Blocks on this block, blocks on receivers, and receivers.
                List <GameObj> itemsTop     = new List <GameObj>();
                List <GameObj> itemsDestTop = new List <GameObj>();
                List <GameObj> itemsNodes   = new List <GameObj>();

                //Gets a list of all blocks on the sender.
                itemsTop = game.mngrLvl.items.Where(o =>
                                                    o.X == X && o.Y == Y && o.Layer == Layer &&
                                                    (o.BlockSprite.depth < BlockSprite.depth)).ToList();

                #region Interaction: MazeTurretBullet
                itemsTop.AddRange(game.mngrLvl.items.Where(o =>
                                                           o.BlockType == Type.TurretBullet &&
                                                           Math.Abs(X * 32 + 16 - o.X) < 16 &&
                                                           Math.Abs(Y * 32 + 16 - o.Y) < 16 &&
                                                           o.Layer == Layer));
                #endregion

                //Gets a list of all enabled receivers.
                itemsNodes = game.mngrLvl.items.Where(o =>
                                                      o.BlockType == Type.Teleporter &&
                                                      o.IsEnabled &&
                                                      o.CustInt1 != 0 &&
                                                      o.CustInt2 == CustInt2).ToList();

                //Teleports blocks if receivers are available.
                foreach (GameObj item in itemsTop)
                {
                    //Filters out all incapable receivers.
                    for (int i = itemsNodes.Count - 1; i >= 0; i--)
                    {
                        //Gets a list of all solid blocks on the receiver.
                        itemsDestTop = game.mngrLvl.items.Where(o =>
                                                                o.X == itemsNodes[i].X &&
                                                                o.Y == itemsNodes[i].Y && o.Layer ==
                                                                itemsNodes[i].Layer && o.IsSolid).ToList();

                        //Iterates through each block on the receiver.
                        for (int j = itemsDestTop.Count - 1; j >= 0; j--)
                        {
                            #region Interaction: MazeCrate
                            if (itemsDestTop[j].BlockType == Type.Crate)
                            {
                                //Gets a list of all solid blocks in front.
                                List <GameObj> itemsDestFront =
                                    game.mngrLvl.items.Where(o => o.IsSolid &&
                                                             o.X == itemsNodes[i].X +
                                                             (int)Utils.DirVector(item.BlockDir).X&&
                                                             o.Y == itemsNodes[i].Y +
                                                             (int)Utils.DirVector(item.BlockDir).Y&&
                                                             o.Layer == itemsNodes[i].Layer).ToList();

                                //Removes valid multiways from the list.
                                #region Interaction: MazeMultiWay.cs
                                itemsDestFront = itemsDestFront.Where(o =>
                                                                      !(o.IsEnabled &&
                                                                        o.BlockType == Type.MultiWay &&
                                                                        ((o.CustInt1 == 0 && o.BlockDir == item.BlockDir) ||
                                                                         (o.CustInt1 != 0 && (o.BlockDir == item.BlockDir ||
                                                                                              o.BlockDir == Utils.DirOpp(BlockDir)))))).ToList();
                                #endregion

                                /*Allows a block to enter the teleporter if
                                 * the crate blocking the receiver can be
                                 * pushed out of the way in the direction the
                                 * block is traveling.*/
                                if (itemsDestFront.Count == 0)
                                {
                                    //Moves the crate; removes it from list.
                                    itemsDestTop[j].X +=
                                        (int)Utils.DirVector(item.BlockDir).X;
                                    itemsDestTop[j].Y +=
                                        (int)Utils.DirVector(item.BlockDir).Y;
                                    itemsDestTop[j].BlockDir = item.BlockDir;
                                    itemsDestTop.RemoveAt(j);
                                }
                            }
                            #endregion
                        }

                        //Removes the receiver for being incapable.
                        if (itemsDestTop.Count != 0)
                        {
                            itemsNodes.RemoveAt(i);
                        }
                    }

                    if (itemsNodes.Count != 0)
                    {
                        //Selects a receiver at random.
                        GameObj receiver =
                            itemsNodes[Utils.Rng.Next(itemsNodes.Count)];

                        game.playlist.Play(sndTeleport, X, Y);

                        #region Interaction: MazeTurretBullet
                        if (item.BlockType == Type.TurretBullet)
                        {
                            item.X  = (int)Math.IEEERemainder(item.X, 32);
                            item.Y  = (int)Math.IEEERemainder(item.Y, 32);
                            item.X += receiver.X * 32;
                            item.Y += receiver.Y * 32;
                        }
                        else
                        {
                            item.X = receiver.X;
                            item.Y = receiver.Y;
                        }
                        #endregion

                        item.Layer = receiver.Layer;
                    }
                }
            }

            spriteAtlas.Update(true);
            base.Update();
        }