public void BuildRandom() { TotemBase totemBase = new TotemBase(); m_allSections.Add(totemBase); m_attachedSections.Add(totemBase); //Set the order of the totem sections int amountOfSections = m_sectionsToPlace.Count; for (int i = 0; i < amountOfSections; ++i) { int index = Program.Random.Next(0, m_sectionsToPlace.Count); m_allSections.Add(m_sectionsToPlace[index]); m_attachedSections.Add(m_sectionsToPlace[index]); m_sectionsToPlace.RemoveAt(index); } //Place the totem sections in the world TotemSection above = null, below = null; for (int i = 0; i < m_allSections.Count; ++i) { if (i == 0) { below = null; m_allSections[i].Transform.PosY = 0; } else { below = m_allSections[i - 1]; m_allSections[i].Transform.PosY = below.Top; } if (i == m_allSections.Count - 1) { above = null; } else { above = m_allSections[i + 1]; } m_allSections[i].Transform.ParentTransform = m_transform; m_allSections[i].PlaceOnTotem(this, above, below); } }
public void BuildFromFile(string filename) { string file = "Content/Levels/" + filename + ".txt"; string[] lines; try { lines = System.IO.File.ReadAllLines(file); } catch { return; } List <TotemSection> sectionsToAdd = new List <TotemSection>(); for (int i = lines.Length - 1; i > -1; --i) { if (lines[i].StartsWith("| |")) { sectionsToAdd.Add(new NormalSection(SectionType.Bilateral)); } if (lines[i].StartsWith("[ |")) { sectionsToAdd.Add(new MetalSection(SectionType.Left)); } if (lines[i].StartsWith("| ]")) { sectionsToAdd.Add(new MetalSection(SectionType.Right)); } if (lines[i].StartsWith("[ ]")) { sectionsToAdd.Add(new MetalSection(SectionType.Bilateral)); } if (lines[i].StartsWith("{ |")) { sectionsToAdd.Add(new SpikeSection(SectionType.Left)); } if (lines[i].StartsWith("| }")) { sectionsToAdd.Add(new SpikeSection(SectionType.Right)); } if (lines[i].StartsWith("{ }")) { sectionsToAdd.Add(new SpikeSection(SectionType.Bilateral)); } if (lines[i].Contains("pD")) { m_powerUpList.Add(new PowerUp(sectionsToAdd.Count, true)); } if (lines[i].Contains("pG")) { m_powerUpList.Add(new PowerUp(sectionsToAdd.Count, false)); } } Console.WriteLine(m_powerUpList.Count); TotemBase totemBase = new TotemBase(); m_allSections.Add(totemBase); m_attachedSections.Add(totemBase); m_allSections.AddRange(sectionsToAdd); m_attachedSections.AddRange(sectionsToAdd); TotemTop totemTop = new TotemTop(); m_allSections.Add(totemTop); m_attachedSections.Add(totemTop); //Place the totem sections in the world TotemSection above = null, below = null; for (int i = 0; i < m_allSections.Count; ++i) { if (i == 0) { below = null; m_allSections[i].Transform.PosY = 0; } else { below = m_allSections[i - 1]; m_allSections[i].Transform.PosY = below.Top; } if (i == m_allSections.Count - 1) { above = null; } else { above = m_allSections[i + 1]; } m_allSections[i].Transform.ParentTransform = m_transform; m_allSections[i].PlaceOnTotem(this, above, below); } // Place powers up in the world // for (int i = 0; i < m_powerUpList.Count; i++) { // Place power up at posY of totem section // int index = m_powerUpList[i].IndexTotemToPlacePowerUp; m_powerUpList[i].Transform.ParentTransform = m_transform; m_powerUpList[i].Transform.PosY = m_allSections[index].Transform.PosY - deltaPosYCorrection; // Place power up at left or right // if (m_powerUpList[i].IsToLeft) { m_powerUpList[i].Transform.PosX = -distanceFromTotemCenter; } else { m_powerUpList[i].Transform.PosX = distanceFromTotemCenter; } } }
public void BuildFromFile(string filename) { string file = "Content/Levels/" + filename + ".txt"; string[] lines; try { lines = System.IO.File.ReadAllLines(file); } catch { return; } List<TotemSection> sectionsToAdd = new List<TotemSection>(); for(int i = lines.Length - 1; i > -1; --i) { if (lines[i].StartsWith("| |")) sectionsToAdd.Add(new NormalSection(SectionType.Bilateral)); if (lines[i].StartsWith("[ |")) sectionsToAdd.Add(new MetalSection(SectionType.Left)); if (lines[i].StartsWith("| ]")) sectionsToAdd.Add(new MetalSection(SectionType.Right)); if (lines[i].StartsWith("[ ]")) sectionsToAdd.Add(new MetalSection(SectionType.Bilateral)); if (lines[i].StartsWith("{ |")) sectionsToAdd.Add(new SpikeSection(SectionType.Left)); if (lines[i].StartsWith("| }")) sectionsToAdd.Add(new SpikeSection(SectionType.Right)); if (lines[i].StartsWith("{ }")) sectionsToAdd.Add(new SpikeSection(SectionType.Bilateral)); if (lines[i].Contains("pD")) { m_powerUpList.Add(new PowerUp(sectionsToAdd.Count, true)); } if (lines[i].Contains("pG")) { m_powerUpList.Add(new PowerUp(sectionsToAdd.Count, false)); } } Console.WriteLine(m_powerUpList.Count); TotemBase totemBase = new TotemBase(); m_allSections.Add(totemBase); m_attachedSections.Add(totemBase); m_allSections.AddRange(sectionsToAdd); m_attachedSections.AddRange(sectionsToAdd); TotemTop totemTop = new TotemTop(); m_allSections.Add(totemTop); m_attachedSections.Add(totemTop); //Place the totem sections in the world TotemSection above = null, below = null; for (int i = 0; i < m_allSections.Count; ++i) { if (i == 0) { below = null; m_allSections[i].Transform.PosY = 0; } else { below = m_allSections[i - 1]; m_allSections[i].Transform.PosY = below.Top; } if (i == m_allSections.Count - 1) { above = null; } else { above = m_allSections[i + 1]; } m_allSections[i].Transform.ParentTransform = m_transform; m_allSections[i].PlaceOnTotem(this, above, below); } // Place powers up in the world // for (int i = 0; i < m_powerUpList.Count; i++) { // Place power up at posY of totem section // int index = m_powerUpList[i].IndexTotemToPlacePowerUp; m_powerUpList[i].Transform.ParentTransform = m_transform; m_powerUpList[i].Transform.PosY = m_allSections[index].Transform.PosY - deltaPosYCorrection; // Place power up at left or right // if (m_powerUpList[i].IsToLeft) { m_powerUpList[i].Transform.PosX = -distanceFromTotemCenter; } else { m_powerUpList[i].Transform.PosX = distanceFromTotemCenter; } } }