Beispiel #1
0
    protected override IEnumerator Move()
    {
        yield break;
        while (true)
        {
            //print(isDowning);
            yield return(new WaitForSeconds(Random.Range(minWaitTime, maxWaitTime)));

            if (!isDowning)
            {
                m_JS.AddForce(Random.Range(minForce, maxForce) * Vector2.Lerp(minVec, maxVec, Random.value));
            }
            else
            {
                m_JS.AddForce(Random.Range(minForce, maxForce) * Vector2.Lerp(DowningminVec, DowningmaxVec, Random.value));
            }
        }
    }
Beispiel #2
0
    void CheckForMouseUp()
    {
        if (Input.GetMouseButtonUp(0))
        {
            StopDrag();
            isGrounded = false;
            jelly.AddForce(jumpForce);

            jelly.CentralPoint.Body2D.AddTorque((mPos.x - transform.position.x) * (jelly.m_Mass * jelly.m_Mass));
        }
    }
Beispiel #3
0
    public void JumpTowards(Vector2 direction)
    {
        if (PauseActions)
        {
            return;
        }
        if (Time.time - lastJumpTime < JumpDelay)
        {
            return;
        }
        if (!IsGrounded())
        {
            return;
        }

        lastJumpTime = Time.time;
        jelly.LockRotation(false);
        sticky.Unstick(0.1f);
        jelly.AddForce(direction.normalized * JumpForce);
    }
Beispiel #4
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Vector2 target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         UnityEngine.Debug.Log("entered");
         // GetComponent<JellySprite>().SetPosition(target, false);
         Vector2 jumpVector = Vector2.zero;
         jumpVector.x = target.x;
         jumpVector.y = target.y;
         jumpVector.Normalize();
         m_JellySprite.AddForce(jumpVector * UnityEngine.Random.Range(m_MinJumpForce, m_MaxJumpForce));
         // GetComponent<JellySprite>().Rotate(180f);
     }
 }
Beispiel #5
0
    /// <summary>
    /// Update this instance.
    /// </summary>
    void Update()
    {
        m_BounceTimer -= Time.deltaTime;

        // Randomly bounce around
        if (m_BounceTimer < 0.0f)
        {
            Vector2 jumpVector = Vector2.zero;
            jumpVector.x = UnityEngine.Random.Range(m_MinJumpVector.x, m_MaxJumpVector.x);
            jumpVector.y = UnityEngine.Random.Range(m_MinJumpVector.y, m_MaxJumpVector.y);
            jumpVector.Normalize();
            m_JellySprite.AddForce(jumpVector * UnityEngine.Random.Range(m_MinJumpForce, m_MaxJumpForce));
            m_BounceTimer = UnityEngine.Random.Range(m_MinBounceTime, m_MaxBounceTime);
        }
    }
Beispiel #6
0
    private void FixedUpdate()
    {
        if (jumpRegistered)
        {
            if (Time.time - lastJumpTime > DELAY_BETWEEN_JUMPS)
            {
                float groundAngle = GroundTiltController.GetEulerAngleZ();
                jumpForce.x = groundAngle <= 180f ? groundAngle * -4 : (360f - groundAngle) * 4f;
                jellySprite.AddForce(jumpForce);

                lastJumpTime = Time.time;
            }

            jumpRegistered = false;
        }
    }
    public void creatureJump()
    {
        Vector2 jumpVec = Vector2.zero;

        //UnityEngine.Debug.Log(volume.Count);
        //UnityEngine.Debug.Log(flow.Count);
        JumpForce = 100f;
        if (volume.Count > 0 && flow.Count > 0 && read)
        {
            JumpForce = (float)(Math.Pow((volume.Average() / flow.Average()), 3) * 3);
            UnityEngine.Debug.Log("Jump force is : " + JumpForce);
            jumpTxt.text = JumpForce.ToString();
        }

        jumpVec.x = -0.1f;
        jumpVec.y = 1f;
        jumpVec.Normalize();
        creature.AddForce(jumpVec * JumpForce);
        JumpForce    = 50;
        drop.value   = 0;
        drop.enabled = true;
        read         = false;
    }
Beispiel #8
0
    public void Jump(bool firstJump)
    {
        Vector2 jumpVector = Vector2.zero;

        if (firstJump)
        {
            int ranDir = Random.Range(0, 2);
            if (ranDir == 0)
            {
                jumpVector = new Vector3(-1, 1, 0);
            }
            else
            {
                jumpVector = new Vector3(1, 1, 0);
            }
        }
        else
        {
            jumpVector = CalculateJumpDirection();
        }

        m_JellySprite.AddForce(jumpVector * UnityEngine.Random.Range(m_MinJumpForce, m_MaxJumpForce));
        m_BounceTimer = UnityEngine.Random.Range(m_MinBounceTime, m_MaxBounceTime);
    }
Beispiel #9
0
    // Update is called once per frame
    void Update()
    {
        bool Mousedown = Input.GetMouseButton(0);

        if (UICamera.hoveredObject != null)
        {
            if (UICamera.hoveredObject.tag.Equals("SelectColor") ||
                UICamera.hoveredObject.tag.Equals("stopButton"))
            {
                initempanel = true;
                return;
            }
        }
        if (Input.GetMouseButtonUp(0) && initempanel)
        {
            initempanel = false;
        }
        if (Mousedown && !isclicked && !isrunning && !initempanel)
        {
            Time.timeScale = 0.3f;
            beginposition  = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,
                                                                        Input.mousePosition.y, 1));
            isclicked = true;
        }
        if (Input.GetMouseButtonUp(0) && !isrunning && isclicked)
        {
            isclicked      = false;
            Time.timeScale = 1.0f;
            endposition    = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,
                                                                        Input.mousePosition.y, 1));
            float   angle       = Mathf.Atan2((beginposition.y - endposition.y), (beginposition.x - endposition.x));
            Vector2 forceonrole = new Vector2(beginposition.x - endposition.x, beginposition.y - endposition.y);
            gameObject.rigidbody2D.AddForce(forceonrole.normalized * 500);
            isrunning = true;
        }

        float H = Input.GetAxis("Horizontal");
        float V = Input.GetAxis("Vertical");

        rigidbody2D.AddForce(new Vector2(H * 20, V * 20));
        inputcount = Input.touchCount;
        if (!isrunning && inputcount == 1)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
            RaycastHit hit;
            if (collider.Raycast(ray, out hit, 10.0f))
            {
                if (Input.GetTouch(0).phase == TouchPhase.Began)
                {
                    beginX = Input.GetTouch(0).position.x;
                    beginY = Input.GetTouch(0).position.y;
                }
                else if (Input.GetTouch(0).phase == TouchPhase.Ended)
                {
                    endX      = Input.GetTouch(0).position.x;
                    endY      = Input.GetTouch(0).position.y;
                    isrunning = true;
                    Vector2 tp = new Vector2((endX - beginX), (endY - beginY));
                    m_jellysprite.AddForce(tp.normalized * shotForce);
                }
                else if (Input.GetTouch(0).phase == TouchPhase.Moved)
                {
                    m_jellysprite.AddForce(new Vector2(0, pushForce));
                }
            }
        }
    }
Beispiel #10
0
 public void AddForce(Vector2 _vec)
 {
     m_jellySprite.AddForce(_vec);
 }
Beispiel #11
0
 public override void AddForce(Vector3 jump, ForceMode impulse)
 {
     _jelly.AddForce(jump, impulse);
 }
Beispiel #12
0
    /// <summary>
    /// Update this instance.
    /// </summary>
    void Update()
    {
        grounded = m_JellySprite.IsGrounded(m_GroundLayer, 1);
        //speed = Vector2.SqrMagnitude ((( Vector2)transform.localPosition ) - exexPos);
        //exexPos = exPos;
        //exPos = transform.localPosition;

        if (lastJump > 0)
        {
            lastJump -= Time.deltaTime;
        }
        if (grounded)
        {
            if (inJump)
            {
                MusicProc.doEvent(ActionEvent.Landed);
            }
            inJump = false;
        }
        else
        {
            inJump = true;
        }

        bool left  = false;
        bool right = false;

        foreach (Touch t in Input.touches)
        {
            if (t.position.x > center)
            {
                right = true;
            }
            else
            {
                left = true;
            }
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            right = true;
        }

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            left = true;
        }

        if (left && right)
        {
            if (lastJump <= 0 && grounded)
            {
                //m_JellySprite.AddForce(Vector2.up * 10000);
                m_JellySprite.AddForce(Vector3.up * 10000);                // - m_JellySprite.WhereIsGround2D(m_GroundLayer)*500);
                lastJump = 0.5f;
                MusicProc.doEvent(ActionEvent.Jump);
            }
        }
        else if (right)
        {
            //jumpVector += Vector2.right * 150;
            cx += rotSpeed * Time.deltaTime;
            if (cx > 1)
            {
                cx = 1;
            }
        }
        else if (left)
        {
            cx -= rotSpeed * Time.deltaTime;
            if (cx < -1)
            {
                cx = -1;
            }
        }
        else if (cx < 0)
        {
            cx += Time.deltaTime * rotSpeed;
            if (cx >= 0)
            {
                cx = 0;
            }
        }
        else if (cx > 0)
        {
            cx -= Time.deltaTime * rotSpeed;
            if (cx <= 0)
            {
                cx = 0;
            }
        }

        //Camera.main.transform.rotation = Quaternion.Euler(0, 0, cx * maxAngle);
        Physics2D.gravity = new Vector2(Mathf.Sin(cx) * gravity, -Mathf.Cos(cx) * gravity);

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.LoadLevel("menu");
        }
    }