public static void SortParticleString(string particleString, Vector2f position) { switch (particleString) { case "t": Color[,] c = new Color[1, 1]; c[0, 0] = Color.Yellow; Image i = new Image(c); ParticleSystem par = new ParticleSystem(position, new Vector2f(0, 0), 200, 10, 35.4f, new Texture(i)); Program.ClientDelegate del = null; int count = 0; del = () => { Program.Shake = true; count++; if (count > 6) { Program.Shake = false; Program.OnUpdate -= del; } }; Program.OnUpdate += del; break; } }
/// <param name="repeatInterval">A lazy modulus check, so 2 = every second frame, 10 = every tenth frame etc.</param> /// <param name="repeatAmount">0 = infinite, use sparingly.</param> public static void AddRelativeRepeat(int startInterval, int repeatInterval, int repeatAmount, Action action) { bool active = false; int count = 0; int elapseTime = startInterval + Program.ElapsedGameTime; Program.ClientDelegate delAction = null; delAction = delegate() { int newTime = Program.ElapsedGameTime; if (newTime > elapseTime) { active = true; } if (active && Program.ElapsedGameTime % repeatInterval == 0) { Task.Factory.StartNew(action); count++; if (count >= repeatAmount && repeatAmount != 0) { Program.OnUpdate -= delAction; } } }; Program.OnUpdate += delAction; }
public static void AddRelative(int interval, Action action) { //Self contained, will unhook itself from OnUpdate via delegate wizardry. int elapseTime = interval + Program.ElapsedGameTime; Program.ClientDelegate delAction = null; delAction = delegate() { int newTime = Program.ElapsedGameTime; if (newTime > elapseTime) { Task.Factory.StartNew(action); Program.OnUpdate -= delAction; } }; Program.OnUpdate += delAction; }
public void WriteLine(string str) { bool skipLineCount = false; PooledText tex = textPool.GetObject(); tex.Position = new Vector2f(0, (14 * lineCount)); tex.ParticleY = 0;; tex.Font = Font; tex.Text = str; tex.CharacterSize = 14; if (str.Contains("\n")) //Split any new lines and send back through this method. { string[] newlineSplit = Regex.Split(str, "\n"); string colourAddition = ""; bool cASkipNextWrite = false; foreach (string ns in newlineSplit) { if (string.IsNullOrEmpty(ns)) { continue; } if (ns.Contains("`")) //If it was using a colour set it on the new line too. { for (int i = ns.Length - 1; i > 0; i--) { if (ns[i] == '`') { WriteLine(ns); colourAddition = "`" + ns[i + 1]; cASkipNextWrite = true; break; } } } if (!cASkipNextWrite) { WriteLine(colourAddition + ns); colourAddition = ""; } cASkipNextWrite = false; } return; } string wwColourAddition = ""; if (str.Length > maxCharPerLine) //Word Wrap. { for (int i = maxCharPerLine; i > 0; i--) { if (str[i] == ' ') { tex.Text = str.Substring(0, i); if (tex.GetLocalWidth() > Program.Window.Size.X) { continue; } skipLineCount = true; lineCount++; //Check for colours and pass on to next string. if (tex.PureText.Contains('`')) { for (int o = tex.PureText.Length - 1; o > 0; o--) { if (tex.PureText[o] == '`') { wwColourAddition = "`" + tex.PureText[o + 1]; break; } } } WriteLine(wwColourAddition + str.Substring(i + 1, str.Length - i - 1)); wwColourAddition = ""; break; } } } textList.Add(tex); //Scroll text. int chunkCount = tex.TextChunks.Count(); Text[] chunks = new Text[tex.TextChunks.Length]; for (int u = 0; u < chunks.Length; u++) { chunks[u] = new Text(tex.TextChunks[u]); tex.TextChunks[u].DisplayedString = ""; } int chunkPosition = 0; int internalChunkPosition = 0; Program.ClientDelegate delDelegate = null; delDelegate = () => { for (int p = 0; p < 2; p++) { if (chunks[chunkPosition].DisplayedString.Length > internalChunkPosition) { internalChunkPosition += 4; if (internalChunkPosition > chunks[chunkPosition].DisplayedString.Length) { internalChunkPosition -= 3; } tex.TextChunks[chunkPosition].DisplayedString = chunks[chunkPosition].DisplayedString.Substring(0, internalChunkPosition); } else { internalChunkPosition = 0; chunkPosition++; if (chunkPosition >= chunks.Length) { Program.OnUpdate -= delDelegate; break; } } } }; Program.OnUpdate += delDelegate; if (!skipLineCount) { lineCount++; } }