// Use this for initialization
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }
        Time.timeScale = 1;
        pause_menu.SetActive(false); // hide pause menu (default)
        paused = false;
        if (Constant.current_level == 1)
        {
            this.p_1       = Constant.level_1_p_1;
            this.p_2       = Constant.level_1_p_2;
            this.p_3       = Constant.level_1_p_3;
            this.p_4       = Constant.level_1_p_4;
            this.level_max = Constant.level_1_max;

            this.backdrop       = GameObject.Find("BackgroundScene");
            m_backdrop_renderer = backdrop.GetComponent <Renderer>();
            groundSegments.Add(Instantiate(ground, new Vector3(-8.29f, -5.4f, 9.94f), Quaternion.Euler(0, 0, 180)));// add initial tile
        }
        else
        {
            this.p_1       = Constant.level_2_p_1;
            this.p_2       = Constant.level_2_p_2;
            this.p_3       = Constant.level_2_p_3;
            this.p_4       = Constant.level_2_p_4;
            this.level_max = Constant.level_2_max;
        }
        m_progress_renderer = level_progress.GetComponent <Image>();
    }
 private void InitializePanelController(UIPanelController panelController, object panelConfigurationPayload)
 {
     if (panelController != null)
     {
         panelController.navigationController = this;
         panelController.OnPanelPushed(panelConfigurationPayload);
     }
 }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        UpdateHealth();
        UpdateGUIText();
        if (Input.GetKeyDown(KeyCode.F))
        {
            WalkerHit();
        }

        if (m_PlayerHealth == 0 || m_PlayerHealth < 0)
        {
            m_PlayerAnimator.SetTrigger("Death");
            FreezeMovement();
            UIPanelController.getInstance().viewGameOver(Constant.current_level, false);
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        // Move the Main Character Left and Right
        float moveHorizontal = Input.GetAxis("Horizontal") * Time.deltaTime;

        //Check weather Freeze Movement command has issued
        if (m_freezeMovement)
        {
            moveHorizontal = 0f;
        }

        #region Character Rotation According to Axes
        if ((moveHorizontal > 0) && (m_rotatedRight == false))
        {
            mainCharacter.transform.Rotate(Vector3.up * 180);
            m_rotatedLeft  = false;
            m_rotatedRight = true;
        }
        else if ((moveHorizontal < 0) && (m_rotatedLeft == false))
        {
            mainCharacter.transform.Rotate(Vector3.down * 180);
            m_rotatedRight = false;
            m_rotatedLeft  = true;
        }
        #endregion Character Rotation According to Axes

        // Detect if the Shift key is pressed
        bool shiftPressed = Input.GetKey(KeyCode.LeftShift);

        if (shiftPressed)
        {
            m_walkSpeed = m_runningSpeed;
        }
        else
        {
            m_walkSpeed = m_tempWalkSpeed;
        }

        UIPanelController.m_speed = m_walkSpeed;         // update UI Controller speed

        float levelMax = 0;
        // get current level max distance
        if (Constant.current_level == 1)
        {
            levelMax = Constant.level_1_max;
        }
        else if (Constant.current_level == 2)
        {
            levelMax = Constant.level_2_max;
        }

        #region Player Movement
        // Move the character using regular pixel movements
        if (moveHorizontal > 0 && move_x < levelMax + Constant.view_margin_right)
        {
            move_x = move_x + m_walkSpeed;
            mainCharacter.transform.position = new Vector3(move_x, mainCharacter.transform.position.y, move_z);
        }
        else if (moveHorizontal < 0)
        {
            move_x = move_x - m_walkSpeed;
            mainCharacter.transform.position = new Vector3(move_x, mainCharacter.transform.position.y, move_z);
        }
        #endregion Player Movement

        UIPanelController.m_move_x = move_x;         // update player position

        #region Running & Walking
        // Set the Animation to Walking, Running
        if ((m_walkSpeed == m_runningSpeed) && (moveHorizontal != 0))
        {
            // Player is Running
            m_movementAnimationBlendSpeed = Mathf.MoveTowards(m_movementAnimationBlendSpeed, 0.5f, m_movementTransitionSpeed * Time.deltaTime + 0.05f);              // Slowly increase the blend creating a realisting transitiion.
            m_Animator.SetFloat("Walk_Run_Blend", m_movementAnimationBlendSpeed);
        }
        else if ((m_walkSpeed < m_runningSpeed) && (moveHorizontal != 0))
        {
            // Player is Walking
            m_movementAnimationBlendSpeed = Mathf.MoveTowards(m_movementAnimationBlendSpeed, 0.25f, m_movementTransitionSpeed * Time.deltaTime);
            m_Animator.SetFloat("Walk_Run_Blend", m_movementAnimationBlendSpeed);
        }
        else if (moveHorizontal == 0)
        {
            // Set the Player to idle state
            m_movementAnimationBlendSpeed = Mathf.MoveTowards(m_movementAnimationBlendSpeed, 0, m_movementTransitionSpeed * (Time.deltaTime + 0.02f));
            m_Animator.SetFloat("Walk_Run_Blend", m_movementAnimationBlendSpeed);
        }

        // Limit the user from going beyond the camera limit
        if (mainCharacter.transform.position.x < -10.00f)
        {
            move_x = -10.00f;
            m_movementAnimationBlendSpeed = Mathf.MoveTowards(m_movementAnimationBlendSpeed, 0, m_movementTransitionSpeed * (Time.deltaTime + 0.02f));
            m_Animator.SetFloat("Walk_Run_Blend", m_movementAnimationBlendSpeed);
        }
        #endregion Running & Walking

        // Trigger Jumping
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (!m_Animator.GetCurrentAnimatorStateInfo(0).IsName("Jump") && mainCharacter.transform.position.y < 1)
            {
                m_Animator.SetTrigger("Jump");
                rgbd.AddForce(new Vector3(0, m_jumpHeight, 0), ForceMode.Impulse);
            }
        }

        // Trigger Sword Attack
        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            float pauseXMovement = mainCharacter.transform.position.x;
            move_x = pauseXMovement;
            m_Animator.SetTrigger("Sword_Attack");
            AudioSource.clip = SwordSwoosh;
            AudioSource.Play();
        }

        // Detect when the player is falling
        if (mainCharacter.transform.position.y < -4.8f && m_isFalling == false)
        {
            m_isFalling      = true;
            AudioSource.clip = FallingScream;
            AudioSource.Play();
            UIPanelController.getInstance().viewGameOver(Constant.current_level, true);
        }
    }
Exemplo n.º 5
0
    public void displayHealthBar()
    {
        this.anim.SetBool("dead", false);
        // check hit status and sound play to change state
        if (this.get_hit && !this.audioSource.isPlaying)
        {
            //this.anim.SetInteger("idle_hit", 0);
            this.get_hit = false;
        }

        if (this.health > 95)
        {
            this.offset_x = 0;
            this.offset_y = 0.86f;
        }
        else if (this.health > 85)
        {
            this.offset_x = 0;
            this.offset_y = 0.72f;
        }
        else if (this.health > 75)
        {
            this.offset_x = 0;
            this.offset_y = 0.58f;
        }
        else if (this.health > 50)
        {
            this.offset_x = 0;
            this.offset_y = 0.437f;
        }
        else if (this.health > 35)
        {
            this.offset_x = 0;
            this.offset_y = 0.293f;
        }
        else if (this.health > 20)
        {
            this.offset_x = 0;
            this.offset_y = 0.15f;
        }
        else if (this.health > 10)
        {
            this.offset_x = 0;
            this.offset_y = 0;
        }
        else
        {
            if (!this.dead)
            {
                // dead
                this.dead = true;
                this.anim.SetBool("dead", true);
                this.audioSource.clip = this.death_clip;
                this.audioSource.Play();
                Destroy(this.gameObject, 3f);
                // update level progress
                UIPanelController.getInstance().viewGameOver(1, true);
            }
        }
        this.healthBar_renderer.material.mainTextureOffset = new Vector2(this.offset_x, this.offset_y);
    }