Example #1
0
        public void GameLoop()
        {
            Invalidate();
            bool newLevel = false;
            while (game.Level.Ship.IsAlive == true)
            {
                // Timer for logic (40FPS)
                Thread.Sleep(25);
                game.PhysicsUpdate();
                Invalidate();
                if (game.Level.Ship.IsZoning == true)
                {
                    Thread.Sleep(2000);
                    newLevel = game.UpdateLevel();
                    drawBuffer = new DrawBuffer(game.Level);
                }
                // Calls GameForm_Paint
                //Invalidate();
                //foreach (Enemy enemy in game.Level.Enemies)
                //{
                //    Invalidate(new Rectangle(new Point((int)enemy.Position.X - enemy.Width, (int)enemy.Position.Y), new Size(enemy.Width * 3, enemy.Height)));
                //}
                //foreach (Coin enemy in game.Level.Coins)
                //{
                //    Invalidate(new Rectangle(new Point((int)enemy.Position.X - enemy.Width, (int)enemy.Position.Y), new Size(enemy.Width * 3, enemy.Height)));
                //}
            }

            // GameOver Loop
            //DateTime timer = DateTime.Now;
            while (game != null && drawBuffer != null)
            {
                Thread.Sleep(25);
                    Invalidate();
            }
        }
Example #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            btnStart.Text = "Reset";
            Start:
            if (thread == null)
            {
                btnStart.Hide();

                time = new DateTime();
                game = new GameService();
                drawBuffer = new DrawBuffer(game.Level);
                thread = new Thread(new ThreadStart(GameLoop));
                thread.Start();
                keysThread = new Thread(new ThreadStart(KeyLoop));
                keysThread.Start();
            }
            else
            {
                game.Level.Ship.IsAlive = false;
                time = DateTime.Now;
                while (time.AddSeconds(2) > DateTime.Now)
                {
                    // Needed to let the game end
                }
                game.Level.Dispose();
                game = null;
                //game.Level.Ship.Direction = left;
                thread = null;
                m_filter = null;
                keysThread = null;
                m_filter = new KeyMessageFilter();
                Application.AddMessageFilter(m_filter);
                goto Start;
            }
        }