Exemple #1
0
    private void OnCollisionEnter2D(Collision2D coll)
    {
        //Time.timeScale = 0f;
        if (coll.gameObject.tag == "Note")
        {
            GameObject  eManager   = GameObject.Find("BossManager");
            BossManager eManScript = eManager.GetComponent <BossManager>();
            eManScript.CancelSpawn();
            foreach (GameObject ge in eManScript.currentNotes)
            {
                BossMoveScript eMoveScript = ge.GetComponent <BossMoveScript>();
                eMoveScript.BossIsMoving = false;
            }

            /*foreach (GameObject ge in eManScript.currentMonster)
             * {
             *  BossMoveScript eMoveScript = ge.GetComponent<BossMoveScript>();
             *  eMoveScript.BossIsMoving = false;
             * }*/
            foreach (GameObject go in GameObject.FindGameObjectsWithTag("background"))
            {
                go.GetComponent <background_scroll> ().isMoving = false;
            }
        }
    }
 private void OnCollisionEnter2D(Collision2D coll)
 {
     if (coll.gameObject.tag == "Note")
     {
         BossMoveScript eMoveScript = coll.gameObject.GetComponent <BossMoveScript>();
         eMoveScript.BossIsInThreshold = true;
     }
 }
    void IncreaseScore(GameObject ge)
    {
        float modifier = 1f;

        if (sandalActive == true)
        {
            modifier = 2f;
        }
        BossMoveScript ems = ge.GetComponent <BossMoveScript>();

        score = score + (ems.pointValue * modifier);
    }
    // Update is called once per frame
    void Update()
    {
//		if (Input.GetKeyDown (KeyCode.Space)) {
//			gameObject.GetComponent<SpriteExploder> ().ExplodeSprite ();
//		}

        if (BossIsMoving)
        {
            transform.Translate(userDirection * movespeed * Time.deltaTime);
            if (this.transform.position.x <= -0.5f)
            {
                BossIsInThreshold = true;
            }
            if (this.transform.position.x <= -1.5f)
            {
                GameObject  eManager   = GameObject.Find("BossManager");
                BossManager eManScript = eManager.GetComponent <BossManager>();
                eManScript.CancelSpawn();
                foreach (GameObject ge in eManScript.currentNotes)
                {
                    BossMoveScript eMoveScript = ge.GetComponent <BossMoveScript>();
                    eMoveScript.BossIsMoving = false;
                }

                /*foreach (GameObject ge in eManScript.currentMonster)
                 * {
                 *      BossMoveScript eMoveScript = ge.GetComponent<BossMoveScript>();
                 *      eMoveScript.BossIsMoving = false;
                 * }*/
                foreach (GameObject go in GameObject.FindGameObjectsWithTag("background"))
                {
                    go.GetComponent <background_scroll> ().isMoving = false;
                }
            }
        }
        else
        {
            if (BossIsInThreshold)
            {
                GameObject  eManager   = GameObject.Find("BossManager");
                BossManager eManScript = eManager.GetComponent <BossManager>();
                if (eManScript.fleeceActive == false)
                {
                    if (pointValue > 20.1)
                    {
                        pointValue = pointValue - 0.1f;
                    }
                }
            }
        }
    }
    public void KeyPress(int key)  //called when a key has been pressed
    {
        if (limit > 0)
        {
            GameObject     firstNote = currentNotes.Peek();
            BossMoveScript ems       = firstNote.GetComponent <BossMoveScript>();
            if (ems.BossIsInThreshold == true && ems.assignedKey == key)
            {
                streak++;
                GameObject toBeDeleted = currentNotes.Dequeue();//dequeue first in queue

                foreach (GameObject ge in currentNotes)
                {
                    BossMoveScript eMoveScript = ge.GetComponent <BossMoveScript>();
                    eMoveScript.BossIsMoving = true;
                }
                Destroy(toBeDeleted);
                limit--;

                //toBeDeleted = currentMonster.Dequeue();//dequeue first in queue

                // sprite exploder stuff
                try {
                    // trigger the explosion
                    toBeDeleted.GetComponent <SpriteExploder>().ExplodeSprite();
                    // unparent the explosion object so it doesn't get deleted below
                    Transform explosion = toBeDeleted.transform.Find("ExplosionPixels");
                    explosion.transform.parent = null;
                }
                // for all the enemies who don't explode yet
                catch (System.Exception ex) {
                    print("Error: I probably don't have a sprite exploder.");
                    print(ex.Message);
                }

                IncreaseScore(toBeDeleted);//increment the score
                UpdateUI();
                top_bar.setPercentage(score / 2400f);

                /*foreach (GameObject ge in currentMonster)
                 * {
                 *  BossMoveScript eMoveScript = ge.GetComponent<BossMoveScript>();
                 *  eMoveScript.BossIsMoving = true;
                 * }
                 * Destroy(toBeDeleted);*/
                foreach (GameObject go in GameObject.FindGameObjectsWithTag("background"))
                {
                    go.GetComponent <background_scroll>().isMoving = true;
                }
                IncreaseEnemyCount();
                if (!IsInvoking("Spawn"))
                {
                    InvokeRepeating("Spawn", 1, spawnTime);
                }
                if ((streak % 10) == 0 && streak != 0)
                {
                    IncreaseThreshold();
                }
            }
            else
            {
                streak = 0;
                bad_hit++;
                if (bad_hit >= 3)
                {
                    if (AmbrosiaCount >= 1)
                    {
                        AmbrosiaCount--;
                        statusText.text = "Ambrosia Activated ";
                        UpdateUI();
                        bad_hit = 0;
                    }
                    else
                    {
                        DecreaseThreshold();
                    }
                }
            }
        }

        noteText.text = "Last note pressed: " + noteNames[key - 21];
    }