public Shaker(IGameUnit unit, int speed = 1000) { shaker = new Thread(() => { //var rnd = new Random(unit.GetHashCode()); //var iter = 0; while (true) { isActive.WaitOne(); //unit.Move((int) Math.Pow(-1, ++iter), 0); unit.Rotate(Math.PI / 120); //Thread.Sleep(1 + rnd.Next(speed)); Thread.Sleep(100); } }) { IsBackground = true }; shaker.Start(); }
public Rotor(IGameUnit unit, double delta = Math.PI / 2, int speed = 1000) { this.speed = speed; rotor = new Thread(() => { while (true) { isActive.WaitOne(); unit.Rotate(delta); unit.Move(0, -1); Thread.Sleep(this.speed); } }) { IsBackground = true }; rotor.Start(); ConsoleKeyboard.Get.Add(this); }
/// <summary> /// Draw! /// </summary> /// <param name="args">The command-line arguments.</param> public static void Main(string[] args) { Console.CursorVisible = false; Console.BackgroundColor = ConsoleHelpers.Convert(background); new Thread(() => { var height = Console.WindowHeight; var width = Console.WindowWidth; while (true) { if (height != Console.WindowHeight || width != Console.WindowWidth) { height = Console.WindowHeight; width = Console.WindowWidth; ConsoleResizeEvent(height, width); } Thread.Sleep(100); } }) { IsBackground = true }.Start(); mesh = CreateMesh(); about = CreateAbout(Console.WindowWidth); help = CreateHelp(); ClearScreen(); mesh.InvalidateEvent += Update; while (true) { info(step); if (toggleHelp) { help.Draw(); } if (toggleAbout) { about.Draw(); } var key = Console.ReadKey(false).Key; ConsoleHelpers.FillRect(Console.BackgroundColor); if (key == ConsoleKey.F1 || key == ConsoleKey.F) { toggleAbout = !toggleAbout; // about.Clear(); mesh.Draw(); } if (key == ConsoleKey.H) { toggleHelp = !toggleHelp; // help.Clear(); mesh.Draw(); } if (key == ConsoleKey.Escape) { break; } else if (key == ConsoleKey.LeftArrow) { mesh.Move(-step, 0); } else if (key == ConsoleKey.RightArrow) { mesh.Move(step, 0); } else if (key == ConsoleKey.UpArrow) { mesh.Move(0, step); } else if (key == ConsoleKey.DownArrow) { mesh.Move(0, -step); } else if (key == ConsoleKey.E) { mesh.Rotate(Math.PI / 12); } else if (key == ConsoleKey.W) { mesh.Rotate(-Math.PI / 12); } else if (key == ConsoleKey.S) { ang = 0; step = 2; mesh = CreateMesh(); about = CreateAbout(Console.WindowWidth); help = CreateHelp(); ClearScreen(); } else if (key == ConsoleKey.Subtract && step > 1) { step--; mesh.Draw(); } else if (key == ConsoleKey.Add) { step++; mesh.Draw(); } else { mesh.Draw(); } } Console.SetCursorPosition(0, 0); }