Example #1
0
    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Move X", lookDirection.x);
        animator.SetFloat("Move Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        Vector2 position = rigidbody2d.position;

        position = position + move * speed * Time.deltaTime;

        rigidbody2d.MovePosition(position);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }
        else
        {
            InvincibilityEffect.Stop();
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
            this.PlaySound(throwCog);
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayableCharacter character = hit.collider.GetComponent <NonPlayableCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (Input.GetKeyDown(KeyCode.C))
        {
            LaunchProjectile();
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            // position of the center of the player sprite
            Vector2      waistPosition = playerRb.position + Vector2.up * 0.2f;
            RaycastHit2D hit           = Physics2D.Raycast(waistPosition, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)   // hits NPC
            {
                NonPlayableCharacter npc = hit.collider.GetComponent <NonPlayableCharacter>();
                if (npc != null)
                {
                    npc.DisplayDialog();
                }
            }
        }
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        this.Animate(move);

        Vector2 position = rigidbody2d.position;

        position = position + move * Speed * Time.deltaTime;

        rigidbody2d.MovePosition(position);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayableCharacter character = hit.collider.GetComponent <NonPlayableCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }
    }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        if (gameOver == true)
        {
            if (level == 2)
            {
                if (Input.GetKeyDown(KeyCode.R))
                {
                    SceneManager.LoadScene("MainScene");         // this loads the currently active scene
                }
            }

            if (level == 1)
            {
                if (Input.GetKeyDown(KeyCode.R))
                {
                    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);         // this loads the currently active scene
                }
            }
        }



        if (Input.GetKeyDown(KeyCode.T))
        {
            tutorial = true;
            PlaySound(teleportSound);
            tutorialUI.text = "Tutorial Mode";
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            tutorial = false;
            PlaySound(teleportSound);
            tutorialUI.text = "Ready to go!";
        }



        if (tutorial == false)
        {
            if (Input.GetKeyDown(KeyCode.N))
            {
                SceneManager.LoadScene("MainScene");             // this loads the currently active scene
            }
        }

        if (tutorial == true)
        {
            if (Input.GetKeyDown(KeyCode.M))
            {
                SceneManager.LoadScene("Level 3");             // this loads the currently active scene
            }
        }



        if (Input.GetKey("escape"))
        {
            Application.Quit();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayableCharacter character = hit.collider.GetComponent <NonPlayableCharacter>();
                if (character != null)
                {
                    if (scoreValue == 5)
                    {
                        levelChange();
                    }
                    character.DisplayDialog();
                    PlaySound(jambiSound);
                }
            }
        }

        ammoUI.text = "Cogs: " + ammo.ToString();
    }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        EnemyCount count = fixTracker.gameObject.GetComponent <EnemyCount>();

        if (count.fixCount == count.fixRequired && canPlay == true)
        {
            PlaySound(victory);
            canPlay = false;
        }
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        if (Input.GetKeyDown(KeyCode.X) || Input.GetButtonDown("Fire1"))
        {
            //RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.zero * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.down * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                Debug.Log("Raycast has hit the object " + hit.collider.gameObject);
                NonPlayableCharacter character = hit.collider.GetComponent <NonPlayableCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }

                else
                {
                    //ResourceCube();
                    ResourceCube cube = hit.collider.GetComponent <ResourceCube>();
                    cube.GetResources();
                    Destroy(hit.collider.gameObject);
                }
            }
        }

        //if(Input.GetKeyDown(KeyCode.C) && ammo > 0)
        //{
        //   Launch();

        //  PlaySound(throwSound);
        //}
        if (Input.GetButtonDown("Fire3") && ammo > 0)
        {
            Launch();

            PlaySound(throwSound);
        }

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);
        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }
        if (currentHealth <= 0)
        {
            SceneManager.LoadScene(currentScene.name);
        }
    }