private void h_tick() { var frame = new Bitmap(Level.Size.Width, Level.Size.Height); using (var graphics = Graphics.FromImage(frame)) { Level.Update(); Level.Draw(graphics); graphics.Flush(); } if (Level.Success) { Level = Level.NextLevel(); } if (Level.Failed) { Level = new FailScreen(); } if (m_canvas.Image != null) { m_canvas.Image.Dispose(); } m_canvas.Image = frame; }
private void Update() { if (lives <= 0 && !GameOver) { GameOver = true; Debug.Log("GAME OVER"); GameObject Spawner = GameObject.FindGameObjectWithTag("Car Spawner"); Spawner.SetActive(false); GameObject[] Cars = GameObject.FindGameObjectsWithTag("Car"); for (int i = 0; i < Cars.Length; i++) { Destroy(Cars[i].gameObject); GameObject carexplosion = Instantiate(Explosion, Cars[i].gameObject.transform.position, Player.gameObject.transform.rotation); ExplosionSound.Play(); Destroy(carexplosion.gameObject, 3.9f); } GameObject explosion = Instantiate(Explosion, Player.gameObject.transform.position, Player.gameObject.transform.rotation); ExplosionSound.Play(); Destroy(Player.gameObject); Destroy(explosion.gameObject, 3.9f); gameoverText.SetActive(true); retryText.SetActive(true); FailScreen.SetActive(true); YesText.SetActive(true); NoText.SetActive(true); } }
public void GameOver() { if (win || gameOver) { return; } gameOver = true; dieSource.Play(); FailScreen fs = FindObjectOfType <FailScreen>(true); if (fs) { fs.gameObject.SetActive(true); } Restart(); }
private void _tick() { Bitmap frame = new Bitmap(Level.Size.Width, Level.Size.Height); using (Graphics graphics = Graphics.FromImage(frame)) { Level.Update(); Level.Draw(graphics); graphics.Flush(); } if (Level.Success) { Level = Level.NextLevel(); } if (Level.Failed) { Level = new FailScreen(); } try { _canvas.Invoke(new Action(() => { _canvas.Parent.Size = frame.Size; _canvas.Size = frame.Size; if (_canvas.Image != null) { _canvas.Image.Dispose(); } _canvas.Image = frame; })); } catch (ObjectDisposedException) { } }