Example #1
0
        public static void ROOM(Game _assets, BinaryReader _reader, Chunk _chunk)
        {
            HandleKVP(_assets, _reader, delegate(Int32 _offset) {
                LRoom _roomGet = new LRoom(_assets, _reader);
                _assets.Rooms.Add(_roomGet.Name, _roomGet);
                _roomGet.Index = _assets.RoomMapping.Count;
                _assets.RoomMapping.Add(_roomGet);
            });

            for (Int32 i = 0; i < _assets.RoomIndices.Count; i++)
            {
                _assets.RoomOrder.Insert(i, _assets.RoomMapping[_assets.RoomIndices[i]]);
            }
        }
Example #2
0
File: VM.cs Project: nommiin/Luna
        public static void LoadRoom(Game _assets, LRoom _room)
        {
            _assets.CurrentRoom = _room;
            LInstance[] _roomInstances = new LInstance[_room.Instances.Count];
            for (int i = 0; i < _room.Instances.Count; i++)
            {
                LRoomInstance _instGet    = _room.Instances[i];
                LInstance     _instCreate = new LInstance(_assets, _instGet.Index, true, _instGet.X, _instGet.Y);
                _instCreate.Variables["image_xscale"] = LValue.Real(_instGet.ScaleX);
                _instCreate.Variables["image_yscale"] = LValue.Real(_instGet.ScaleY);
                _instCreate.Variables["image_speed"]  = LValue.Real(_instGet.ImageSpeed);
                _instCreate.Variables["image_index"]  = LValue.Real(_instGet.ImageIndex);
                _instCreate.Variables["image_blend"]  = LValue.Real(_instGet.ImageBlend);
                _instCreate.Variables["image_angle"]  = LValue.Real(_instGet.Rotation);
                _instCreate.RoomPreCreate             = _instGet.PreCreate;
                _instCreate.RoomCreate = _instGet.CreationCode;
                _roomInstances[i]      = _instCreate;
            }

            for (int i = 0; i < _roomInstances.Length; i++)
            {
                LInstance _instGet = _roomInstances[i];
                if (_instGet.PreCreate != null)
                {
                    _instGet.Environment.ExecuteCode(_assets, _instGet.PreCreate);
                }
                if (_instGet.RoomPreCreate != null)
                {
                    _instGet.Environment.ExecuteCode(_assets, _instGet.RoomPreCreate);
                }
                if (_instGet.Create != null)
                {
                    _instGet.Environment.ExecuteCode(_assets, _instGet.Create);
                }
                if (_instGet.RoomCreate != null)
                {
                    _instGet.Environment.ExecuteCode(_assets, _instGet.RoomCreate);
                }
            }

            if (_room.CreationCode != null)
            {
                Domain _roomEnvironment = new LInstance(_assets, -100, false).Environment;
                _roomEnvironment.ExecuteCode(_assets, _room.CreationCode);
            }
        }
Example #3
0
        public void Insert(string SName,string SDesc)
        {
            LRoom item = new LRoom();

            item.SName = SName;

            item.SDesc = SDesc;

            item.Save(UserName);
        }
Example #4
0
        /// <summary>
        /// A button that generates the field in which the whole path finding process can be organized
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Generate_Click(object sender, EventArgs e)
        {
            Random      rnd   = new Random();
            MainField   field = new MainField();
            Cell        cell  = new Cell();
            List <Room> rooms = new List <Room>();
            Graphics    g     = this.CreateGraphics();

            lbl_Status.Text = "Status: Nothing";

            // Reset the key and gate positions with each new map created (start and end points)
            this.current_key[0] = 0;
            this.current_key[1] = 0;

            this.current_gate[0] = 0;
            this.current_gate[1] = 0;

            this.rooms_template = InitialTemplate.prepareEmptyTemplate();

            /** Generate a second copy of an empty array that will later match the original one. It will be needed to clear spaces
             * For connecting joins between the rooms. This can be only properly done if one map will never change after being populated
             * As dynamically changing map would require a much bigger set of rules to account for when looking where room connections are present.
             **/
            bool[][] rooms_template_permenant = new bool[25][];
            rooms_template_permenant = InitialTemplate.prepareEmptyTemplate();

            /** Initiate an array of all possible room types that can be generated. The names are only representations of rooms
             * as a random number generator will allow to pick one by one a room for generation and based on which room is picked
             * it will be added to the collection of all rooms for geeneration. Which will later be drawn and connected among each other
             * if connections between them actually exist
             **/
            String[] choices = { "Square", "Plus", "L", "Corner", "Long1", "Long2", "Funnel", "Empty" }; // X, FullPlus - redacted

            // ------------------ PREPARE THE MAZE --------------------------------
            // Generate a list of rooms with their information. The whole screen should have 25 rooms
            for (int i = 0; i < 25; i++)
            {
                // Generate a random number that will decide what the room will be
                int    room_value  = rnd.Next(0, choices.Length);
                String chosen_room = choices[room_value];

                // Add the chosen room to the whole collection
                switch (chosen_room)
                {
                case "Square":
                    SquareRoom squareRoom = new SquareRoom();
                    rooms.Add(squareRoom);
                    break;

                case "Plus":
                    PlusRoom plusRoom = new PlusRoom();
                    rooms.Add(plusRoom);
                    break;

                case "L":
                    LRoom lRoom = new LRoom();
                    rooms.Add(lRoom);
                    break;

                case "Empty":
                    EmptyRoom emptyRoom = new EmptyRoom();
                    rooms.Add(emptyRoom);
                    break;

                case "Corner":
                    CornerRoom cornerRoom = new CornerRoom();
                    rooms.Add(cornerRoom);
                    break;

                case "Long1":
                    LongRoom1 longRoom1 = new LongRoom1();
                    rooms.Add(longRoom1);
                    break;

                case "Long2":
                    LongRoom2 longRoom2 = new LongRoom2();
                    rooms.Add(longRoom2);
                    break;

                case "FullPlus":
                    FullPlusRoom fullPlusRoom = new FullPlusRoom();
                    rooms.Add(fullPlusRoom);
                    break;

                case "Funnel":
                    FunnelRoom funnelRoom = new FunnelRoom();
                    rooms.Add(funnelRoom);
                    break;

                case "X":
                    XRoom xRoom = new XRoom();
                    rooms.Add(xRoom);
                    break;
                }
            }

            /** Populate the information about walls that rooms add to the map in a matrix format (2D array to be more speicific here)
             * We iterrate through rooms for each case and build it all into a sort of a coordinate matrix type deal
             **/
            int row = 0;
            int col = 0;

            int true_row = 0;
            int true_col = 0;

            foreach (Room room in rooms)
            {
                /**
                 * rooms are build itteratevelly cell by cell, left to right. Consider the following example of a 2x2 room:
                 * Step 1: #
                 *
                 * Step 2: ##
                 *
                 * Step 3: ##
                 *         #
                 *
                 * Step 4: ##
                 *         ##
                 *
                 * Finish
                 * Same applies for 5 by 5. When the next room is processed, it is built in the same fashion next to the original one or down
                 * if 5 rooms per line have been constructed
                 **/
                // In the beginning we reset our position to what we are filling now on the y axis
                int position_y = 16 + (5 * cell.height * col);

                // While we still have new space to fill in a designated area - means our room is not fully drawn
                foreach (bool[] roomLine in room.room) // roomLine - just means a specific row we are moving by building a room
                {
                    // We move through each value in a row
                    int position_x = 16 + (5 * cell.width * row);
                    foreach (bool roomIndividual in roomLine) // roomIndividual - just means a seperate room cell we fill by moving through the previous line
                    {
                        if (roomIndividual)
                        {
                            true_row = (position_x / cell.width) - 1;
                            true_col = (position_y / cell.height) - 1;
                            this.rooms_template[true_row][true_col]      = roomIndividual;
                            rooms_template_permenant[true_row][true_col] = roomIndividual;
                        }
                        position_x += cell.width;
                    }
                    position_y += cell.height;
                }
                row += 1;
                if (row % 5 == 0)
                {
                    row  = 0;
                    col += 1;
                }
            }

            // ------------------ CLEANING THE MAZE --------------------------------

            /**
             * Now the goal is to go over the maze again, applying few rules and deleting spaces between rooms that can be easily connected.
             * In reality, there are only 4 rules that need to be applied to clean the maze.
             * Condition: All rooms are closed, and their external walls need to be evaluated for whether they need to be taken down or not.
             * The walls that need to be evaluated are always located on the X axis on lines: 0, 4, 5, 9, 10, 14, 15, 19, 20, 24, 25
             * The walls that need to be evaluated are always located on the Y axis on lines: 0, 4, 5, 9, 10, 14, 15, 19, 20, 24, 25
             * Because rooms are not connected beyond lines 0 and 25 on both axes, we can ommmit them.
             *
             * The condition is simple:
             *                           IF the walls of the given room neighbour 1. an open space on one side next to the space evaluated
             *                                                                    2. a closed space on the other side of the space evaluated
             *                                                                    3. an open space on the side of the cell that fits criteria 2.
             *                           THEN rooms can be connected and the given space should be deleted.
             **/
            // Go over first iterration on the X axis (i.e. 4, 9, 14, 19, 24)
            for (int x = 4; x < rooms_template_permenant.Length; x += 5)
            {
                for (int y = 0; y < rooms_template_permenant.Length; y++)
                {
                    try
                    {
                        if (rooms_template_permenant[y][x - 1] == false && rooms_template_permenant[y][x] == true && rooms_template_permenant[y][x + 1] == true && rooms_template_permenant[y][x + 2] == false)
                        {
                            this.rooms_template[y][x] = false;
                        }
                    }
                    catch
                    {
                        // Do nothing for now
                    }
                }
            }


            // Go over second iterration on the X axis (i.e. 5, 10, 15, 20)
            for (int x = 5; x < rooms_template_permenant.Length; x += 5)
            {
                for (int y = 0; y < rooms_template_permenant.Length; y++)
                {
                    try
                    {
                        if (rooms_template_permenant[y][x - 2] == false && rooms_template_permenant[y][x - 1] == true && rooms_template_permenant[y][x] == true && rooms_template_permenant[y][x + 1] == false)
                        {
                            this.rooms_template[y][x] = false;
                        }
                    }
                    catch
                    {
                        // Do nothing for now
                    }
                }
            }

            // Go over first iterration on the Y axis (i.e. 4, 9, 14, 19, 24)
            for (int x = 0; x < rooms_template_permenant.Length; x++)
            {
                for (int y = 4; y < rooms_template_permenant.Length; y += 5)
                {
                    try
                    {
                        if (rooms_template_permenant[y - 1][x] == false && rooms_template_permenant[y][x] == true && rooms_template_permenant[y + 1][x] == true && rooms_template_permenant[y + 2][x] == false)
                        {
                            this.rooms_template[y][x] = false;
                        }
                    }
                    catch
                    {
                        // Do nothing for now
                    }
                }
            }

            // Go over the second iterration on the Y axis (i.e. 5, 10, 15, 20)
            for (int x = 0; x < rooms_template_permenant.Length; x++)
            {
                for (int y = 5; y < rooms_template_permenant.Length; y += 5)
                {
                    try
                    {
                        if (rooms_template_permenant[y - 2][x] == false && rooms_template_permenant[y - 1][x] == true && rooms_template_permenant[y][x] == true && rooms_template_permenant[y + 1][x] == false)
                        {
                            rooms_template[y][x] = false;
                        }
                    }
                    catch
                    {
                        // Do nothing for now
                    }
                }
            }

            // ------------------ DRAW THE MAZE --------------------------------

            // Load all of our objects that are required to draw our map
            Image image1 = new Bitmap("..\\..\\Graphics\\PNG\\Wall1.png", true);
            Image image2 = new Bitmap("..\\..\\Graphics\\PNG\\Wall2.png", true);
            Image image3 = new Bitmap("..\\..\\Graphics\\PNG\\Wall3.png", true);
            Image image4 = new Bitmap("..\\..\\Graphics\\PNG\\Wall4.png", true);

            TextureBrush tBrush1 = new TextureBrush(image1);
            TextureBrush tBrush2 = new TextureBrush(image2);
            TextureBrush tBrush3 = new TextureBrush(image3);
            TextureBrush tBrush4 = new TextureBrush(image4);

            // Clean everything before drawing if there are instances of an old map being present
            Brush myOldLaceBrush = new SolidBrush(color: Color.OldLace);

            g.FillRectangle(brush: myOldLaceBrush, x: field.x, y: field.y, width: field.width, height: field.height);

            // As we have all values of our maze in a 2D Matrix (array), we can just draw them one by one.
            int place_x = field.x;
            int place_y = field.y;

            for (int i = 0; i < this.rooms_template.Length; i++)
            {
                for (int j = 0; j < this.rooms_template[i].Length; j++)
                {
                    bool roomState = this.rooms_template[i][j];
                    if (roomState)
                    {
                        // Chose a random brush to paint with, as we want all of our walls to be randomly different
                        int rnd_brush = rnd.Next(0, 4);
                        switch (rnd_brush)
                        {
                        case 0:
                            g.FillRectangle(tBrush1, x: place_x, y: place_y, width: cell.width, height: cell.height);
                            break;

                        case 1:
                            g.FillRectangle(tBrush2, x: place_x, y: place_y, width: cell.width, height: cell.height);
                            break;

                        case 2:
                            g.FillRectangle(tBrush3, x: place_x, y: place_y, width: cell.width, height: cell.height);
                            break;

                        case 3:
                            g.FillRectangle(tBrush4, x: place_x, y: place_y, width: cell.width, height: cell.height);
                            break;

                        default:
                            break;
                        }
                    }
                    place_x += cell.width;
                }
                place_x  = field.x;
                place_y += cell.height;
            }

            // Update the representation that we will want of our matrix to be in, for the future
            this.rooms_template_redux = TemplateConverter.redefineTemplate(original_template: this.rooms_template);
        }
Example #5
0
        public void Update(short Id,string SName,string SDesc)
        {
            LRoom item = new LRoom();
            item.MarkOld();
            item.IsLoaded = true;

            item.Id = Id;

            item.SName = SName;

            item.SDesc = SDesc;

            item.Save(UserName);
        }