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(); }
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); }
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; }
/// <summary> /// Constructs a new level. /// </summary> /// <param name="serviceProvider"> /// The service provider that will be used to construct a ContentManager. /// </param> /// <param name="path"> /// The absolute path to the level file to be loaded. /// </param> public Level(IServiceProvider serviceProvider, string path, int score, int pHP, int pMaxHP) { // Create a new content manager to load content used just by this level. ContentManager = new ContentManager(serviceProvider, "Content"); Content = new ContentLoader(this); timeRemaining = TimeSpan.FromMinutes(1.0); NextLevel = null; LoadTiles(path, pHP, pMaxHP); levelSize = new Rectangle(0, 0, Width * Tile.Width, Height * Tile.Height); // Load background layer textures. For now, all levels must // use the same backgrounds and only use the left-most part of them. layers = new Layer[3]; layers[0] = new Layer(Content, "Backgrounds/Layer0", 0.2f); layers[1] = new Layer(Content, "Backgrounds/Layer1", 0.5f); layers[2] = new Layer(Content, "Backgrounds/Layer2", 0.8f); // Load sounds. this.score = score; exitReachedSound = Content.LoadSoundEffect("Sounds/ExitReached"); }
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."); }