Ejemplo n.º 1
0
        private void KeyBoardMove()
        {
            Vector3 input = new Vector3();

            if (Input.GetKey(KeyCode.W))
            {
                input.y += 1;
            }

            if (Input.GetKey(KeyCode.S))
            {
                input.y -= 1;
            }

            if (Input.GetKey(KeyCode.A))
            {
                input.x -= 1;
            }

            if (Input.GetKey(KeyCode.D))
            {
                input.x += 1;
            }

            if (input == Vector3.zero)             // To prevent unnecessary calculations while not moving
            {
                return;
            }

            CachedTransform.Translate(speedFactor * speed * input.normalized, Space.Self);
        }
Ejemplo n.º 2
0
        protected internal override void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(elapseSeconds, realElapseSeconds);

            CachedTransform.Translate(Vector3.back * m_AsteroidData.Speed * elapseSeconds, Space.World);
            CachedTransform.Rotate(m_RotateSphere * m_AsteroidData.AngularSpeed * elapseSeconds, Space.Self);
        }
Ejemplo n.º 3
0
        protected internal override void OnUpdate(float elapseSeconds, float realElapseSeconds)
#endif
        {
            base.OnUpdate(elapseSeconds, realElapseSeconds);

            CachedTransform.Translate(Vector3.forward * m_BulletData.Speed * elapseSeconds, Space.World);
        }
Ejemplo n.º 4
0
        protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(elapseSeconds, realElapseSeconds);

            CachedTransform.Translate(Vector3.forward * -data.Speed * elapseSeconds, Space.World);
            CachedTransform.Rotate(random * 90 * elapseSeconds, Space.Self);
        }
    protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
    {
        base.OnUpdate(elapseSeconds, realElapseSeconds);

        CachedTransform.Translate(
            Vector3.forward * m_Speed * elapseSeconds, Space.World);
    }
Ejemplo n.º 6
0
        private void collider(Vector2 vector, float a, float elapseSeconds)
        {
            RaycastHit2D result1 = Physics2D.Raycast(CachedTransform.position, a * vector, 0.5f, 1 << LayerMask.NameToLayer("Wall") | 1 << LayerMask.NameToLayer("Player"));

//			RaycastHit2D result2=Physics2D.Raycast(CachedTransform.position, new Vector2(vector.x*a==0 ?a:vector.x*a,vector.y*a==0 ?a:vector.y*a),0.5f,1 << LayerMask.NameToLayer("Wall"));
//			RaycastHit2D result3=Physics2D.Raycast(CachedTransform.position, new Vector2(vector.x*a==0 ?-a:vector.x*a,vector.y*a==0 ?-a:vector.y*a),0.5f,1 << LayerMask.NameToLayer("Wall"));
            if (result1 && result1.collider.CompareTag("Player"))
            {
                v = -v;
                result1.collider.GetComponent <TargetableObject>().OnHurt();
            }
//			else if (result2&&result2.collider.CompareTag("Player"))
//			{
//				v = -v;
//				result2.collider.GetComponent<TargetableObject>().OnHurt();
//			}
//			else if (result3&&result3.collider.CompareTag("Player"))
//			{
//				v = -v;
//				result3.collider.GetComponent<TargetableObject>().OnHurt();
//			}
            else if (!result1)
            {
                CachedTransform.Translate(elapseSeconds * m_data.Speed * vector * a);
            }
            else
            {
                random();
            }
        }
Ejemplo n.º 7
0
        protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(elapseSeconds, realElapseSeconds);

            CachedTransform.Translate(Vector3.left * m_PipeData.MoveSpeed * elapseSeconds, Space.World);
            if (CachedTransform.position.x <= m_PipeData.HideTarget)
            {
                //隐藏自身
                GameEntry.Entity.HideEntity(this);
            }
        }
Ejemplo n.º 8
0
        protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(elapseSeconds, realElapseSeconds);

            CachedTransform.Translate(Vector2.right * m_BulletData.FlySpeed * elapseSeconds, Space.World);

            if (CachedTransform.position.x >= 9.1f)
            {
                GameEntry.Entity.HideEntity(this);
            }
        }
Ejemplo n.º 9
0
    private void Update()
    {
        CachedTransform.Translate(Vector3.forward * Time.deltaTime, Space.Self);

        Vector3 pos = CachedTransform.localPosition;

        // Checks if bullet is out of screen
        if (pos.y < -AppManager.GUI.MaxYPos || pos.y > AppManager.GUI.MaxYPos || pos.x > AppManager.GUI.MaxXPos || pos.x < -AppManager.GUI.MaxXPos)
        {
            AppManager.Pool.Despawn(CachedTransform);
        }
    }
Ejemplo n.º 10
0
 private IEnumerator Shake(float time, float horizontal, float vertical, float frequency)
 {
     while (time > 0)
     {
         time -= Time.deltaTime;
         Vector3 test = new Vector3(
             Mathf.Sin(Time.realtimeSinceStartup * frequency) * horizontal,
             Mathf.Sin(Time.realtimeSinceStartup * frequency / 4 - 0.5f) * vertical / 8,
             0);
         CachedTransform.Translate(test, Space.Self);
         yield return(new WaitForEndOfFrame());
     }
 }
Ejemplo n.º 11
0
        protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(elapseSeconds, realElapseSeconds);
            m_CancalTime += elapseSeconds;

            if (m_CancalTime > 10)
            {
                GameEntry.Entity.HideEntity(this);
                m_CancalTime = 0;
            }

            if (m_FruitData.HP <= 0)
            {
                return;
            }
            CachedTransform.Translate(Vector3.back * m_FruitData.Speed * elapseSeconds, Space.World);
        }
Ejemplo n.º 12
0
        protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(elapseSeconds, realElapseSeconds);

            CachedTransform.Translate(Vector3.left * m_BgData.MoveSpeed * elapseSeconds, Space.World);
            if (CachedTransform.position.x <= m_BgData.SpawnTarget && m_IsSpawn == false)
            {
                //显示背景实体
                GameEntry.Entity.ShowBg(new BgData(GameEntry.Entity.GenerateSerialId(), m_BgData.TypeId, m_BgData.MoveSpeed, 17.6f));
                m_IsSpawn = true;
            }

            if (CachedTransform.position.x <= m_BgData.HideTarget)
            {
                //隐藏实体
                GameEntry.Entity.HideEntity(this);
            }
        }
Ejemplo n.º 13
0
    private void Update()
    {
        CachedTransform.Translate(Vector3.up * _speed * Time.deltaTime, Space.Self);

        // Make shot at player after passing 25% of screen
        if (!_fired && CachedTransform.localPosition.y < AppManager.GUI.MaxYPos * 0.5f + _sprite.height)
        {
            _fired = true;

            const string bulletPrefabName = "EnemyBullet";
            AppManager.Pool.Spawn(bulletPrefabName, AppManager.Game.GameObjectsContainer, CachedTransform.localPosition - Vector3.up * _sprite.height);
        }

        // Add enemy to pool after passing screen
        if (CachedTransform.localPosition.y < -AppManager.GUI.MaxYPos)
        {
            AppManager.Pool.Despawn(CachedTransform);
        }
    }
Ejemplo n.º 14
0
        // Late update to be certain the camera had a chance to move
        private void LateUpdate()
        {
            // In local space we are origin, so the startPos position is the inverse vector we moved
            Vector3 delta = -CachedTransform.InverseTransformPoint(startPos);

            if (NotOutsideBounds(delta))
            {
                return;
            }

            // apply the x and y limits to the delta vector
            delta.x = Mathf.Max(Mathf.Min(delta.x, RelativeLimits.x), RelativeLimits.z);
            delta.y = Mathf.Max(Mathf.Min(delta.y, RelativeLimits.y), RelativeLimits.w);

            delta.z = 0;             // Keep Z the same

            // Set the position back to where we started and translate over the limited delta
            CachedTransform.position = startPos;
            CachedTransform.Translate(delta, Space.Self);
        }
Ejemplo n.º 15
0
        protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(elapseSeconds, realElapseSeconds);

            CachedTransform.Translate(Vector3.left * m_BgData.MoveSpeed * elapseSeconds, Space.World);

            ////   0   ,
            ////            this.SpawnTarget = 3.8f;
            ////this.HideTarget = -22.02f;
            if (CachedTransform.position.x <= m_BgData.SpawnTarget && !m_IsSpawn)
            {
                GameEntry.Entity.ShowBg(new BgData(GameEntry.Entity.GenerateSerialId(), m_BgData.TypeId, m_BgData.MoveSpeed, m_BgData.StartPosition));
                m_IsSpawn = true;
            }

            if (CachedTransform.position.x <= m_BgData.HideTarget)
            {
                GameEntry.Entity.HideEntity(this);
            }
        }
Ejemplo n.º 16
0
        private void collider(Vector2 vector, float a, float b, float elapseSeconds)
        {
            bool    result1 = Physics2D.Raycast(CachedTransform.position, a * vector, RayLength, _layerMask);
            bool    result2 = Physics2D.Raycast(CachedTransform.position, new Vector2(vector.x * a == 0 ?a:vector.x * a, vector.y * a == 0 ?a:vector.y * a), RayLength, _layerMask);
            bool    result3 = Physics2D.Raycast(CachedTransform.position, new Vector2(vector.x * a == 0 ?-a:vector.x * a, vector.y * a == 0 ?-a:vector.y * a), RayLength, _layerMask);
            Vector2 vector2 = Vector2.zero;

            if (!result1 && !result2 && !result3)
            {
                vector2 = elapseSeconds * m_data.Speed * vector * a;
            }
//            else if (Math.Abs(b) > 0.7f)
//            {
//                vector2 = elapseSeconds * b * b * new Vector2(Mathf.Sign(b), Mathf.Sign(b))*(Vector2.one-vector);
//            }
//            else if (Math.Abs(b)<0.3f)
//            {
//                vector2 = elapseSeconds * (1 - Math.Abs(b)) * (1 - Math.Abs(b)) * new Vector2(-Mathf.Sign(b), -Mathf.Sign(b))*(Vector2.one-vector);
//            }
            CachedTransform.Translate(vector2);
        }
Ejemplo n.º 17
0
    protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
    {
        base.OnUpdate(elapseSeconds, realElapseSeconds);

        CachedTransform.Translate(CachedTransform.forward * bulletData.Speed * elapseSeconds, Space.World);

        zeroSpeedAutoDestroyTimes += elapseSeconds;

        // 将超出边界的子弹隐藏
        if (PositionUtility.IsOutOfMapBoundary(CachedTransform.position))
        {
            GameEntry.Entity.HideEntity(this.Id);
        }
        // 对于速度为0的子弹,在0.5秒后自动销毁
        else if (bulletData.Speed == 0)
        {
            if (zeroSpeedAutoDestroyTimes >= 0.5f)
            {
                GameEntry.Entity.HideEntity(this.Id);
            }
        }
    }
Ejemplo n.º 18
0
        private void SwipeMove()
        {
            if (Input.touchCount != 1)             // Can only move with 1 finger
            {
                return;
            }

            Touch touch = Input.GetTouch(0);

            if (touch.phase == TouchPhase.Began)
            {
                lastPosition = touch.rawPosition;
                return;
            }

            Vector2 moveDirection = lastPosition - touch.position;

            if (moveDirection.magnitude > deadZone)
            {
                CachedTransform.Translate(speedFactor * speed * moveDirection.normalized, Space.Self);
            }

            lastPosition = touch.position;
        }
Ejemplo n.º 19
0
 protected void MoveForward(float dis)
 {
     CachedTransform.Translate(moveDirection * dis, Space.World);
 }