示例#1
0
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------

        protected override void Initialize()
        {
            base.Initialize();

            string typeName = Properties.GetString("warp_type", "Tunnel");

            warpType     = (WarpType)Enum.Parse(typeof(WarpType), typeName, true);
            collisionBox = new Rectangle2I(2, 6, 12, 12);
            warpEnabled  = !IsTouchingPlayer();

            // Find the closest room edge.
            edgeDirection = -1;
            Rectangle2I roomBounds = RoomControl.RoomBounds;
            Rectangle2I myBox      = new Rectangle2I((int)position.X, (int)position.Y, 16, 16);
            int         minDist    = -1;

            for (int dir = 0; dir < 4; dir++)
            {
                int dist = Math.Abs(myBox.GetEdge(dir) - roomBounds.GetEdge(dir));
                if (dist < minDist || minDist < 0)
                {
                    edgeDirection = dir;
                    minDist       = dist;
                }
            }

            // Make sure we know if the player respawns on top of this warp point.
            RoomControl.PlayerRespawn += delegate(Player player) {
                warpEnabled = !IsTouchingPlayer();
            };

            // For entrance warp points, intercept room transitions in order to warp.
            RoomControl.RoomTransitioning += delegate(int direction) {
                if (warpType == WarpType.Entrance && direction == edgeDirection && IsTouchingPlayer())
                {
                    RoomControl.CancelRoomTransition();
                    Warp(direction);
                }
            };
        }