Example #1
0
        // Fetches a map from a map file and imports it into a 3 dimensional array
        public Sprite[,,] fetchMap(string mapID)
        {
            block_setup setup = new block_setup();

            Sprite[,,] sprites = new Sprite[10, 10, 3];
            StreamReader map1 = null;

            try
            {
                map1 = new StreamReader(path_map + mapID + ".csv");
                Debug.WriteLine("No error for map path");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error whilst trying to access map: {0}", ex);
            }

            string[] row;

            for (int y = 9; y >= 0; y--)
            {
                row = map1.ReadLine().Split(',');
                for (int x = 0; x < row.Length; x++)
                {
                    if (row[x] != "0")
                    {
                        Sprite.Block block = new Sprite.Block(setup.b(row[x]));
                        block.xPos       = x; block.yPos = y; block.zPos = 0;
                        sprites[x, y, 0] = block;
                    }
                }
            }
            map1.Close();
            return(sprites);
        }
Example #2
0
        public Sprite[,,] Getmap(nfloat Height, nfloat Width, int mapnum)
        {
            block_setup setup = new block_setup();
            fetch_data  fetch = new fetch_data();

            Sprite[,,] sprites = new Sprite[10, 10, 3];
            StreamReader maps = null;

            try
            {
                maps = new StreamReader(fetch.Get_path_map() + "maps.csv");
                Debug.WriteLine("No error for map path");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            string[] row;

            do
            {
                row = maps.ReadLine().Split(',');
                if (int.Parse(row[0]) == mapnum)
                {
                    Sprite.Block block = new Sprite.Block(setup.b(row[3]));
                    block.xPos       = int.Parse(row[1]); block.yPos = int.Parse(row[2]); block.zPos = 0;
                    block.spriteNode = SKSpriteNode.FromImageNamed(block.path);
                    setup.setPos(ref block, ref sprites, Height, Width);
                }
            }while (int.Parse(row[0]) <= mapnum);
            maps.Close();
            return(sprites);
        }
Example #3
0
        // Sets the position and height of a block
        public void setPos(ref Sprite.Block sprite, ref Sprite[,,] sprites, nfloat Height, nfloat Width)
        {
            try
            {
                // XY positions have a value between 1 and 10
                sprite.spriteNode.Position = new CoreGraphics.CGPoint(((sprite.xPos + 0.5) * (Height / 10)) + (Width - Height) / 2, (sprite.yPos + sprite.yShift + 0.5 + (sprite.spriteh - 15) / 30) * (Height / 10));
                // Adds their position to the sprite array
                for (int i = 0; i < sprite.height; i++)
                {
                    sprites[sprite.xPos, sprite.yPos, i] = sprite;
                }
                sprite.spriteNode.ZPosition = sprite.defaultZ + 4 * (9 - sprite.yPos) + 2 * (sprite.height - 1);
                sprite.spriteNode.Size      = new CGSize(Height / 10, (Height * sprite.spriteh) / 150);
                Debug.WriteLine("no error setting position");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            Debug.WriteLine("Name: {0}, Climbable: {1}", sprite.Name, sprite.Climbable);
            Debug.WriteLine(sprite.spriteNode.Position);
            Debug.WriteLine((sprite.yPos + sprite.yShift) * (Height / 10));
            Debug.WriteLine(sprite.spriteNode.Size);
        }
Example #4
0
        // Generic block fetching program
        public Sprite.Block b(string ID)
        {
            fetch_data fetch_Data = new fetch_data();

            Sprite.Block block = new Sprite.Block();
            try
            {
                fetch_Data.Fetch(ID, out Sprite.Entity e, out block);
                Debug.WriteLine("No problems fetching: {0}", ID);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("p1_setup block setup");
                Debug.WriteLine(ex + "\n");
            }
            return(block);
        }
Example #5
0
        // Gets the map from the table and returns it in a Sprite array
        public Sprite[,,] Getmap(nfloat Height, nfloat Width, int mapnum)
        {
            block_setup setup = new block_setup();

            Sprite[,,] sprites = new Sprite[10, 10, 3];
            StreamReader maps = null;

            try
            {
                maps = new StreamReader(path_map + "maps.csv");
                Debug.WriteLine("No error for map path");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to access maps directory: {0}", ex);
            }

            string[] row;
            maps.ReadLine();
            try
            {
                do
                {
                    row = maps.ReadLine().Split(',');
                    if (int.TryParse(row[0], out int z) && int.Parse(row[0]) == mapnum)
                    {
                        Sprite.Block block = new Sprite.Block(setup.b(row[3]));
                        block.xPos       = int.Parse(row[1]); block.yPos = int.Parse(row[2]); block.zPos = 0;
                        block.spriteNode = SKSpriteNode.FromImageNamed(block.path);
                        setup.setPos(ref block, ref sprites, Height, Width);
                    }
                }while (int.Parse(row[0]) <= mapnum);
                Debug.WriteLine("Fetched map from maps table without problem");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to fetch from maps table: {0}", ex);
            }
            maps.Close();
            return(sprites);
        }
Example #6
0
        // Fetches a map file and imports it into a 3 dimensional array while instantiating the values
        public Sprite[,,] fetchMap(nfloat Height, nfloat Width, string mapID)
        {
            block_setup setup = new block_setup();

            Sprite[,,] sprites = new Sprite[10, 10, 3];
            StreamReader map1 = null;

            try
            {
                map1 = new StreamReader(path_map + mapID + ".csv");
                Debug.WriteLine("No error for map path");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error whilst trying to access map: {0}", ex);
            }

            string[] row;

            for (int y = 9; y >= 0; y--)
            {
                row = map1.ReadLine().Split(',');
                for (int x = 0; x < row.Length; x++)
                {
                    if (row[x] != "0")
                    {
                        Sprite.Block block = new Sprite.Block(setup.b(row[x]));
                        block.xPos       = x; block.yPos = y; block.zPos = 0;
                        block.spriteNode = SKSpriteNode.FromImageNamed(block.path);
                        setup.setPos(ref block, ref sprites, Height, Width);
                    }
                }
            }
            map1.Close();
            return(sprites);
        }
Example #7
0
        // Function to fetch values from the tables
        public Sprite Fetch(string ID, out Sprite.Entity fetch1, out Sprite.Block fetch2)
        {
            // Tries to set up streamreader from the tables.
            Sprite.Basic temp = null;
            StreamReader sprites = null, entities = null, blocks = null;

            try
            {
                sprites  = new StreamReader(path_g + "sprites.csv");
                entities = new StreamReader(path_g + "entities.csv");
                blocks   = new StreamReader(path_g + "blocks.csv");
                temp     = new Sprite.Basic();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }

            bool found = false;

            string[] data;

            // Fetches values from sprites table and stores them in a temporary sprite.Basic
            while (!found)
            {
                data = sprites.ReadLine().Split(',');
                if (data[0] == ID)
                {
                    found = true; temp.ID = data[0]; temp.Name = data[1]; temp.Solid = bool.Parse(data[2]); temp.Type = data[3]; temp.defaultZ = int.Parse(data[4]); temp.path = data[5]; temp.yShift = Convert.ToDouble(data[6]); temp.spriteh = int.Parse(data[7]);
                }
            }
            found = false;
            sprites.Close();

            // Checks the type of the sprite whose value was fetched and sets up a corresponding sprite.entity or sprite.block
            switch (temp.Type)
            {
            case "entity":
                fetch1    = new Sprite.Entity();
                fetch1.ID = temp.ID; fetch1.Name = temp.Name; fetch1.Solid = temp.Solid; fetch1.Type = temp.Type; fetch1.defaultZ = temp.defaultZ; fetch1.path = temp.path; fetch1.yShift = temp.yShift; fetch1.spriteh = temp.spriteh;
                while (!found)
                {
                    data = entities.ReadLine().Split(',');
                    if (data[0] == ID)
                    {
                        found = true; fetch1.Max_Speed = int.Parse(data[1]); fetch1.Base_Speed = int.Parse(data[2]); fetch1.Acceleration = int.Parse(data[3]); fetch1.Health = int.Parse(data[4]); fetch1.Strength = int.Parse(data[5]);
                    }
                }
                fetch2 = new Sprite.Block();
                entities.Close();
                blocks.Close();
                return(temp);

            case "block":
                fetch2    = new Sprite.Block();
                fetch2.ID = temp.ID; fetch2.Name = temp.Name; fetch2.Solid = temp.Solid; fetch2.Type = temp.Type; fetch2.defaultZ = temp.defaultZ; fetch2.path = temp.path; fetch2.yShift = temp.yShift; fetch2.spriteh = temp.spriteh;
                while (!found)
                {
                    data = blocks.ReadLine().Split(',');
                    if (data[0] == ID)
                    {
                        found = true; fetch2.Climbable = Convert.ToBoolean(int.Parse(data[1])); fetch2.height = int.Parse(data[2]); fetch2.Traversable = Convert.ToBoolean(int.Parse(data[3]));
                    }
                }
                fetch1 = new Sprite.Entity();
                entities.Close();
                blocks.Close();
                return(temp);

            default:
                fetch1    = new Sprite.Entity();
                fetch1.ID = temp.ID; fetch1.Name = temp.Name; fetch1.Solid = temp.Solid; fetch1.Type = temp.Type; fetch1.defaultZ = temp.defaultZ;
                fetch2    = new Sprite.Block();
                fetch2.ID = temp.ID; fetch2.Name = temp.Name; fetch2.Solid = temp.Solid; fetch2.Type = temp.Type; fetch2.defaultZ = temp.defaultZ;
                entities.Close();
                blocks.Close();
                return(temp);
            }
        }