Ejemplo n.º 1
0
 // Sets the postition and height of an entity
 public void setPos(ref Sprite.Entity sprite, ref Sprite[,,] sprites, nfloat Height, nfloat Width)
 {
     // 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) * (Height / 10));
     // Adds their postition to the sprite array
     sprite.actualX = sprite.xPos * 15 + 7.5;
     sprite.actualY = sprite.yPos * 15 + 7.5;
     sprites[sprite.xPos, sprite.yPos, 0] = sprite;
     sprite.spriteNode.ZPosition          = sprite.defaultZ + (9 - sprite.yPos);
     sprite.spriteNode.Size = new CGSize(Height / 10, (Height * sprite.spriteh) / 150);
     sprite.last_direction  = "";
     sprite.Speed           = sprite.Base_Speed;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Fetches the values for the entity p1.
        /// </summary>
        /// <returns>the sprite.entity p1.</returns>
        public Sprite.Entity p1()
        {
            fetch_data fetch_Data = new fetch_data();

            Sprite.Entity player = new Sprite.Entity();
            try
            {
                fetch_Data.Fetch("p1", out player, out Sprite.Block b);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("p1_setup p1()");
                Debug.WriteLine(ex);
            }
            player.spritef = player.path + "front.png"; player.spriteb = player.path + "back"; player.spritel = player.path + "left"; player.spriter = player.path + "right";
            return(player);
        }
Ejemplo n.º 3
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);
            }
        }