Exemplo n.º 1
0
    public void TogglePause()
    {
        var paused = !GlobalGame.Get().currentLevel.GetPause();

        GlobalGame.Get().currentLevel.SetPause(paused);
        pauseMenu.SetActive(paused);
    }
Exemplo n.º 2
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == "Player")
     {
         GlobalGame.Get().currentLevel.PlayerWin();
     }
 }
Exemplo n.º 3
0
    void Update()
    {
        var level = GlobalGame.Get().currentLevel;

        if (level.IsPlayable())
        {
            level.timeSpent   += Time.deltaTime;
            textComponent.text = Mathf.RoundToInt(level.timeSpent).ToString();
        }
    }
Exemplo n.º 4
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == "Player")
     {
         var contact = other.bounds.ClosestPoint(transform.position);
         Instantiate(explosion, contact, Quaternion.identity);
         GlobalGame.Get().currentLevel.PlayerDie();
         Destroy(other.gameObject);
     }
 }
Exemplo n.º 5
0
 public void PlayerWin()
 {
     player.GetComponent <Rigidbody2D> ().velocity = Vector2.zero;
     // Fix the position of the player on finish.
     player.GetComponent <Rigidbody2D> ().bodyType = RigidbodyType2D.Static;
     playerInteractive = false;
     pauseButton.SetActive(false);
     winMenu.SetActive(true);
     // No next level for last level.
     continueButton.SetActive(GlobalGame.Get().levelIndex != GlobalGame.levels.Length - 1);
 }
Exemplo n.º 6
0
 void FixedUpdate()
 {
     if (GlobalGame.Get().currentLevel.IsPlayable() && player != null)
     {
         var desired    = player.transform.position + offset;
         var halfHeight = GetComponent <Camera> ().orthographicSize;
         var halfWidth  = halfHeight / Screen.height * Screen.width;
         desired.x          = Mathf.Min(topRight.x + border - halfWidth, Mathf.Max(bottomLeft.x - border + halfWidth, desired.x));
         desired.y          = Mathf.Min(topRight.y + border - halfHeight, Mathf.Max(bottomLeft.y - border + halfHeight, desired.y));
         transform.position = Vector3.SmoothDamp(transform.position, desired, ref velocity, smoothTime);
     }
 }
Exemplo n.º 7
0
 void SetDeathAndLevelPanel()
 {
     GameObject.Find("Death Value").GetComponent <Text> ().text = GlobalGame.Get().totalDeath.ToString();
     GameObject.Find("Level Value").GetComponent <Text> ().text = (GlobalGame.Get().levelIndex + 1).ToString();
 }
Exemplo n.º 8
0
 public void RestartLevel()
 {
     ++GlobalGame.Get().totalDeath;
     SceneManager.LoadScene(SceneManager.GetActiveScene().name);
 }
Exemplo n.º 9
0
 public void LoadNextLevel()
 {
     SceneManager.LoadScene(GlobalGame.levels [++GlobalGame.Get().levelIndex]);
 }
Exemplo n.º 10
0
 void Awake()
 {
     GlobalGame.Get().currentLevel = this;
 }
Exemplo n.º 11
0
 void Start()
 {
     pauseMenu = GameObject.Find("Menus").transform.Find("Pause Menu").gameObject;
     GlobalGame.Get().currentLevel.SetPause(false);
 }
Exemplo n.º 12
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (EventSystem.current.IsPointerOverGameObject() || EventSystem.current.IsPointerOverGameObject(0) || !GlobalGame.Get().currentLevel.IsPlayable())
            {
                return;
            }
            var mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            mousePosition.z = 0;

            var hits = Physics2D.OverlapPointAll(mousePosition);
            foreach (var hit in hits)
            {
                if (hit.gameObject.tag == "Planet")
                {
                    Destroy(hit.transform.parent.gameObject);
                    Instantiate(explosion, mousePosition, Quaternion.identity);
                    var blasts = Physics2D.OverlapCircleAll(hit.transform.position, blastRadius);
                    foreach (var blast in blasts)
                    {
                        if (blast.gameObject.tag == "Player")
                        {
                            var direction = blast.transform.position - hit.transform.position;
                            direction.Normalize();
                            blast.GetComponent <Rigidbody2D> ().AddForce(blastImpulse * direction, ForceMode2D.Impulse);
                            break;
                        }
                    }
                    return;
                }
            }
            hits = Physics2D.OverlapCircleAll(mousePosition, overlapRadius);
            foreach (var hit in hits)
            {
                if (hit.gameObject.tag == "Planet" || hit.gameObject.tag == "Meteroid")
                {
                    return;
                }
            }
            var newPlanet = Instantiate(planets [Random.Range(0, planets.Length)], (Vector2)mousePosition, Quaternion.identity);
            iTween.ScaleFrom(newPlanet, iTween.Hash("scale", new Vector3(0.1f, 0.1f, 1f), "time", 0.3f));
        }
    }