示例#1
0
 void initialize()
 {
     elapsedTime             = 0.0f;
     state                   = ChispaState.idle;
     minX                    = xPos = -Screen.width / 3.0f;
     maxX                    = Screen.width + Screen.width / 3.0f;
     maxY                    = Screen.height;
     xSpeed                  = swipeSpeed;
     this.transform.position = new Vector2(xPos, yPos);
     showText                = false;
 }
示例#2
0
    public void swipeRightToLeft()
    {
        xSpeed = -swipeSpeed;
        xPos   = Screen.width + Screen.width / 20.0f;
        xAccel = -swipeAccel;

        this.transform.localScale = new Vector3(-1, 1, 1);

        state = ChispaState.rightToLeft;

        showText = true;
    }
示例#3
0
    public void swipeLeftToRight()
    {
        xSpeed = swipeSpeed;
        xPos   = -Screen.width / 20.0f;
        xAccel = swipeAccel;

        this.transform.localScale = new Vector3(1, 1, 1);

        state = ChispaState.leftToRight;

        showText = true;
    }
示例#4
0
    void Update()
    {
        float scaleFactor = Screen.height / 600.0f;

        if (showText)
        {
            controller.theText.color = new Color(1, 1, 1, 1);
            showText = false;
        }

        if (state == ChispaState.leftToRight || state == ChispaState.rightToLeft)
        {
            xPos   += xSpeed * scaleFactor * Time.deltaTime;
            xSpeed += xAccel * scaleFactor * Time.deltaTime;

            // we are in absolute coordinates: 0 is left, Screen.width is right
            yPos = (maxY / 2.0f) + swayAmplitude * Mathf.Sin(angle);

            angle += angleSpeed * Time.deltaTime;

            this.transform.position = new Vector2(xPos, yPos);

            if (xPos > maxX || xPos < minX)
            {
                state  = ChispaState.idle;
                xSpeed = swipeSpeed;
            }

            elapsedTime += Time.deltaTime;
            if (elapsedTime > timeToEmitDust)
            {
                elapsedTime = 0.0f;
                GameObject newDustGO = (GameObject)Instantiate(dustPrefab, this.transform.position,
                                                               Quaternion.Euler(0, 0, FloatRandom.floatRandomRange(0, 180.0f)));
                newDustGO.transform.parent = this.transform.parent;
                ChispaAlertDustParticle newDust = newDustGO.GetComponent <ChispaAlertDustParticle> ();
                newDust.initialize();
            }
        }

        if (state == ChispaState.leftToRight)
        {
            if (Input.GetMouseButtonDown(0))                // finish at once

            {
                xSpeed = xSpeed * scaleFactor * 10.0f;
            }
        }

        if (state == ChispaState.rightToLeft)
        {
            if (Input.GetMouseButtonDown(0))                // finish at once

            {
                xSpeed = xSpeed * scaleFactor * 10.0f;
            }
        }

        if (state == ChispaState.idle)
        {
            if (Input.GetMouseButtonDown(0))
            {
                controller.dismiss();
            }
        }
    }