Ejemplo n.º 1
0
        public ItemType(string name, Rectangle location, BlockType placeableBlock)
        {
            Name = name;
            Description = "A default description";
            Stacksize = 255;
            Location = location;

            Use = "placeblock:" + placeableBlock.Id;
        }
Ejemplo n.º 2
0
        public void mock(BlockType[] blockTypes, Weapon[] weapons)
        {
            ItemTypes = new ItemType[10];

            ItemTypes[0] = new ItemType("Sword", new Rectangle(0, 0, 40, 40), weapons[0]);
            ItemTypes[1] = new ItemType("Food", new Rectangle(40, 0, 40, 40));
            ItemTypes[2] = new ItemType("Stone", new Rectangle(80, 0, 40, 40), blockTypes[0]);
            ItemTypes[3] = new ItemType("Shirt", new Rectangle(120, 0, 40, 40));
            ItemTypes[4] = new ItemType("Health Potion", new Rectangle(160, 0, 40, 40));
            ItemTypes[5] = new ItemType("Mana Potion", new Rectangle(200, 0, 40, 40), "placewall:1");
            ItemTypes[6] = new ItemType("Pants", new Rectangle(240, 0, 40, 40));
            ItemTypes[7] = new ItemType("Gun", new Rectangle(280, 0, 40, 40));
            ItemTypes[8] = new ItemType("Copper Ore", new Rectangle(320, 0, 40, 40), "placeentity:1");
            ItemTypes[9] = new ItemType("Bow", new Rectangle(360, 0, 40, 40), weapons[2]);
        }
Ejemplo n.º 3
0
 public Block( BlockType type )
 {
     Type = type;
     Health = type.Health;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Generates and places a new block at x/y
        /// </summary>
        /// <param name="x">Coordianate X of the block location</param>
        /// <param name="y">Coordianate X of the block location</param>
        /// <param name="type">Block Type</param>
        /// <returns>Returns true if the block placement was successfull, false if no block was placed</returns>
        public bool placeBlock(int x, int y, BlockType type)
        {
            if (getBlock(x, y) != null) { return false; }

            // Check for blocks to attach to
            if (getBlock(x - 1, y) == null && getBlock(x + 1, y) == null && getBlock(x, y - 1) == null && getBlock(x, y + 1) == null)
            {
                return false;
            }

            Blocks[x, y] = new Block(type);
            Fluids.Water.Blocks[x, y] = 0;
            return true;
        }
Ejemplo n.º 5
0
        public void Initialize( Texture2D mapTexture, Package package, Config config, GraphicsDevice graphics, ContentManager content )
        {
            // Setup Liquids
            Fluids.Initialize(SizeX, SizeY, content.Load<Texture2D>("Blocks/blocks"));

            BlockTexture = mapTexture;
            BlockState = content.Load<Texture2D>("Blocks/blocks");
            WallTexture = content.Load<Texture2D>("Blocks/wall");
            Entities.Initialize(content);
            Flora.Initialize(this, content.Load<Texture2D>("flora"));
            // Gather Map Data
            string data = package.RemoteString("maps/manifest/" + config.MapId);
            XmlDocument xml = new XmlDocument();
            xml.LoadXml(data);

            Spawn = new Vector2(Int32.Parse(xml.DocumentElement.Attributes["spawnx"].Value) * 24, Int32.Parse(xml.DocumentElement.Attributes["spawny"].Value) * 24);

            #region Xml Parsing

            foreach (XmlNode node in xml.DocumentElement.ChildNodes)
            {
                if (node.Name == "BlockType")
                {
                    int upto = 0;
                    foreach (XmlNode blocktype in node.ChildNodes)
                    {
                        Types[upto] = new BlockType(blocktype.Attributes["name"].Value, Int32.Parse(blocktype.Attributes["id"].Value), 100);
                        foreach (XmlNode slice in blocktype.ChildNodes)
                        {
                            Types[upto].Slices[int.Parse(slice.Attributes["i"].Value)] = new Rectangle(int.Parse(slice.Attributes["x"].Value) * 24, int.Parse(slice.Attributes["y"].Value) * 24, 24, 24);
                        }
                        upto++;
                    }
                }
                else if (node.Name == "Block")
                {
                    foreach (XmlNode block in node.ChildNodes)
                    {
                        Blocks[Int32.Parse(block.Attributes["x"].Value), Int32.Parse(block.Attributes["y"].Value)] = new Block(GetBlockType(Int32.Parse(block.Attributes["type"].Value)));
                    }
                }
                else if (node.Name == "Liquid")
                {
                    foreach (XmlNode liquid in node.ChildNodes)
                    {
                        if(byte.Parse(liquid.Attributes["type"].Value) == 1){
                            Fluids.Water.Blocks[Int32.Parse(liquid.Attributes["x"].Value), int.Parse(liquid.Attributes["y"].Value)] = 24;
                        }
                        else if (byte.Parse(liquid.Attributes["type"].Value) == 1)
                        {
                            // lava
                        }
                    }
                }
                else if (node.Name == "EntityType")
                {
                    //Entities.Types = new EntityType[node.ChildNodes.Count];

                    int i = 0;
                    foreach (XmlNode entitytype in node.ChildNodes)
                    {
                        /*Entities.Types[i] = new EntityType(
                            int.Parse(entitytype.Attributes["id"].Value),
                            entitytype.Attributes["name"].Value,
                            package.RemoteTexture(entitytype.Attributes["sprite"].Value, graphics),
                            int.Parse(entitytype.Attributes["width"].Value),
                            int.Parse(entitytype.Attributes["height"].Value),
                            true
                        );*/
                        i++;
                    }
                }
                else if (node.Name == "Entity")
                {
                    foreach (XmlNode entity in node.ChildNodes)
                    {
                        //EntityType type = Entities.getType();
                        //EntityType type = Entities.getType(int.Parse(entity.Attributes["type"].Value));
                        // int.Parse(entity.Attributes["width"].Value)
                        /*
                        Entities.Entities.Add(
                            new Entity(type, int.Parse(entity.Attributes["x"].Value), int.Parse(entity.Attributes["y"].Value))
                        );*/
                    }
                }
            }

            #endregion

            // Autogenerate
            //MapGenerator generator = new MapGenerator();
            //generator.Setup(SizeX, SizeY);
            //generator.Generate(this);
        }