Exemplo n.º 1
0
 public void AddRoom(TDSRoom mRoom)
 {
     foreach (var tuple in Rooms.Keys.Where(x => x.Item1 == mRoom.X && x.Item2 == mRoom.Y))
     {
         Rooms[tuple] = mRoom;
         return;
     }
     Rooms.Add(new Tuple<int, int>(mRoom.X, mRoom.Y), mRoom);
 }
Exemplo n.º 2
0
        public static TDSRoom InputCreateRoomBox(TDSRoom currentRoom)
        {
            var form = new Form();
            var westRadioButton = new RadioButton {Text = "To the west", Enabled = false};
            var eastRadioButton = new RadioButton {Text = "To the east", Enabled = false};
            var northRadioButton = new RadioButton {Text = "To the north", Enabled = false};
            var southRadioButton = new RadioButton {Text = "To the south", Enabled = false};
            var isRequiredCheckBox = new CheckBox {Text = "Is required", Checked = true};
            var isSecretCheckBox = new CheckBox {Text = "Is secret", Checked = false};
            var doneButton = new Button {Text = "OK"};

            form.Text = "Create new room";

            form.ClientSize = new Size(396, 200);
            form.Controls.AddRange(new Control[]
                                   {
                                       westRadioButton, eastRadioButton, northRadioButton, southRadioButton,
                                       isRequiredCheckBox, isSecretCheckBox, doneButton
                                   });
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;

            westRadioButton.SetBounds(25, 25, 100, 25);
            eastRadioButton.SetBounds(25, 50, 100, 25);
            northRadioButton.SetBounds(25, 75, 100, 25);
            southRadioButton.SetBounds(25, 100, 100, 25);
            isRequiredCheckBox.SetBounds(125, 25, 100, 25);
            isSecretCheckBox.SetBounds(125, 50, 100, 25);
            doneButton.SetBounds(125, 100, 100, 25);

            if (currentRoom.Level.GetRoom(currentRoom.X - 1, currentRoom.Y) == null) westRadioButton.Enabled = true;
            if (currentRoom.Level.GetRoom(currentRoom.X + 1, currentRoom.Y) == null) eastRadioButton.Enabled = true;
            if (currentRoom.Level.GetRoom(currentRoom.X, currentRoom.Y - 1) == null) northRadioButton.Enabled = true;
            if (currentRoom.Level.GetRoom(currentRoom.X, currentRoom.Y + 1) == null) southRadioButton.Enabled = true;

            TDSRoom result = null;
            var resultX = 0;
            var resultY = 0;

            doneButton.Click += (e, sender) =>
                                {
                                    if (westRadioButton.Checked) resultX = -1;
                                    if (eastRadioButton.Checked) resultX = 1;
                                    if (northRadioButton.Checked) resultY = -1;
                                    if (southRadioButton.Checked) resultY = 1;

                                    result = TDSControl.CreateRoom(currentRoom.Level, currentRoom.X + resultX, currentRoom.Y + resultY, isRequiredCheckBox.Checked, isSecretCheckBox.Checked);
                                    form.Close();
                                };

            form.ShowDialog();

            return result;
        }
Exemplo n.º 3
0
        private TDGInstance CreateInstance(TDSRoom mRoom, bool mTemporary = false)
        {
            var result = new TDGInstance(this, mTemporary);
            TDLFactory.Instance = result;

            // Initialize field and pathfinder
            result.Initialize(mRoom.Level.RoomWidth, mRoom.Level.RoomHeight);

            // Refresh texture size, if instance isn't temporary
            if (!mTemporary) RefreshGFX(TDUtils.TileSize*result.Width, TDUtils.TileSize*result.Height);

            // Fill the instance with floor
            for (var iY = 0; iY < result.Height; iY++)
                for (var iX = 0; iX < result.Width; iX++)
                {
                    TDLFactory.Tile = result.GetTile(iX, iY);
                    result.AddEntity(TDLFactory.Floor());
                }

            // Get all tiles from the editor tilemanager and create corrispondent entities
            foreach (var tileManagerEntity in mRoom.TileManager.Entities)
            {
                var methodInfo = tileManagerEntity.Outline.MethodInfo;
                var parameterValues = new object[tileManagerEntity.Parameters.Count];

                for (var i = 0; i < tileManagerEntity.Parameters.Count; i++)
                    parameterValues[i] = tileManagerEntity.Parameters[i].Value;

                TDLFactory.Tile = result.GetTile(tileManagerEntity.Tile.X, tileManagerEntity.Tile.Y);
                var invokedEntity = (Entity) methodInfo.Invoke(null, parameterValues);
                result.AddEntity(invokedEntity);

                // If the room was cleared previously and the entity is required, destroy it instantly
                // This means that if the player returns to the room after it was cleared, there are no mobs
                if (mRoom.IsClear && invokedEntity.HasTag(TDLTags.RequiredKill))
                    invokedEntity.Destroy();
            }

            result.CalculatePathmaps();

            return result;
        }