Ejemplo n.º 1
0
 public FallingTrap(Point pos, ContentLoader loader)
 {
     m_rise = -loader.Random.Next(Tile.Height);
     m_tex = loader.LoadTexture2D("Traps/Rising");
     m_bounds = new Vector2(pos.X, pos.Y);
     GenBounds();
 }
Ejemplo n.º 2
0
        public Layer(ContentLoader content, string basePath, float scrollRate)
        {
            // Assumes each layer only has 3 segments.
            Textures = new Texture2D[3];
            for (int i = 0; i < 3; ++i)
                Textures[i] = content.LoadTexture2D(basePath + "_" + i);

            ScrollRate = scrollRate;
        }
Ejemplo n.º 3
0
 public StaticTrap(Point pos, ContentLoader loader)
 {
     m_spin = loader.Random.Next(360);
     m_tex = loader.LoadTexture2D("Traps/Static");
     m_center = new Vector2(m_tex.Width / 2, m_tex.Height / 2);
     BoundingRectangle = new Rectangle(pos.X, pos.Y, m_tex.Width, m_tex.Height);
     BoundingCircle = new Circle(new Vector2(pos.X + m_tex.Width / 2, pos.Y + m_tex.Height / 2),
         m_tex.Width > m_tex.Height ? (float)m_tex.Width / 2 : (float)m_tex.Height / 2);
 }
Ejemplo n.º 4
0
        public TileGenerator(string tileName, ContentLoader loader)
        {
            m_loader = loader;

            #region LoadData
            using (XmlReader reader = XmlReader.Create("Content/Tiles/" + tileName + "/tile.xml"))
            {
                string name;
                bool started = false;
                while (reader.Read())
                {
                    XmlNodeType type = reader.MoveToContent();
                    if (type == XmlNodeType.Element)
                    {
                        name = reader.Name.ToLower();

                        if (name == "tile")
                        {
                            if (started)
                                throw new Exception("'tile' nodes cannot be nested");
                            started = true;
                            Collision = (TileCollision)Enum.Parse(typeof(TileCollision), reader.GetAttribute("collision"));
                        }
                        else if (!started)
                            throw new Exception("The 'tile' node must be instantiated.");
                        else if (name == "texture")
                        {
                            int chance = int.Parse(reader.GetAttribute("chance"));
                            m_maxChance += chance;
                            m_textures.Add(loader.LoadTexture2D("Tiles/" + reader.ReadString()), chance);
                        }
                        else
                            throw new NotSupportedException("Node '" + name + "' is not supported.");
                    }
                    else if (type == XmlNodeType.EndElement)
                    {
                        name = reader.Name.ToLower();

                        if (name == "tile")
                        {
                            if (!started)
                                throw new Exception("The 'tile' node must be instantiated.");
                            started = false;
                        }
                        else if (!started)
                            throw new Exception("The 'tile' node must be instantiated.");
                    }
                }
            }
            #endregion

            if (m_textures.Count == 0)
                throw new Exception("Tile '" + tileName + "' must have at least 1 texture.");
        }