Пример #1
0
    public override void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Bird")
        {
            ABBird bird = collision.gameObject.GetComponent <ABBird> ();
            float  collisionMagnitude = collision.relativeVelocity.magnitude;
            float  birdDamage         = 1f;

            switch (_material)
            {
            case MATERIALS.wood:
                birdDamage = bird._woodDamage;
                break;

            case MATERIALS.stone:
                birdDamage = bird._stoneDamage;
                break;

            case MATERIALS.ice:
                birdDamage = bird._iceDamage;
                break;
            }

            DealDamage(collisionMagnitude * birdDamage);
        }
        else
        {
            base.OnCollisionEnter2D(collision);
        }
    }
Пример #2
0
    void Update()
    {
        // Updating camera zoom
        CalculateOrthographicSize();

        if (!_isDraging)
        {
            ABBird target = ABGameWorld.Instance.GetCurrentBird();

            Vector3 cameraNextPos = Vector3.zero;
            cameraNextPos.x = LeftBound();

            if (target && target.OutOfSlingShot && target.IsInFrontOfSlingshot())
            {
                cameraNextPos.x = RightBound() / 2f;
            }
            else
            {
                if (_dragDistance < 0f)
                {
                    cameraNextPos.x = RightBound();
                }
                else
                {
                    cameraNextPos.x = LeftBound();
                }
            }

            FollowTarget(cameraNextPos);
        }

        _isDraging = false;
    }
Пример #3
0
    private void ClickDown(Vector3 position)
    {
        _dragOrigin = position;

        Ray          ray = Camera.main.ScreenPointToRay(position);
        RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);

        if (hit && hit.transform.tag == "Bird")
        {
            _selectedBird = hit.transform.gameObject.GetComponent <ABBird> ();
            if (_selectedBird && !_selectedBird.IsSelected &&
                _selectedBird == ABGameWorld.Instance.GetCurrentBird())
            {
                _selectedBird.SelectBird();
                _usedSpecialPower = false;
                return;
            }
        }

        // Trigger special attack
        if (_selectedBird && _selectedBird.IsInFrontOfSlingshot() &&
            _selectedBird == ABGameWorld.Instance.GetCurrentBird() &&
            !_selectedBird.IsDying && !_usedSpecialPower)
        {
            _usedSpecialPower = true;
            _selectedBird.SendMessage("SpecialAttack", SendMessageOptions.DontRequireReceiver);
        }
    }
Пример #4
0
	public void AddBird(ABBird readyBird) {
		
		if(_birds.Count == 0)
			readyBird.GetComponent<Rigidbody2D>().gravityScale = 0f;

		if(readyBird != null)
			_birds.Add(readyBird);
	}
Пример #5
0
    public override void OnCollisionEnter2D(Collision2D collision)
    {
        ABLevel addPoints = LevelList.Instance.GetCurrentLevel();

        if (collision.gameObject.tag == "test" && collision.otherCollider.gameObject.name != "Platform(Clone)" && collision.otherCollider.gameObject.name != "Ground")
        {
            addPoints.triggerX = collision.contacts [0].point.x;
            addPoints.triggerY = collision.contacts [0].point.y;
//            foreach (ContactPoint2D striggerPoint in collision.contacts) {
//                addPoints.triggerX = striggerPoint.point.x;
//                addPoints.triggerY = striggerPoint.point.y;
//            }
//			Debug.Log (collision.contacts [0].point);
        }
        else if (collision.gameObject.name != "Platform(Clone)" && collision.gameObject.name != "Ground" && collision.otherCollider.gameObject.tag == "test")
        {
            addPoints.triggerX = collision.contacts [0].point.x;
            addPoints.triggerY = collision.contacts [0].point.y;
//			Debug.Log (collision.contacts [0].point);
        }
        if (collision.gameObject.name == "Ground")
        {
            foreach (ContactPoint2D groundPoint in collision.contacts)
            {
                if (!addPoints.grounds.Contains(groundPoint.point.x) && groundPoint.point.x <= 5)
                {
                    addPoints.grounds.Add(groundPoint.point.x);
                }
            }
        }
        if (collision.gameObject.tag == "Bird")
        {
            ABBird bird = collision.gameObject.GetComponent <ABBird>();
            float  collisionMagnitude = collision.relativeVelocity.magnitude;
            float  birdDamage         = 1f;

            switch (_material)
            {
            case MATERIALS.wood:
                birdDamage = bird._woodDamage;
                break;

            case MATERIALS.stone:
                birdDamage = bird._stoneDamage;
                break;

            case MATERIALS.ice:
                birdDamage = bird._iceDamage;
                break;
            }

            DealDamage(collisionMagnitude * birdDamage);
        }
        else
        {
            base.OnCollisionEnter2D(collision);
        }
    }
Пример #6
0
    public GameObject AddBird(GameObject original, Quaternion rotation)
    {
        Vector3 birdsPos = _slingshot.transform.position - ABConstants.SLING_SELECT_POS;

        if (_birds.Count >= 1)
        {
            birdsPos.y = _slingshot.transform.position.y;

            for (int i = 0; i < _birds.Count; i++)
            {
                if ((i + 1) % _birdsAmounInARow == 0)
                {
                    float coin = (Random.value < 0.5f ? 1f : -1);
                    birdsPos.x = _slingshot.transform.position.x + (Random.value * 0.5f * coin);
                }

                birdsPos.x -= ABWorldAssets.BIRDS [original.name].GetComponent <SpriteRenderer> ().bounds.size.x * 1.75f;
            }
        }

        GameObject newGameObject = (GameObject)Instantiate(original, birdsPos, rotation);
        Vector3    scale         = newGameObject.transform.localScale;

        scale.x = original.transform.localScale.x;
        scale.y = original.transform.localScale.y;
        newGameObject.transform.localScale = scale;

        newGameObject.transform.parent = _birdsTransform;
        newGameObject.name             = "bird_" + _birds.Count;

        ABBird bird = newGameObject.GetComponent <ABBird>();

        bird.SendMessage("InitSpecialPower", SendMessageOptions.DontRequireReceiver);

        if (_birds.Count == 0)
        {
            bird.GetComponent <Rigidbody2D>().gravityScale = 0f;
        }

        if (bird != null)
        {
            _birds.Add(bird);
        }

        return(newGameObject);
    }
Пример #7
0
	public void KillBird(ABBird bird) {

		if (!_birds.Contains (bird))
			return;
		
		_birds.Remove(bird);
		
		if(_birds.Count == 0) {
			
			// Check if player lost the game
			if(!_isSimulation)
				Invoke("ShowLevelFailedBanner", _timeToResetLevel);

			return;
		}
		
		_birds[0].GetComponent<Rigidbody2D>().gravityScale = 0f;
		_birds[0].JumpToSlingshot = true;
	}
Пример #8
0
    public void DragCamera(Vector3 dragDistance)
    {
        ABBird target = ABGameWorld.Instance.GetCurrentBird();

        if (target && target.IsFlying)
        {
            return;
        }

        _isDraging = true;

        if (dragDistance.magnitude > 0f)
        {
            _dragDistance = dragDistance.x;
        }

        Vector3 cameraPos = transform.position;

        cameraPos.x        = Mathf.Lerp(cameraPos.x, cameraPos.x - dragDistance.x, _dampTime * Time.deltaTime);
        cameraPos.x        = Mathf.Clamp(cameraPos.x, LeftBound(), RightBound());
        transform.position = cameraPos;
    }