Example #1
0
 private void SpawnEnemies()
 {
     if (EnemyAppearingSW.Elapsed.TotalSeconds >= 1 / EnemiesPerSecond)
     {
         var enemy = new Enemy(RenderWidth - 1, Rand.Next(0, RenderHeight - 1))
         {
             Health = 25
         };
         Creatures.Add(enemy);
         Enemies.Add(enemy);
         EnemyAppearingSW = Stopwatch.StartNew();
         EnemyAppearingSW.Start();
     }
 }
Example #2
0
        public void Run()
        {
            Running = true;
            Thread t = new Thread(() =>
            {
                Console.CursorVisible = false;

                Stopwatch sw = new Stopwatch();
                EnemyAppearingSW.Start();

                State = GameState.Playing;

                InitMenus();

                Creatures.Add(Character);

                while (Running)
                {
                    sw = Stopwatch.StartNew();
                    sw.Start();

                    ProcessInput();
                    Update();
                    Render();

                    sw.Stop();
                    FrameTime = sw.Elapsed;

                    //if (FrameTime.TotalMilliseconds < 33)
                    //{
                    //    sw.Start();
                    //    Thread.Sleep(TimeSpan.FromMilliseconds(33) - FrameTime);
                    //    sw.Stop();
                    //    FrameTime = sw.Elapsed;
                    //}
                }
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }