示例#1
0
    private void SummonBullet(int BulletIndex, float CertainSpeed)
    {
        Vector3 RelativeSumPoint = new Vector3(SummonPoint.x * GetComponent <Collider2D>().bounds.size.x,
                                               SummonPoint.y * GetComponent <Collider2D>().bounds.size.y, 0);
        Vector3    position;
        Quaternion rotation;
        bool       FacingRight = GetComponent <PlayerController>().FacingRight;

        if (FireDirection.y < 0 && FireDirection.x == 0)
        {
            position = FacingRight
                ? transform.position + RelativeSumPoint
                : transform.position + Vector3.Reflect(RelativeSumPoint, Vector3.right);
        }
        else
        {
            position = _aimindic.transform.position;
        }

        rotation = FacingRight
            ? Quaternion.Euler(0f, 0f, Vector2.SignedAngle(Vector2.right, FireDirection))
            : Quaternion.Euler(0f, 180f, Vector2.SignedAngle(FireDirection, Vector2.left));

        var bulletInstance = Instantiate(Bullets[BulletIndex], position, rotation);

        bulletInstance.GetComponent <Rigidbody2D>().velocity = CertainSpeed * FireDirection;
        bulletInstance.gameObject.GetComponent <BulletInfo>().playerOrigin = gameObject;
    }
        public override void Act()
        {
            if (!InputManager.IsFingerDown)
            {
                return;
            }
//            currentSpeed = Mathf.Lerp(currentSpeed, InputManager.ScreenLeftRightJoystick(), 0.5f);
            var currentFingerPosition = InputManager.CurrentFingerPositionScreenCentered;
            var percentage            = Vector2.SignedAngle(Vector2.down, currentFingerPosition.normalized);

            percentage += (percentage < 0) ? 360 : 0;
            percentage /= 360;

            var currentPercentage = GameManager.Player.FloatPosition;

            if (Mathf.Abs(currentPercentage - percentage) > 0.5f)
            {
                percentage += (currentPercentage > percentage)? 1:-1;
            }

            if (Mathf.Abs(currentPercentage - percentage) > 0)
            {
                GameManager.Player.SetPosition(Mathf.Lerp(currentPercentage, percentage, GameManager.Ball.squishing? 0.001f : 0.1f));
            }
//            GameManager.Player.SetPosition(percentage);
//            var currentPlayerPosition = GameManager.Player.transform.position.normalized;

//            var sign = Mathf.Sign(currentFingerPosition.x * currentPlayerPosition.y - currentFingerPosition.y * currentPlayerPosition.x);
//            percentage = Vector2.Angle(currentFingerPosition, currentPlayerPosition) * sign;
        }
示例#3
0
        private void UpdateMouseInput()
        {
            var offset     = new Vector2(Screen.width / 2f, Screen.height / 2f);
            var mousePoint = ((Vector2)Input.mousePosition - offset).normalized;
            var angle      = -Vector2.SignedAngle(Vector2.up, mousePoint);

            angle = angle < 0 ? 360 + angle : angle;
            _rotateEventEntity.Get <RotateEventComponent>().Value = angle;
        }
示例#4
0
        public Projectile(Game game, Vec2 start, Vec2 target, float speed,
                          SpriteDef def, Vec2 spriteForward)
            : base(game)
        {
            this.target = target;
            this.speed  = speed;

            Vec2  dir   = target - start;
            float angle = Vec2.SignedAngle(spriteForward, dir);
            var   rot   = Quaternion.Euler(0, 0, angle);

            sprite       = MakeProjSprite(game, start, rot, def, Color.white, 3);
            spriteTrailA = MakeProjSprite(game, start, rot, def, new Color(1, 1, 1, .25f), 2);
            spriteTrailB = MakeProjSprite(game, start, rot, def, new Color(1, 1, 1, .0625f), 1);
        }
示例#5
0
    private void FixedUpdate()
    {
        if (gameOver)
        {
//            GameOverFixedUpdate();
            return;
        }

#if UNITY_STANDALONE
        Vector3 newAngle = new Vector3(0, 0, 0);

        bool up    = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow);
        bool left  = Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
        bool right = Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
        bool down  = Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow);
        bool move  = (up ^ down) || (left ^ right);
        if (up && down)
        {
            up   = false;
            down = false;
        }

        if (right && left)
        {
            right = false;
            left  = false;
        }

        if (up)
        {
            if (left)
            {
                newAngle = new Vector3(0, 0, -135);
            }
            else if (right)
            {
                newAngle = new Vector3(0, 0, 135);
            }
            else
            {
                newAngle = new Vector3(0, 0, 180);
            }
        }
        else if (down)
        {
            if (left)
            {
                newAngle = new Vector3(0, 0, -45);
            }
            else if (right)
            {
                newAngle = new Vector3(0, 0, 45);
            }
            else
            {
                newAngle = new Vector3(0, 0, 0);
            }
        }
        else
        {
            if (left)
            {
                newAngle = new Vector3(0, 0, -90);
            }
            else if (right)
            {
                newAngle = new Vector3(0, 0, 90);
            }
            else
            {
                newAngle = dirAngle;
            }
        }
        transform.rotation = Quaternion.Euler(newAngle);
        dirAngle           = newAngle;
        transform.Translate(Vector2.down * (move ? speed : 0));
#elif UNITY_IOS || UNITY_ANDROID
        if (controlType == 0 && Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            switch (touch.phase)
            {
            case TouchPhase.Began:
                beginPos   = touch.position;
                dirChoosen = false;
                break;

            case TouchPhase.Moved:
                direction = touch.position - beginPos;
                break;

            case TouchPhase.Ended:
                dirChoosen = true;
                break;
            }
        }

        if (controlType == 1 && Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Moved)
            {
                direction = touch.deltaPosition;
            }

            dirChoosen = true;
        }

        if (controlType == 2 && Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began)
            {
                beginPos = touch.position;
            }

            if (touch.phase == TouchPhase.Moved)
            {
                direction  = touch.position - beginPos;
                direction /= 10;
            }

            dirChoosen = true;
        }

        if (dirChoosen)
        {
            float angle = Vector2.SignedAngle(Vector2.down, direction);
            transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
            int w = Screen.width, h = Screen.height;
            var newPos = transform.position;
            if (controlType <= 1)
            {
                newPos.x += direction.x / w * speed * 10 * 5;
                newPos.y += direction.y / h * speed * 10 * 5;
            }
            else
            {
                newPos.x += direction.normalized.x / 15;
                newPos.y += direction.normalized.y / 15;
            }

            transform.position = newPos;
            dirChoosen         = false;
        }
#endif


        curMana   = Math.Min(curMana + manaRegen * Time.deltaTime, maxMana);
        curHP     = Math.Min(curHP + HPRegen * Time.deltaTime, maxHP);
        timeScore = (int)(Time.timeSinceLevelLoad * PointPerSecond);
        speedX    = speedY = 0;
    }