Example #1
0
 void Start()
 {
     dead          = false;
     crates        = GameObject.FindGameObjectsWithTag("crates"); // gets a list of all crates
     parts         = GameObject.FindGameObjectsWithTag("parts");  // likewise for parts
     anim          = GetComponent <Animator> ();                  // gets this objects animator
     has_vac       = false;                                       // initial values of tools / key
     unlocked_vac  = false;
     has_bull      = false;
     unlocked_bull = false;
     has_tool      = false;
     unlocked_tool = false;
     has_key       = false;
     HideVac();         // hide tools
     HideBull();
     HideTool();
     // gui stuff
     health    = 10;
     resources = 0;
     SetGUIText();
     // these numbers come from editor lighting settings - RGB & current brightness
     myColour = new Color(0.1838235F, 0.1865268F, 0.1865268F, 0.1865268F);
     // i like to think this is bitbots alarm clock
     SoundManagerScript.Playsound("beeps");
 }
 // player not near door, close door
 private void OnTriggerExit2D(Collider2D collision)
 {
     if (collision.gameObject.name == "player")
     {
         anim.SetBool("player_near", false);
         SoundManagerScript.Playsound("doorclose");
     }
 }
 // player near door - open door
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.name == "player")
     {
         anim.SetBool("player_near", true);
         SoundManagerScript.Playsound("dooropen");
     }
 }
Example #4
0
 private void OnTriggerEnter2D(Collider2D col)
 {
     if (col.transform.tag == "Player")
     {
         KomponenGerak.Damage(1);
         StartCoroutine(KomponenGerak.Knockback(0.5f, KomponenGerak.transform.position));
         SoundManagerScript.Playsound("spikeHit");
     }
 }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        infoKoin.text = " : " + koin.ToString() + "/8";

        if (ulang == true)
        {
            transform.position = mulai;
            ulang = false;
        }

        if (nyawa <= 0)
        {
            Destroy(gameObject);
            kalah.SetActive(true);
        }
        else if (koin >= 8)
        {
            lontara.SetActive(true);
            Destroy(gameObject);
        }

        if (tanah == true)
        {
            anim.SetBool("lompat", false);
        }
        else
        {
            anim.SetBool("lompat", true);
        }

        tanah = Physics2D.OverlapCircle(deteksitanah.position, jangkauan, targetlayer);
        if (Input.GetKey(KeyCode.D))
        {
            anim.SetBool("lari", true);
            transform.Translate(Vector2.right * kecepatan * Time.deltaTime);
            pindah = -1;
        }
        else if (Input.GetKey(KeyCode.A))
        {
            anim.SetBool("lari", true);
            transform.Translate(Vector2.left * kecepatan * Time.deltaTime);
            pindah = 1;
        }
        else
        {
            anim.SetBool("lari", false);
        }

        if (tanah == true && (Input.GetKey(KeyCode.Space)))
        {
            lompat.AddForce(new Vector2(0, kekuatanLompat));
            SoundManagerScript.Playsound("jump");
        }

        if (pindah > 0 && !balik)
        {
            balikBadan();
        }
        else if (pindah < 0 && balik)
        {
            balikBadan();
        }
    }
Example #6
0
    // player interaction via keyboard
    private void GetInput()
    {
        // reset values
        direction = Vector3.zero;
        rot       = Vector3.zero;
        anim.SetBool("moving", false);
        // set speed
        speed = 2.5f;
        // WASD controls - we dont was else if, as players
        // should be able to bank sideways
        if (Input.GetKey(KeyCode.W))
        {
            direction += Vector3.up;
            anim.SetBool("moving", true);
            SoundManagerScript.Playsound("player_move");
        }
        if (Input.GetKey(KeyCode.A))
        {
            rot += new Vector3(0, 0, 180);
            anim.SetBool("moving", true);
            SoundManagerScript.Playsound("player_move");
        }
        if (Input.GetKey(KeyCode.S))
        {
            direction += Vector3.down;
            anim.SetBool("moving", true);
            SoundManagerScript.Playsound("player_move");
        }
        if (Input.GetKey(KeyCode.D))
        {
            rot += new Vector3(0, 0, -180);
            anim.SetBool("moving", true);
            SoundManagerScript.Playsound("player_move");
        }
        // booster
        if (Input.GetKey(KeyCode.Q))
        {
            speed = speed * 2;
        }
        // show vacuum
        if (Input.GetKeyDown(KeyCode.V))
        {
            if (unlocked_vac == true)
            {
                SoundManagerScript.Playsound("pickup");
                has_vac = !has_vac;
                if (has_vac == false)
                {
                    HideVac();
                }
                if (has_vac == true)
                {
                    HideBull();
                    HideTool();
                    has_bull = false;
                    has_tool = false;
                    ShowVac();
                }
            }
        }
        // show bulldozer
        if (Input.GetKeyDown(KeyCode.B))
        {
            if (unlocked_bull == true)
            {
                SoundManagerScript.Playsound("pickup");
                has_bull = !has_bull;
                if (has_bull == false)
                {
                    HideBull();
                }
                if (has_bull == true)
                {
                    HideVac();
                    HideTool();
                    has_vac  = false;
                    has_tool = false;
                    ShowBull();
                }
            }
        }

        // show tool
        if (Input.GetKeyDown(KeyCode.C))
        {
            if (unlocked_tool == true)
            {
                SoundManagerScript.Playsound("pickup");
                has_tool = !has_tool;
                if (has_tool == false)
                {
                    HideTool();
                }
                if (has_tool == true)
                {
                    HideVac();
                    HideBull();
                    has_vac  = false;
                    has_bull = false;
                    ShowTool();
                }
            }
        }
        // end of player keyboard interactions
    }
Example #7
0
    // COLLISIONS
    // note - some collisions have a pause (screen flash red)
    // using waitforseconds, which yield a return object,
    // therefor method is ienumerator
    IEnumerator OnTriggerEnter2D(Collider2D collision)
    {
        // green blob collisions
        if (collision.gameObject.CompareTag("globs"))
        {
            if (has_vac == true)
            {
                SoundManagerScript.Playsound("hoover");
                collision.gameObject.SetActive(false);
                resources = resources + 1;
                SetGUIText();
            }
            if (has_vac == false)
            {
                health = health - 1;
                SetGUIText();
                SoundManagerScript.Playsound("warning");
                RenderSettings.ambientLight = Color.red;
                yield return(new WaitForSeconds(0.3F));

                RenderSettings.ambientLight = myColour;
            }
        }
        // part collisions
        if (collision.gameObject.CompareTag("parts"))
        {
            if (has_vac == true)
            {
                SoundManagerScript.Playsound("hoover");
                collision.gameObject.SetActive(false);
                resources = resources + 2;
                SetGUIText();
            }
        }
        // wire collisions
        if (collision.gameObject.CompareTag("wires"))
        {
            if (has_tool == true)
            {
                SoundManagerScript.Playsound("wirefix");
                collision.gameObject.SetActive(false);
                RenderSettings.ambientLight = Color.blue;
                yield return(new WaitForSeconds(0.2F));

                RenderSettings.ambientLight = myColour;
            }
            if (has_tool == false)
            {
                health = health - 15;                 // instant death if you hit a live wire
                SetGUIText();
                RenderSettings.ambientLight = Color.red;
                yield return(new WaitForSeconds(1F));

                RenderSettings.ambientLight = myColour;
            }
        }

        // pickup collisions (unlocking tools)
        if (collision.gameObject.CompareTag("bull_pickup"))
        {
            collision.gameObject.SetActive(false);
            has_bull      = true;
            unlocked_bull = true;
            ShowBull();             // in demo there is predetermined order of tool unlocks
            HideVac();              // but future levels may change order
            HideTool();             // so hide other tools
            has_vac  = false;
            has_tool = false;
            SoundManagerScript.Playsound("pickup");
        }
        if (collision.gameObject.CompareTag("vac_pickup"))
        {
            collision.gameObject.SetActive(false);
            has_vac      = true;
            unlocked_vac = true;
            ShowVac();
            HideBull();
            HideTool();
            has_bull = false;
            has_tool = false;
            SoundManagerScript.Playsound("pickup");
        }
        if (collision.gameObject.CompareTag("tool_pickup"))
        {
            collision.gameObject.SetActive(false);
            has_tool      = true;
            unlocked_tool = true;
            ShowTool();
            HideBull();
            HideVac();
            has_bull = false;
            has_vac  = false;
            SoundManagerScript.Playsound("pickup");
        }
        if (collision.gameObject.CompareTag("key"))
        {
            SoundManagerScript.Playsound("pickup");
            collision.gameObject.SetActive(false);
            has_key = true;
            SetGUIText();
        }
        // exit collisions
        if (collision.gameObject.CompareTag("exit"))
        {
            if (has_key == true)
            {
                SceneManager.LoadScene("completed", LoadSceneMode.Single);
            }
        }
    }