Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        currentTime -= Time.deltaTime;
        if (currentTime < 0f)
        {
            currentTime = 0f;
        }

        if (Input.GetButton("Fire1"))
        {
            moveInput = new Vector3(0f, 0f, 0f);
            if (currentTime == 0f)
            {
                GameObject theArrow    = Instantiate(arrow, transform.position, Quaternion.identity);
                arrow      arrowScript = theArrow.GetComponent <arrow>();
                arrowScript.target = bow;
                currentTime        = timer;
            }
        }
        else
        {
            moveInput = new Vector3(Input.GetAxisRaw("Mouse X"), 0f, Input.GetAxisRaw("Mouse Y"));
        }
        Vector3 playerDirection = Vector3.right * Input.GetAxisRaw("Mouse X") + Vector3.forward * Input.GetAxisRaw("Mouse Y");

        transform.rotation = Quaternion.LookRotation(playerDirection, Vector3.up);
        moveVelocity       = moveInput * moveSpeed;
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        float x = 0;
        float y = 0;
        float z = 0;
        float l = float.PositiveInfinity;

        GameObject[] gameObjects = GameObject.FindGameObjectsWithTag("enemyTag");
        foreach (var item in gameObjects)
        {
            float tx = m_fPositionX - item.transform.position.x;
            float ty = m_fPositionY - item.transform.position.y;
            float tl = tx * tx + ty * ty;
            tl = Mathf.Sqrt(tl);
            if (tl < l)
            {
                l = tl;
                x = item.transform.position.x;
                y = item.transform.position.y;
                z = item.transform.position.z;
            }
        }
        if (l < 30)
        {
            if (0 == m_nTickCount)
            {
                m_nTickCount = 150;

                Vector3 worldMousePosition = new Vector3(x, y, z);

                float      arrowRotation = (180 / Mathf.PI) * Mathf.Atan2(worldMousePosition.y - transform.position.y, worldMousePosition.x - transform.position.x);
                GameObject weponObject   = Instantiate(arrowPrefab, new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z), transform.rotation) as GameObject;
                arrow      arrowObject   = (arrow)weponObject.GetComponent <arrow>();
                arrowObject.mousePosition = worldMousePosition;
                arrowObject.arrowRotation = arrowRotation;
            }
            //Debug.Log( true );
        }
        else
        {
            //Debug.Log( false );
        }
        if (0 < m_nTickCount)
        {
            --m_nTickCount;
        }
    }
Exemplo n.º 3
0
    private void unlinked()
    {
        //Sword and bow player
        currentTime -= Time.deltaTime;
        if (currentTime < 0f)
        {
            currentTime = 0f;
        }

        if (Input.GetButton("Fire1"))
        {
            moveInputBow = new Vector3(0f, 0f, 0f);
            if (currentTime == 0f)
            {
                GameObject theArrow    = Instantiate(arrow, transformBow.position, Quaternion.identity);
                arrow      arrowScript = theArrow.GetComponent <arrow>();
                arrowScript.target = bow_obj;
                currentTime        = timer;
            }
        }
        else
        {
            moveInputBow = new Vector3(Input.GetAxisRaw("Mouse X"), 0f, Input.GetAxisRaw("Mouse Y"));
        }

        Vector3 playerDirectionBow = Vector3.right * Input.GetAxisRaw("Mouse X") + Vector3.forward * Input.GetAxisRaw("Mouse Y");

        transformBow.rotation = Quaternion.LookRotation(playerDirectionBow, Vector3.up); //Blowing up the console
        moveVelocityBow       = moveInputBow * moveSpeed;


        //Shield player
        moveInputShield    = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
        moveVelocityShield = moveInputShield * moveSpeed;

        if (!Input.GetButton("Fire2"))
        {
            Vector3 playerDirectionShield = Vector3.right * Input.GetAxisRaw("Horizontal") + Vector3.forward * Input.GetAxisRaw("Vertical");
            if (playerDirectionShield.sqrMagnitude > 0.0f)
            {
                transformShield.rotation = Quaternion.LookRotation(playerDirectionShield, Vector3.up);
            }
        }
    }
Exemplo n.º 4
0
    private void linked()
    {
        HorizontalShield   = Input.GetAxisRaw("Horizontal");
        HorizontalBow      = Input.GetAxisRaw("Horizontal");
        VerticalShield     = Input.GetAxisRaw("Vertical");
        VerticalBow        = Input.GetAxisRaw("Vertical");
        moveInputShield    = rotatePointAroundAxis(new Vector3(HorizontalShield, 0f, VerticalShield), rotateShield, new Vector3(0, 1, 0));
        moveInputBow       = rotatePointAroundAxis(new Vector3(HorizontalBow, 0f, VerticalBow), rotateBow, new Vector3(0, 1, 0));
        moveVelocityShield = moveInputShield * moveSpeed;
        moveVelocityBow    = moveInputBow * moveSpeed;

        Vector3 playerDirectionShield = rotatePointAroundAxis(Vector3.right * Input.GetAxisRaw("Mouse X") + Vector3.forward * Input.GetAxisRaw("Mouse Y"), rotateShield, new Vector3(0, 1, 0));
        Vector3 playerDirectionBow    = rotatePointAroundAxis(Vector3.right * Input.GetAxisRaw("Mouse X") + Vector3.forward * Input.GetAxisRaw("Mouse Y"), rotateBow, new Vector3(0, 1, 0));

        if (playerDirectionShield.sqrMagnitude > 0.0f)
        {
            transformShield.rotation = Quaternion.LookRotation(playerDirectionShield, Vector3.up);
        }
        if (playerDirectionBow.sqrMagnitude > 0.0f)
        {
            transformBow.rotation = Quaternion.LookRotation(playerDirectionBow, Vector3.up);
        }

        currentTime -= Time.deltaTime;
        if (currentTime < 0f)
        {
            currentTime = 0f;
        }

        if (Input.GetButton("Fire1"))
        {
            if (currentTime == 0f)
            {
                GameObject theArrow    = Instantiate(arrow, transformBow.position, Quaternion.identity);
                arrow      arrowScript = theArrow.GetComponent <arrow>();
                arrowScript.target = bow_obj;
                currentTime        = timer;
            }
        }
    }
Exemplo n.º 5
0
 // Update is called once per frame
 void Update()
 {
     if (shoot == true)
     {
         //arrow delay:
         if (time < Time.time)
         {
             //create the arrow
             arrow arrow = Instantiate <arrow>(myarrow, transform.position, transform.rotation) as arrow;
             //set direction and speed
             arrow.direction = direction2;
             //when shooting from the left we want to rotate the arrow accordingly
             if (fromLeft == true)
             {
                 arrow.transform.rotation = Quaternion.Euler(0, 0, 180);
             }
             else
             {
                 arrow.transform.rotation = Quaternion.Euler(0, 0, 0);
             }
             time = Time.time + arrowDelay;
         }
     }
 }
Exemplo n.º 6
0
    void Update()
    {
        if (weponMenuOpen)
        {
            weponMenuItem getWeponMenuItem;
            float         itemPositionX, itemPositionY;
            int           objectSize;

            Vector3 screenMousePosition = Input.mousePosition;

            for (int i = 0; i < weponMenuItemObject.Length; i++)
            {
                getWeponMenuItem = weponMenuItemObject[i].GetComponent <weponMenuItem>();
                itemPositionX    = getWeponMenuItem.positionX;
                itemPositionY    = Screen.height - getWeponMenuItem.positionY;
                objectSize       = getWeponMenuItem.size;
                //스크린 좌표계의 최상단은 스크린 높이를 600이라 하면 ex)(0, 600) 이지만 drawTexture는 최상단이 (0, 0)기준으로 그린다.

                if (screenMousePosition.x >= itemPositionX && screenMousePosition.x <= itemPositionX + objectSize &&
                    screenMousePosition.y <= itemPositionY && screenMousePosition.y >= itemPositionY - objectSize)
                {
                    getWeponMenuItem.mouseOver = true;
                }
                else
                {
                    getWeponMenuItem.mouseOver = false;
                }
            }
        }

        if (Input.GetMouseButtonDown(0) && !weponMenuOpen)
        {
            //Vector3 originMousePosition = Input.mousePosition;
            //originMousePosition.z = 26;
            //Vector3 worldMousePosition = Camera.main.ScreenToWorldPoint(originMousePosition);

            Vector3 scrPos             = Camera.main.WorldToScreenPoint(transform.position);
            Vector3 curScrPos          = new Vector3(Input.mousePosition.x, Input.mousePosition.y, scrPos.z);
            Vector3 worldMousePosition = Camera.main.ScreenToWorldPoint(curScrPos);

            switch (selectedWepon)
            {
            case 1: {
                if (arrowSwitch)
                {
                    if (shotMagic(1.0f))
                    {
                        Invoke("arrowCoolingTime", 1.0f);

                        float      arrowRotation = (180 / Mathf.PI) * Mathf.Atan2(worldMousePosition.y - transform.position.y, worldMousePosition.x - transform.position.x);
                        GameObject weponObject   = Instantiate(arrowPrefab, new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z), transform.rotation) as GameObject;
                        arrow      arrowObject   = (arrow)weponObject.GetComponent <arrow>();
                        arrowObject.mousePosition = worldMousePosition;
                        arrowObject.arrowRotation = arrowRotation;

                        gameObject.renderer.material.color = Color.white;
                        selectedWepon = 3;

                        arrowSwitch = false;
                    }
                }
                break;
            }                    //arrow

            case 2: {
                if (fireSwitch)
                {
                    if (shotMagic(10.0f))
                    {
                        Invoke("fireCoolingTime", 3.0f);

                        GameObject weponObject = Instantiate(firePrefab, new Vector3(worldMousePosition.x, worldMousePosition.y, this.transform.position.z), Quaternion.Euler(-90, 0, 0)) as GameObject;

                        gameObject.renderer.material.color = Color.white;
                        selectedWepon = 3;

                        fireSwitch = false;
                    }
                }
                break;
            }                    //fire
            }
        }
    }
Exemplo n.º 7
0
        void MoveRobotByDirection()
        {
            if (!Robot.IsMoving)
                return;

            //check the direction of walking Robot
            switch (button)
            {
                case arrow.forward:
                    {

                        if (Math.Abs(RobotPlaceForward[1]) < 18.5 && Math.Abs(RobotPlaceForward[0]) < 18.5
                            && (Math.Abs(RobotPlaceForward[1]) > 4.5 || Math.Abs(RobotPlaceForward[0]) > 1.5)
                            || (Robot.Jump > 15 && (Math.Abs(RobotPlaceForward[1]) < 5 && Math.Abs(RobotPlaceForward[0]) < 2)))
                        {
                            GL.glRotatef(-Robot.WalkAngle, 0, 1, 0);
                            GL.glTranslatef(0.2f * Move, 0, 0);
                            GL.glRotatef(Robot.WalkAngle, 0, 1, 0);

                        }
                        WhatWillDirection = button;
                    }
                    break;
                case arrow.backward:
                    {
                        if (Math.Abs(RobotPlaceBackward[1]) < 18.5 && Math.Abs(RobotPlaceBackward[0]) < 18.5
                                        && (Math.Abs(RobotPlaceBackward[1]) > 4.5 || Math.Abs(RobotPlaceBackward[0]) > 1.5)
                                        || (Robot.Jump > 15 && (Math.Abs(RobotPlaceBackward[1]) < 5 && Math.Abs(RobotPlaceBackward[0]) < 2)))
                        {
                            GL.glRotatef(-Robot.WalkAngle, 0, 1, 0);
                            GL.glTranslatef(-0.2f * Move, 0, 0);
                            GL.glRotatef(Robot.WalkAngle, 0, 1, 0);

                        }
                        WhatWillDirection = button;
                    }
                    break;
                case arrow.right:
                    {

                        if (Math.Abs(RobotPlaceRight[1]) < 18.5 && Math.Abs(RobotPlaceRight[0]) < 18.5
                            && (Math.Abs(RobotPlaceRight[1]) > 4.5 || Math.Abs(RobotPlaceRight[0]) > 1.5)
                            || (Robot.Jump > 15 && (Math.Abs(RobotPlaceRight[1]) < 5 && Math.Abs(RobotPlaceRight[0]) < 2)))
                        {
                            GL.glRotatef(-Robot.WalkAngle, 0, 1, 0);
                            GL.glTranslatef(0, 0, 0.2f * Move);
                            GL.glRotatef(Robot.WalkAngle, 0, 1, 0);

                        }
                        WhatWillDirection = button;
                    }
                    break;
                case arrow.left:
                    {
                        if (Math.Abs(RobotPlaceLeft[1]) < 18.5 && Math.Abs(RobotPlaceLeft[0]) < 18.5
                            && (Math.Abs(RobotPlaceLeft[1]) > 4.5 || Math.Abs(RobotPlaceLeft[0]) > 1.5)
                            || (Robot.Jump > 15 && (Math.Abs(RobotPlaceLeft[1]) < 5 && Math.Abs(RobotPlaceLeft[0]) < 2)))
                        {
                            GL.glRotatef(-Robot.WalkAngle, 0, 1, 0);
                            GL.glTranslatef(0, 0, -0.2f * Move);
                            GL.glRotatef(Robot.WalkAngle, 0, 1, 0);

                        }
                        WhatWillDirection = button;
                    }
                    break;
            }
        }
Exemplo n.º 8
0
    public override void _PhysicsProcess(float delta)
    {
        health_number_bar.SetText(_health.ToString() + " " + "HP");
        velocity.y += gravity;
        if (!is_dead)
        {
            bool friction = false;

            if (Input.IsActionJustPressed("ui_select") && attack_state == 0)
            {
                sprite.Play("Attack");
                attack_state = 30;
            }
            if (attack_state > 0)
            {
                if (attack_state == 1)
                {
                    arrow shot = (arrow)_arrow.Instance();

                    shot.Init(80.0f, arrow_point_pos);
                    GetParent().AddChild(shot);
                }
                attack_state--;
            }
            if (Input.IsActionPressed("ui_right"))
            {
                velocity.x   = Math.Min(velocity.x + acceleration, max_speed);
                sprite.FlipH = false;
                if (attack_state == 0)
                {
                    sprite.Play("Run");
                }
                if (Math.Sign(arrow_point_pos.Position.x) == -1)
                {
                    arrow_point_pos.Position = new Vector2(-arrow_point_pos.Position.x, arrow_point_pos.Position.y);
                }
            }
            else if (Input.IsActionPressed("ui_left"))
            {
                velocity.x   = Math.Max(velocity.x - acceleration, -max_speed);
                sprite.FlipH = true;
                if (attack_state == 0)
                {
                    sprite.Play("Run");
                }
                if (Math.Sign(arrow_point_pos.Position.x) == 1)
                {
                    arrow_point_pos.Position = new Vector2(-arrow_point_pos.Position.x, arrow_point_pos.Position.y);
                }
            }
            else
            {
                if (attack_state == 0)
                {
                    sprite.Play("Idle");
                }
                friction = true;
            }


            // PHYSICS
            if (IsOnFloor())
            {
                if (Input.IsActionPressed("ui_up"))
                {
                    velocity.y = jump_height;
                }
                if (friction)
                {
                    velocity.x = Lerp(velocity.x, 0.0f, 0.2f);
                }
            }
            else
            {
                if (velocity.y < 0.0f)
                {
                    if (attack_state == 0)
                    {
                        sprite.Play("Jump");
                    }
                }
                else
                {
                    if (attack_state == 0)
                    {
                        sprite.Play("Fall");
                    }
                }
                if (friction)
                {
                    velocity.x = Lerp(velocity.x, 0.0f, 0.05f);
                }
            }
        }
        velocity = MoveAndSlide(velocity, new Vector2(0, -1));
    }
Exemplo n.º 9
0
        void MoveRobotByDirection()
        {
            if (!Robot.IsMoving)
            {
                return;
            }

            //check the direction of walking Robot
            switch (button)
            {
            case arrow.forward:
            {
                if (Math.Abs(RobotPlaceForward[1]) < 18.5 && Math.Abs(RobotPlaceForward[0]) < 18.5 &&
                    (Math.Abs(RobotPlaceForward[1]) > 4.5 || Math.Abs(RobotPlaceForward[0]) > 1.5) ||
                    (Robot.Jump > 15 && (Math.Abs(RobotPlaceForward[1]) < 5 && Math.Abs(RobotPlaceForward[0]) < 2)))
                {
                    GL.glRotatef(-Robot.WalkAngle, 0, 1, 0);
                    GL.glTranslatef(0.2f * Move, 0, 0);
                    GL.glRotatef(Robot.WalkAngle, 0, 1, 0);
                }
                WhatWillDirection = button;
            }
            break;

            case arrow.backward:
            {
                if (Math.Abs(RobotPlaceBackward[1]) < 18.5 && Math.Abs(RobotPlaceBackward[0]) < 18.5 &&
                    (Math.Abs(RobotPlaceBackward[1]) > 4.5 || Math.Abs(RobotPlaceBackward[0]) > 1.5) ||
                    (Robot.Jump > 15 && (Math.Abs(RobotPlaceBackward[1]) < 5 && Math.Abs(RobotPlaceBackward[0]) < 2)))
                {
                    GL.glRotatef(-Robot.WalkAngle, 0, 1, 0);
                    GL.glTranslatef(-0.2f * Move, 0, 0);
                    GL.glRotatef(Robot.WalkAngle, 0, 1, 0);
                }
                WhatWillDirection = button;
            }
            break;

            case arrow.right:
            {
                if (Math.Abs(RobotPlaceRight[1]) < 18.5 && Math.Abs(RobotPlaceRight[0]) < 18.5 &&
                    (Math.Abs(RobotPlaceRight[1]) > 4.5 || Math.Abs(RobotPlaceRight[0]) > 1.5) ||
                    (Robot.Jump > 15 && (Math.Abs(RobotPlaceRight[1]) < 5 && Math.Abs(RobotPlaceRight[0]) < 2)))
                {
                    GL.glRotatef(-Robot.WalkAngle, 0, 1, 0);
                    GL.glTranslatef(0, 0, 0.2f * Move);
                    GL.glRotatef(Robot.WalkAngle, 0, 1, 0);
                }
                WhatWillDirection = button;
            }
            break;

            case arrow.left:
            {
                if (Math.Abs(RobotPlaceLeft[1]) < 18.5 && Math.Abs(RobotPlaceLeft[0]) < 18.5 &&
                    (Math.Abs(RobotPlaceLeft[1]) > 4.5 || Math.Abs(RobotPlaceLeft[0]) > 1.5) ||
                    (Robot.Jump > 15 && (Math.Abs(RobotPlaceLeft[1]) < 5 && Math.Abs(RobotPlaceLeft[0]) < 2)))
                {
                    GL.glRotatef(-Robot.WalkAngle, 0, 1, 0);
                    GL.glTranslatef(0, 0, -0.2f * Move);
                    GL.glRotatef(Robot.WalkAngle, 0, 1, 0);
                }
                WhatWillDirection = button;
            }
            break;
            }
        }